You need to sign in to do that
Don't have an account?
Leena Reddy
lead mapping
i have a custom field in lead and opportunity as AGE__C.and age__c field in lead is mapped to account.but now i need the same age__c field to be mapped to opportunity also...how it can be possible..how can i write a trigger for this scenario????
I am still not clear about your requirement.Could you please be more specific.
Hi vinit.Actually i have a custom field in lead,account,opportunity as AGE__c.now i need that age field value should be populated in acc,con,opp when ever the lead is converted and updated.
You need to create an update Trigger on Lead and need to use ConvertAccountId and ConvertedOpportunityId which would be generated in Lead conversion.Please go through the below link to know more about these fields :-
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_lead.htm
Can it be possible.
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
contact c=new contact();
Account ac=new Account();
opportunity op=new opportunity();
for(Lead myLead: Trigger.new){
if(myLead.isconverted==false) {
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
lc.convertedStatus = 'Closed - Converted';
c.Roll_No__c=myLead.Roll_No__c;
ac.Roll_No__c=myLead.Roll_No__c;
op.roll_no__c= myLead.Roll_No__c;
//Database.ConvertLead(lc,true);
//lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}
}
}
This seems fine to me other than the below line :-
lc.convertedStatus = 'Closed - Converted';
I won't recommend you to hard code the value rather than you should query as follow :-
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
so that in future if you change the ConvertedStatus,it won't break :)
Hello,
Can't you use the standard field mapping on lead convert?
then How can we map multiple fields ?? trigger needs to play
It's only one field getting mapped to all the objects.
Ok, my bad. I didn't understand what you wanted to say.
We can have one - to - one field mapping and here it is one - to -three. So trigger will have to come into picture.
Thanks for clarifying it :)
I tried this,but not mapping..sumthng went wrong..make changes to this
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
contact c=new contact();
Account ac=new Account();
opportunity op=new opportunity();
for(Lead myLead: Trigger.new){
if(myLead.isconverted==false) {
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
c.Roll_No__c=myLead.Roll_No__c;
ac.Roll_No__c=myLead.Roll_No__c;
op.roll_no__c= myLead.Roll_No__c;
list<account> acc =[select id,Roll_No__c from account where id in:trigger.new.getaccountid()];
system.debug('@@@@@@acc'+acc);
//Database.ConvertLead(lc,true);
//lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}
}
}
Hi,
Try below :-
trigger LeadConvert on Lead (after update) {
List<Account> accList = new List<Account>();
List<Contact> conList = new List<Contact>();
List<Opportunity> oppList = new List<Opportunity>();
//Bulkified
for (Lead lead : Trigger.new) {
if (lead.isConverted == false) //to prevent recursion
{
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
Account acc = new Account(id=lcr.AccountId,Roll_No__c=lead.Roll_No__c);
accList.add(acc);
Contact con = new Contact(id=lcr.ContactId,Roll_No__c=lead.Roll_No__c);
conList.add(con);
Opportunity opp = new Opportunity(id=lcr.OpportunityId,Roll_No__c=lead.Roll_No__c);
oppList.add(opp);
}
}
update accList;
update conList
update oppList;
}