You need to sign in to do that
Don't have an account?

please help me for auto populate
i want to auto populate the picklist after selecting a lookup field. please help me.

<apex:page Controller="OppContactRoleController" id="p1"> <script> var ContactValue=''; function changeValue(input) { asChangePrimary(input.value); } function ValidateRoles(input,objSelection,Object) { if(input.value!='--None--'){ if(ContactValue!=''){ alert('Please select '+Object); } } } function setContact(convalue){ ContactValue=convalue; } function getvalue(myinput) { // var x=document.getElementById('p1:fm:pb2:pbt:c1:opp:contactid').value; //alert(x); // alert(myinput.value); var y=myinput.value; document.getElementById('p1:fm:iph').value=y; } </script> <apex:form id="fm" > <apex:actionfunction name="getvalue" action="{!getcontactrole}" /> <!-- do not remove this --> <apex:inputtext value="{!mylookupvalue}" id="iph" > <!-- <apex:actionsupport event="on" action="{!getcontactrole}" /> --> </apex:inputtext> <!-- *********************** --> <apex:pageMessages id="pgmsg" /> <apex:actionFunction action="{!setPrimary}" name="asChangePrimary" rerender="hdn"> <apex:param name="PrimaryContact" assignTo="{!PrimaryContact}" value="" /> </apex:actionFunction> <apex:actionFunction action="{!SaveAll}" name="RemoveExcessOncomplete" rerender="pb2"> </apex:actionFunction> <apex:pageBlock id="pb1" title="Contact Role and Partner Merge" rendered="{!!ShowView}"> <apex:pageBlockButtons location="top"> <a class="btn" style="text-decoration: none;" href="{!$Page.OppcontactRolePage}?Id={!strId}&IsInline=1&IsNew=1" target="_top">New Project Firm</a> </apex:pageBlockButtons> <apex:pageBlockTable value="{!lstMainConAccRoleWrap}" var="l"> <apex:column headerValue="Action"> <apex:outputPanel > <apex:outputLink style="color:#015ba7" value="{!$Page.OppcontactRolePage}?Id={!strId}&IsInline=1" target="_top">Edit</apex:outputLink> <span style="color:#015ba7">|</span> </apex:outputPanel> <apex:commandlink style="color:#015ba7" value="Del" onclick="return confirm('Are you sure?');" target="_top" action="{!DelOCR}" > <apex:param value="{!l.iIndex}" name="RowIndex" assignTo="{!RowIndex}"/> <apex:param value="{!l.RecordId}" name="delRecordId" assignTo="{!delRecordId}"/> </apex:commandlink> </apex:column> <apex:column headerValue="Project Firm" value="{!l.objAcc.Name}"/> <apex:column headerValue="Company City" value="{!l.objAcc.BillingCity}"/> <apex:column headerValue="Company State" value="{!l.objAcc.BillingState}"/> <apex:column headerValue="Firm Role"> <apex:outputPanel > {!l.objOPR.Role} </apex:outputPanel> </apex:column> <apex:column headerValue="Contact Role"> <apex:outputPanel > {!l.objOCR.Role} </apex:outputPanel> </apex:column> <apex:column HeaderValue="Contact" value="{!l.objOCR.ContactId}"/> <apex:column HeaderValue="Primary"> <apex:outputPanel rendered="{!!l.objOCR.IsPrimary}"><img src="/img/checkbox_unchecked.gif" alt="Not Checked" width="21" height="16" class="checkImg" title="Not Checked"/></apex:outputPanel> <apex:outputPanel rendered="{!l.objOCR.IsPrimary}"><img src="/img/checkbox_checked.gif" alt="Checked" width="21" height="16" class="checkImg" title="Checked"/> </apex:outputPanel> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:pageblock id="pb2" rendered="{!ShowView}"> <apex:pageBlockTable value="{!lstMainConAccRoleWrap}" var="l" id="pbt"> <apex:column headervalue="Action"> <apex:commandLink rendered="{!if(l.RecordId!='',true,false)}" value="Delete" onclick="return confirm('Are you sure ?');" action="{!DelOCR}" style="color:#015ba7;"> <apex:param value="{!l.iIndex}" name="RowIndex" assignTo="{!RowIndex}"/> <apex:param value="{!l.RecordId}" name="delRecordId" assignTo="{!delRecordId}"/> </apex:commandLink> <apex:outputLink rendered="{!if(l.RecordId=='',true,false)}" onclick="return confirm('Are you sure ?');" style="color:#015ba7" value="{!$Page.OppcontactRolePage}?Id={!strId}&IsInline=1" target="_top">Delete</apex:outputLink> </apex:column> <apex:column headervalue="Primary"> <apex:outputPanel > <apex:outputPanel rendered="{!If(l.IsPrimary,true,false)}"> <input type="radio" checked="true" name="chosen" id="{!l.RecordId}" VALUE="{!l.RecordId}" onclick="changeValue(this);" /> </apex:outputPanel> <apex:outputPanel rendered="{!If(l.IsPrimary,false,true)}"> <input type="radio" name="chosen" id="{!l.RecordId}" VALUE="{!l.RecordId}" onclick="changeValue(this);" /> </apex:outputPanel> </apex:outputPanel> </apex:column> <apex:column headerValue="Contact" id="c1"> <apex:outputPanel id="opp"> <apex:inputField required="false" value="{!l.objOCR.ContactId}" id='contactid' > <apex:actionsupport event="onchange" action="{!getcontactrole}" /> <!-- action support added for sending value to apex class.--> <!-- <apex:actionsupport event="onchage" action="{!getcontactrole}" /> --> </apex:inputField> </apex:outputPanel> </apex:column> <apex:column headerValue="Contact Role"> <apex:inputField value="{!l.objOCR.Role}" > </apex:inputField> </apex:column> <apex:column headerValue="Account"> <apex:outputPanel > <apex:inputField value="{!l.objCon.AccountId}"/> </apex:outputPanel> </apex:column> <apex:column headerValue="Partner Role"> <apex:outputPanel > <apex:selectList value="{!l.objOPR.Role}" size="1" multiselect="false"> <apex:selectOptions value="{!OPRRoleOptions}"></apex:selectOptions> </apex:selectList> </apex:outputPanel> <!-- <apex:inputField rendered="{!if(l.objOCR==null,false,true)}" value="{!l.objOCR.Role}" /> <apex:inputField rendered="{!if(l.objOCR==null,true,false)}" value="{!l.objOPR.Role}" /> --> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!SaveAll}" /> <apex:commandButton value="New" onclick="SavePage();" rerender="pb2,pgmsg" /> <apex:commandButton value="Back" action="{!Back}" /> </apex:pageBlockButtons> </apex:pageblock> <apex:actionFunction action="{!QuickSave}" oncomplete="AddNew();" name="SavePage" rerender="pb2,pgmsg" /> <apex:actionFunction action="{!AddNew}" rerender="pb2,pgmsg" name="AddNew"/> ...........{!cons.role__c} </apex:form> </apex:page>
public with sharing class OppContactRoleController { Public List<Contact> contactList {get;set;} public boolean ShowView{get;set;} public String strId{get;set;} public string PrimaryContact{get;set;} Id OCRId; public string delRecordId{get;set;} Map<string,string> mapOCR=new Map<string,string>(); string FirstPrimaryContact; public integer RowIndex{get;set;} set<Id> conIds = new Set<Id>(); public string PrimaryAccount{get;set;} public string delOPRId{get;set;} Map<string,string> mapOPR=new Map<string,string>(); string FirstPrimaryAccount; set<Id> AccIds = new Set<Id>(); /* New Approach */ List<Account> lstAcc=new List<Account>(); public list<MainConAccRoleWrap> lstMainConAccRoleWrap{get;set;} List<OpportunityContactRole> lstOCR=new List<OpportunityContactRole>(); List<Partner> lstOPR=new List<Partner>(); Map<Id,Account> mapIDAcc=new Map<Id,Account>(); Map<Id,Contact> mapIDCon=new Map<Id,Contact>(); public List<SelectOption> OPRRoleOptions{get;set;} set<string> setOPRRole=new set<string>(); Map<string,integer> MapMerge=new Map<string,integer>(); // Account,Role set<integer> MergeIndex=new set<integer>(); Map<string,integer> MapParterAccId=new Map<string,integer>(); // modification code for contact role auto populate. public string mylookupvalue{get;set;} public contact cons{get;set;} public void getcontactrole() { cons=[select id,name,role__c from contact where name=:mylookupvalue limit 1]; } Public OppContactRoleController (){//ApexPages.StandardController cntrl try{ }catch(exception ex){ system.debug('------Error------'+ex.getMessage()+'-----ar Line #----------'+ex.getLineNumber()); } OPRRoleOptions= new List<SelectOption>(); lstMainConAccRoleWrap=new list<MainConAccRoleWrap>(); RowIndex=-1; try{ strId=ApexPages.currentPage().getParameters().get('Id'); ShowView=false; string IsNew=ApexPages.currentPage().getParameters().get('IsNew'); string IsInline=ApexPages.currentPage().getParameters().get('IsInline'); if(IsInline=='1'){ ShowView=true; } OPRRoleOptions(); contactList = new List<Contact>(); for(OpportunityContactRole cRole :[Select Id,ContactId,IsPrimary,Role from OpportunityContactRole where Role!=null and OpportunityId =: strId]){ if(cRole.IsPrimary){ PrimaryContact=cRole.Id; FirstPrimaryContact=cRole.Id; } lstOCR.add(cRole); conIds.add(cRole.ContactId); } for(Partner oRole :[Select Id,AccountToId,IsPrimary,Role from Partner where Role!=null and AccountToId!=null and AccountFromId=null and OpportunityId =: strId]){ lstOPR.add(oRole); AccIds.add(oRole.AccountToId); integer PartnerOccurCount=MapParterAccId.get(oRole.AccountToId)==null?0:MapParterAccId.get(oRole.AccountToId); // MapParterAccId.put(oRole.AccountToId,PartnerOccurCount++); } contactList = [Select Id, Name, AccountId from Contact where Id in: conIds]; for(Contact ObjCon:contactList){ mapIDCon.put(ObjCon.Id,ObjCon); AccIds.add(ObjCon.AccountId); } lstAcc=[Select Id, Name,BillingStreet,BillingCity, BillingState, BillingCountry from Account where Id in: AccIds]; for(Account ObjAcc:lstAcc){ mapIDAcc.put(ObjAcc.Id,ObjAcc); } integer i=0; for(OpportunityContactRole objOCR:lstOCR){ lstMainConAccRoleWrap.add(new MainConAccRoleWrap(objOCR.Id,objOCR,new Partner(),mapIDAcc.get(mapIDCon.get(objOCR.ContactId).AccountId),objOCR.IsPrimary,lstMainConAccRoleWrap.size(),new Contact(AccountId=mapIDCon.get(objOCR.ContactId).AccountId))); MapMerge.put(String.ValueOf(mapIDCon.get(objOCR.ContactId).AccountId),i); i++; } for(Partner objOPR:lstOPR){ If(!MapMerge.Keyset().Contains(String.ValueOf(objOPR.AccountToId))){ lstMainConAccRoleWrap.add(new MainConAccRoleWrap(objOPR.Id,new OpportunityContactRole(OpportunityId=strId),objOPR,mapIDAcc.get(objOPR.AccountToId),objOPR.IsPrimary,lstMainConAccRoleWrap.size(),new Contact(AccountId=objOPR.AccountToId))); } else{ integer IndexUpd=MapMerge.get(String.ValueOf(objOPR.AccountToId)); if(!MergeIndex.Contains(IndexUpd)){ MainConAccRoleWrap objUpd=lstMainConAccRoleWrap[IndexUpd]; string RecordId=objUpd.RecordId+','+objOPR.Id; objUpd.RecordId=RecordId; objUpd.objOPR=objOPR; objUpd.IsPrimary=objOPR.IsPrimary; objUpd.objAcc=mapIDAcc.get(objOPR.AccountToId); objUpd.objCon=new Contact(AccountId=objOPR.AccountToId); lstMainConAccRoleWrap[IndexUpd]=objUpd; MergeIndex.add(IndexUpd); } } } if(IsNew=='1'){ ShowView=true; lstMainConAccRoleWrap.add(new MainConAccRoleWrap(null,new OpportunityContactRole(OpportunityId=strId),new Partner(),new Account(),false,lstMainConAccRoleWrap.size(),new Contact())); } } catch(Exception Ex){ system.debug('-------Exception-------'+ex.getMessage()+'------at Line #-----'+ex.getLineNumber()); } delRecordId=null; system.debug('---lstMainConAccRoleWrap--Load-'+lstMainConAccRoleWrap); } Public class MainConAccRoleWrap{ public OpportunityContactRole objOCR{get;set;} public Partner objOPR{get;set;} public boolean IsPrimary{get;set;} public integer iIndex{get;set;} //public Contact objCon{get;set;} Contact objCon1, public Account objAcc{get;set;} public string RecordId{get;set;} //public List<SelectOption> ObjOPRole{get;set;} public Contact objCon{get;set;} // string RecordId,OpportunityContactRole objOCR,Partner objOPR,Account objAcc,boolean IsPrimary,integer iIndex,Contact objCon public MainConAccRoleWrap(string RecordId1,OpportunityContactRole objOCR1,Partner objOPR1,Account objAcc1,boolean IsPrimary1,integer iIndex1,Contact objCon1){ this.RecordId=RecordId1; this.objOCR=objOCR1; this.objOPR=objOPR1; this.IsPrimary=IsPrimary1; this.iIndex=iIndex1; //this.objCon=objCon1; this.objAcc=objAcc1; this.objCon=objCon1; } } public void AddNew(){ ShowView=true; lstMainConAccRoleWrap.add(new MainConAccRoleWrap(null,new OpportunityContactRole(OpportunityId=strId),new Partner(),new Account(),false,lstMainConAccRoleWrap.size(),new Contact())); } public void RemoveExcess(){ ShowView=true; System.debug('----------contactList----------'+contactList); } public void setPrimary(){ system.debug('---PrimaryContact ---'+PrimaryContact ); } public pageReference DelOCR(){ if(!string.IsEmpty(delRecordId)){ delRecordId= lstMainConAccRoleWrap[RowIndex].RecordId; if(delRecordId.contains(',')){ string[] delArr=delRecordId.split(','); Database.delete(delArr[0]); Database.delete(delArr[1]); } else{ Database.delete(delRecordId); } } ShowView=false; pageReference pg=new PageReference('/'+strId); pg.setredirect(true); return pg; } public pageReference Back(){ pageReference pg=new PageReference('/'+strId); //pageReference pg=new PageReference('/apex/OppcontactRolePage?Id=00617000005UyFO&IsInline=1'); pg.setredirect(true); return pg; } public void PrepareView(){ try{ system.debug('---lstMainConAccRoleWrap---Save--'+lstMainConAccRoleWrap); List<OpportunityContactRole> lstOCRDML=new List<OpportunityContactRole>(); List<Partner> lstOPRDML=new List<Partner>(); // string RecordId,OpportunityContactRole objOCR,Partner objOPR,Account objAcc,boolean IsPrimary,integer iIndex,Contact objCon set<string> setPartnerAcc=new set<string>(); for(MainConAccRoleWrap objMCA:lstMainConAccRoleWrap){ if(objMCA.objOCR.ContactId!=null && objMCA.objOCR.Role!=null && objMCA.objOCR.Role!='--None--'){ if(PrimaryContact==objMCA.RecordId){ objMCA.objOCR.IsPrimary=true; } lstOCRDML.add(objMCA.objOCR); } // if(objMCA.objOPR.Role!=null && objMCA.objOPR.Role!='--None--'){ //objMCA.objCon.AccountId!=null && String PartnerAccId=''; if(objMCA.objCon!=null && objMCA.objCon.AccountId!=null){ PartnerAccId=objMCA.objCon.AccountId; } else{ if(!string.IsEmpty(objMCA.objOCR.ContactId)){ if(mapIDCon.get(objMCA.objOCR.ContactId)!=null){ PartnerAccId=mapIDCon.get(objMCA.objOCR.ContactId).AccountId; } else{ PartnerAccId=[select AccountId from Contact where Id=:objMCA.objOCR.ContactId].AccountId; } } } //integer PartnerOccurCount=MapParterAccId.get(PartnerAccId)==null?0:MapParterAccId.get(PartnerAccId); // PartnerOccurCount<=1 && if(!string.IsEmpty(PartnerAccId) && !setPartnerAcc.contains(PartnerAccId)){ Partner objPartNew=new Partner(); objPartNew.Role=objMCA.objOPR.Role; objPartNew.AccountToId=PartnerAccId; if(PrimaryContact==objMCA.RecordId){ objPartNew.IsPrimary=objMCA.IsPrimary; } objPartNew.OpportunityId=strId; lstOPRDML.add(objPartNew); //if(PartnerOccurCount==0){ // MapParterAccId.put(PartnerAccId,PartnerOccurCount++); //} setPartnerAcc.add(PartnerAccId); } // } } if(!lstOCRDML.IsEmpty()){ Upsert lstOCRDML; } Delete[select Id from Partner where OpportunityId=:strId]; if(!lstOPRDML.IsEmpty()){ Upsert lstOPRDML; } ShowView=false; }catch(exception ex){ system.debug('------Error------'+ex.getMessage()+'-----ar Line #----------'+ex.getLineNumber()); ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'------Error------'+ex.getMessage()+'-----ar Line #----------'+ex.getLineNumber()); ApexPages.addMessage(myMsg); } } public pageReference SaveAll(){ PrepareView(); pageReference pg=new PageReference('/'+strId); pg.setredirect(true); return pg; } public void QuickSave(){ PrepareView(); } public void OPRRoleOptions() { Schema.DescribeFieldResult fieldResult = Partner.Role.getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); OPRRoleOptions.add(new SelectOption('--None--', '--None--')); for( Schema.PicklistEntry f : ple) { OPRRoleOptions.add(new SelectOption(f.getLabel(), f.getValue())); setOPRRole.add(f.getLabel()); } } }
I would recommend the Use Of javascript remoting here for the scenatio specified.

hi prakash, i am new to this type of modification, could u give me the full code please.