function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris ChahinianChris Chahinian 

Apex trigger: Update Lead Source from Custom Contact Lookup Field to Opportunity

Hi,

On Opportunities, l have a custom field called ‘Primary_Contact_Name__c’, this is a Lookup related to Contacts.

When the Primary_Contact_Name__c field is entered on an Opportunity (mandatory field) and saved, I need the Lead Source from this Primary_Contact_Name__c Contact Reord to update the Opportunity Lead Source field.

I still want to give the user the option to select a Lead Source on the Opportunity, but when they hit save, if a Lead Source already exists on the Primary_Contact_Name__c, l want it to be overridden.

If the Lead Source on the Contact is empty, l need the Opportunity Lead source the user selected to remain, and update the Lead Source on the Primary_Contact_Name__c Contact record.

I need this trigger to run ONLY when the Opportunity is first created. Once a Lead Source has been set on both Contact & Opportunities, l want it to remain for ever.

Is this possbile? Thanks
SonamSonam (Salesforce Developers) 
HI Chris, this is possible.Check the thread below to get the sample code to update the Lead Source:
http://stackoverflow.com/questions/13715218/salesforce-com-trigger-copy-contact-lead-source-to-opportunity