You need to sign in to do that
Don't have an account?
Brent Woodard 10
Need to create my first trigger
I have a custom field on my Lead object, it's a pick list named LeadSource.
On my custom object "Checkout" whenever someone uses a lookup relationship to select the lead, I want it to automatically fill out a custom field on that called marketing source. I need it to do something like the code written below. I'm a C# developer by history and I'm not even sure if I need to create a new object here or if everything is already loaded.
Here is the code I wrote, I wouldn't think it would be much more complicated than this but I need help.
On my custom object "Checkout" whenever someone uses a lookup relationship to select the lead, I want it to automatically fill out a custom field on that called marketing source. I need it to do something like the code written below. I'm a C# developer by history and I'm not even sure if I need to create a new object here or if everything is already loaded.
Here is the code I wrote, I wouldn't think it would be much more complicated than this but I need help.
trigger <SetMaketingSource> on Checkout__c (before insert, after insert, after update) { Lead.LeadSource = Checkout__c.Marketing_Source__c }
https://help.salesforce.com/articleView?id=000213419&type=1
https://douglascayers.com/2017/04/02/use-process-builder-to-update-related-records-when-activities-logged/
https://salesforcesidekick.com/2016/07/11/how-to-work-with-related-records-in-process-builder-criteria/
Approach 1 - Formula Field
>> I hope u alreday created a loop up fiel;d on CheckOut object to make a relationship with Lead
>> If u want to make "marketing source" custom field in Checkout object as a formula field then it will be prety easy
>> Craete a formula field Class "Marketing Source" and make formula return type as "Text" and use below formula. (FYI- There is a standard field called LeadSource present in lead object. i hope u are talking baout this. If not also no issue, u can just update the field in formula)
Text(Lead__r.LeadSource)
>> Now if you create a Checkout record and selected a Lead, then this formula field will auto populate with the lead source of the lead that u selected.
>> Result
Approach 2- Process Builder/Workflow
>> If u dont want formula field, then either workflow or a process builder will do the work
>> Create a process buulder on "Checkout" Object
>> Select "when a record is created or edited"
>> Then in criteria select as below (Lead__c is the custom look up field on checkout object which having relationship with Lead)
>> Then in immediate action do as below (set LeadSource from Lead to the Marketing Source of custom object Checkout)
>> Now activate the process builder and test it
>> Result
**** below are the custom field in Checkout Object i used for above. Hope it help u achive ur requirement
Field Label API Name Data Type
Lead Lead__c Lookup(Lead)
Marketing Source(Formula Field) Marketing_Source_Formula__c Formula (Text)
Marketing Source(Update By Process Bldr) Marketing_Source__c Text(100)
Try the below code: