
I have code that creates a mapping from a Lead record. if i want to set values back on the Lead record, how can i do this? The code i am using is below, however, nothing seems to happen. Is this line of code possible?
LeadtaskMap.get(tsk.whoid).Status = 'Contacted'; Any suggestions?Thanks.trigger LeadTrigger on Task (before insert, before update) { List<Id> leadIds=new List<Id>(); for(Task t:trigger.new) { if(t.Status=='Completed') { if(t.whoId != null && String.valueOf(t.whoId).startsWith('00Q')==TRUE) //check if the task is associated with a lead { leadIds.add(t.whoId); }//if 2 }//if 1 }//for map<id,Lead> LeadtaskMap = new map<id,Lead>([SELECT Id, Description, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE]); for(Task tsk:trigger.new) { if(LeadtaskMap.keyset().contains(tsk.whoid)) { if(tsk.Status == 'Completed' && tsk.Subject == 'Make contact with Lead') { LeadtaskMap.get(tsk.whoid).Status = 'Contacted'; } if(LeadtaskMap.get(tsk.whoid).Description == null && tsk.Status == 'Completed' && tsk.Subject == 'Qualify Opportuntity') { tsk.adderror('Task cannot be completed until the following fields have been populated: Description'); } Else { LeadtaskMap.get(tsk.whoid).Status = 'Qualified'; } } } }2 Antworten
Please check below post. I hope that will help youhttp://amitsalesforce.blogspot.in/2014/11/dynamic-field-mapping-using-custom.html Like below code you can do.
LeadObj=new Lead();
MyLeadid=ApexPages.currentPage().getParameters().get('MyLeadid');
getAllMapping();
qry = 'select ' + qry + 'id FROM My_Lead__c where id =: MyLeadid';
My_Lead__c MyLead = Database.query(qry);
for(String sMyLeadField: MapMappingTable.keySet())
{
String sLeadField = MapMappingTable.get(sMyLeadField);
LeadObj.put(sLeadField, MyLead.get(sMyLeadField));
}
Please let us know if this will help you
ThanksAmit Chaudhary