You need to sign in to do that
Don't have an account?
JD Sprague
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,
Thank you for sharing this valuable information on mapping Lead Record Type to Opportunity Record Type. The need for an effective solution in this area is evident for many Salesforce developers, and the contributions here provide valuable insights.
I'd like to add a couple of pointers:
Bulk Processing: While the provided triggers seem to work well for individual records, always ensure that they are bulkified to handle the processing of multiple records simultaneously, especially in scenarios involving data migrations or mass updates.
Error Handling: Always include robust error handling in your triggers to manage exceptions. This ensures that your trigger doesn't fail silently, leaving users confused.
Unit Testing: Before deploying any trigger to production, it's essential to have comprehensive test classes written that cover various scenarios to ensure the trigger works as expected. Aim for at least 90% code coverage and make.
There is Another Version for PC as well you can check it on (https://carparkapk.com/car-parking-multiplayer-mod-apk-for-pc/)