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

Lead Record Type to Opportunity Record Type Apex Trigger
I am looking to map the Lead Record Type to the Opportunity Record Type when I convert the lead. Right now the Opportunity Record Type populates with a default value. I have only written a few apex triggers as of now and am still new to salesforce, I appreciate any help!
1)(Can be done using the out-of-box functionality: Create a custom field on Lead object which stores the value of lead record type and map it to a custom field on the Opportunity side such that it stored the value of the lead record type
2)Write a before insert trigger on opportunity such that it looks at this value of the custom field and sets the record type of the opportunity
All Answers
1)(Can be done using the out-of-box functionality: Create a custom field on Lead object which stores the value of lead record type and map it to a custom field on the Opportunity side such that it stored the value of the lead record type
2)Write a before insert trigger on opportunity such that it looks at this value of the custom field and sets the record type of the opportunity
trigger AddPrimaryContactToConvertedOpp on Lead (After Update) {
// THIS TRIGGER WILL OVERWRITE ANY CONTACT DEFINED IN THE CUSTOM FIELD CONTACT__C ON THE OPPORTUNITY OBJECT.
// SET THIS FIELD TO READ ONLY OR CHANGE THE FUNCTIONALITY BELOW TO AVIOD DATA BEING OVERWRITTEN BY MISTAKE...
// [1] Build list of Oppos to update
List<Opportunity> oUpdList = new List<Opportunity> ();
for (Lead l : Trigger.new)
if (l.IsConverted && l.convertedOpportunityId != null)
oUpdList.add(new Opportunity(id = l.convertedOpportunityId, name = l.name));
// [2] Update the converted Oppos
update oUpdList; // could be Database.update(oUpdList,false) if you want partial successes
}
this trigger updates a field in the new opportunity but will not work with the recordtype for some reason.
Here is the Sample Code,