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

populated the lookup filed in text field
i Have created the handler for that in the text filed i want the name but populated the id following is my code
public class Populatedlookup {
Public void updateField(List<Lead> leadList){
/*
for(lead l : leadList){
leadId.add(l.Id);
System.debug('leadid'+ leadId.add(l.Id));
}
lead leadOne = [select id, name, Channel_Partner__c from lead where Id IN: leadId];
if(leadOne.Channel_Partner__c!=null){
Distributor__c dis = [select id, name from Distributor__c where Id=:leadOne.Channel_Partner__c];
DistributorName = dis.Name;
*/
for(Lead leadObj:LeadList){
if(leadObj.Channel_Partner__c!=null){
leadObj.Channel_Partner_Text__c=leadObj.Channel_Partner__r.Name;
}
else{
leadObj.Channel_Partner_Text__c='';
}
}
}
}
public class Populatedlookup {
Public void updateField(List<Lead> leadList){
/*
for(lead l : leadList){
leadId.add(l.Id);
System.debug('leadid'+ leadId.add(l.Id));
}
lead leadOne = [select id, name, Channel_Partner__c from lead where Id IN: leadId];
if(leadOne.Channel_Partner__c!=null){
Distributor__c dis = [select id, name from Distributor__c where Id=:leadOne.Channel_Partner__c];
DistributorName = dis.Name;
*/
for(Lead leadObj:LeadList){
if(leadObj.Channel_Partner__c!=null){
leadObj.Channel_Partner_Text__c=leadObj.Channel_Partner__r.Name;
}
else{
leadObj.Channel_Partner_Text__c='';
}
}
}
}
Hope you are calling this method from trigger ,if so then you need to do a additional query to parent object field details .
Try with below code ,if the parent object name is different then plz change .
public class Populatedlookup {
Public void updateField(List<Lead> leadList){
Set<Id> chanelIdSet= new Set<Id>();
Map<Id,Channel_Partner__c> chanelMap;// Change Object Name if diffrent
for(Lead leadObj:LeadList){
if(leadObj.Channel_Partner__c!=null){
chanelIdSet.add(leadObj.Channel_Partner__c);
}
}
if(!chanelIdSet.isEmpty()){
chanelMap= new Map<Id,Channel_Partner__c>([SELECT Id,Name FROM Channel_Partner__c WHERE Id IN : chanelIdSet ]);
}
for(Lead leadObj:LeadList){
if(leadObj.Channel_Partner__c!=null){
if(!chanelMap.isEmpty() && chanelMap.get(leadObj.Channel_Partner__c) != null){
leadObj.Channel_Partner_Text__c= chanelMap.get(leadObj.Channel_Partner__c).Name;
}
}else{
leadObj.Channel_Partner_Text__c='';
}
}
}
}
Let me know if it helps !!
Thanks
Manoj
All Answers
Hope you are calling this method from trigger ,if so then you need to do a additional query to parent object field details .
Try with below code ,if the parent object name is different then plz change .
public class Populatedlookup {
Public void updateField(List<Lead> leadList){
Set<Id> chanelIdSet= new Set<Id>();
Map<Id,Channel_Partner__c> chanelMap;// Change Object Name if diffrent
for(Lead leadObj:LeadList){
if(leadObj.Channel_Partner__c!=null){
chanelIdSet.add(leadObj.Channel_Partner__c);
}
}
if(!chanelIdSet.isEmpty()){
chanelMap= new Map<Id,Channel_Partner__c>([SELECT Id,Name FROM Channel_Partner__c WHERE Id IN : chanelIdSet ]);
}
for(Lead leadObj:LeadList){
if(leadObj.Channel_Partner__c!=null){
if(!chanelMap.isEmpty() && chanelMap.get(leadObj.Channel_Partner__c) != null){
leadObj.Channel_Partner_Text__c= chanelMap.get(leadObj.Channel_Partner__c).Name;
}
}else{
leadObj.Channel_Partner_Text__c='';
}
}
}
}
Let me know if it helps !!
Thanks
Manoj