Controller Code :-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | public class ActionRegionEXp { public String DepartmentStr{get;set;} public Contact conobj{get;set;} public ActionRegionEXp() { Conobj = new Contact(); } public void FetchInfo() { if(DepartmentStr!=null && DepartmentStr!='') { List<Contact> ConLst = new List<Contact>(); conLst = [select id,Department,title,email from Contact where Department=:DepartmentStr]; if(conLst !=null && conLst.size()>0) { conobj= conLst[0]; } else { Apexpages.Message message= new Apexpages.Message(ApexPages.Severity.Info,'No Record Found with this Department:' +DepartmentStr); ApexPages.addMessage (message); Conobj=Null; } } } } |
Visualforce Page Code :-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <apex:page controller="ActionRegionEXp"> <apex:pageMessages id="messgs"> </apex:pageMessages> <apex:form > <apex:pageBlock id="pageblock"> <table> <apex:actionRegion > <tr> <td> <apex:outputLabel value="Enter Deparment"> </apex:outputLabel></td> <td> <apex:inputText value="{!DepartmentStr}"/></td> <td> <apex:commandbutton value="Get Info" action="{!Fetchinfo}" rerender="pageblock,messgs" /> </td> </tr> </apex:actionRegion> <tr> <td> <apex:outputLabel value="Contact Title"></apex:outputLabel> </td> <td> <apex:inputField value="{!conobj.Title}"/> </td> </tr> <tr> <td> <apex:outputLabel value="Contact Email"> </apex:outputLabel> </td> <td> <apex:inputField value="{!conobj.Email}"/> </td> </tr> </table> </apex:pageBlock> </apex:form> </apex:page> |
Output Screen :-
No comments:
Post a Comment