You need to sign in to do that
Don't have an account?
Populate Lookup filed value in Picklist on opportunityLineIgtem
Hi There,
I have a requirement , I want to populate the Lookupfiled value in picklist value.
I was able to populate the lookup filed ID in picklist but not the the value of lookupfiled.
below is my trigger
trigger SyncPicklistFieldwithLookupField on OpportunityLineItem (before insert) {
list<OpportunityLineItem > oppSyncList=new list<OpportunityLineItem> ();
for(OpportunityLineItem oppLineitem : trigger.new){
if(oppLineitem.Product_Test__c!=null){
system.debug('oppLineitem.Product_Test__c='+oppLineitem.Product_Test__c);
//PRODT_GROUP_NM__c is the pick list
oppLineitem.PRODT_GROUP_NM__c=oppLineitem.Product_Test__c; // Product_Test__c is the lookup field
system.debug('oppLineitem.PRODT_GROUP_NM__c='+oppLineitem.PRODT_GROUP_NM__c);
oppSyncList.add(oppLineitem);
system.debug('oppSyncList='+oppSyncList);
}
}
}
so how to populate look up filed value in pick list .
If any one know the solution please let me know.
list<OpportunityLineItem > oppSyncList=new list<OpportunityLineItem> ();
list<string> lstIds = new list<string>();
map<string,string> mapProductNames = new map<string,string>();
for(OpportunityLineItem oppLineitem : trigger.new){
if(oppLineitem.Product_Test__c!=null)
lstIds.add(oppLineitem.Product_Test__c);
}
if(lstIds != null && lstIds.size()>0){
for(Product_Test__c obj : [select Id,Name from Product_Test__c where Id IN : lstIds]){
mapProductNames.put(obj.Id,obj.Name);
}
}
for(OpportunityLineItem oppLineitem : trigger.new){
if(oppLineitem.Product_Test__c!=null){
system.debug('oppLineitem.Product_Test__c='+oppLineitem.Product_Test__c);//PRODT_GROUP_NM__c is the pick list
if(mapProductNames.get(oppLineitem.Product_Test__c) != null)
oppLineitem.PRODT_GROUP_NM__c=mapProductNames.get(oppLineitem.Product_Test__c);
system.debug('oppLineitem.PRODT_GROUP_NM__c='+oppLineitem.PRODT_GROUP_NM__c);
oppSyncList.add(oppLineitem);
system.debug('oppSyncList='+oppSyncList);
}
}
}