You need to sign in to do that
Don't have an account?
Nico Wrenn
Help writing my first apex trigger - I have a simple use case in mind
Hello World!
I have a use case that requires a trigger and it sounds about as simple as it gets. We have an external application called BrightTALK integrated with our Salesforce org. Trouble is, we use State and Country Picklists and BrightTALK tries to push Leads into our Salesforce org with Country names that do not match the countries in our Salesforce org. As far as I know, there are two ways to tackle this issue. 1) Change the list of Countries in our Salesforce org. 2) Write a before trigger, which, if I understand correctly, could change a Country value like "China (Hong Kong)" into "China", which our org would then accept because the value matches a value in our State and Country Picklists setup.
I have never written a trigger before, and I took one programming class 10 years ago. Does anyone have any recommended places to start, sample code to look at, reference material to refer me to where I can see the methods available to me in an before trigger and learn some syntax? Any help is much appreciated.
I have a use case that requires a trigger and it sounds about as simple as it gets. We have an external application called BrightTALK integrated with our Salesforce org. Trouble is, we use State and Country Picklists and BrightTALK tries to push Leads into our Salesforce org with Country names that do not match the countries in our Salesforce org. As far as I know, there are two ways to tackle this issue. 1) Change the list of Countries in our Salesforce org. 2) Write a before trigger, which, if I understand correctly, could change a Country value like "China (Hong Kong)" into "China", which our org would then accept because the value matches a value in our State and Country Picklists setup.
I have never written a trigger before, and I took one programming class 10 years ago. Does anyone have any recommended places to start, sample code to look at, reference material to refer me to where I can see the methods available to me in an before trigger and learn some syntax? Any help is much appreciated.
1) Assuming there are no other integrations, One other option is to use API name of picklist values. Change API name to match with the country name of Bright TALK systems.
2) If there are other systems or code that use these names in the current system
Create a custom metadata that has mapping between Country code in salesfroce and corresponding country code in Bright Talk
Then create a trigger on the lead object and populate sfdc country with from mapping this way you dont have to change code if there are new countries added or changed in future .
You can go through https://trailhead.salesforce.com/en/modules/custom_metadata_types/units/custom_metadata_types_overview
and then create trigger and developer community will be able to help once you start based on solution you choose.
All Answers
I would suggest something like below,
Trigger is also taken cared for All newly coming records, all updating records and also for the records who are getting undeleted who once had "China (Hong Kong)" as a value in country field.
Hope it helps and if it solves the question then please mark it as best answer!
1) Assuming there are no other integrations, One other option is to use API name of picklist values. Change API name to match with the country name of Bright TALK systems.
2) If there are other systems or code that use these names in the current system
Create a custom metadata that has mapping between Country code in salesfroce and corresponding country code in Bright Talk
Then create a trigger on the lead object and populate sfdc country with from mapping this way you dont have to change code if there are new countries added or changed in future .
You can go through https://trailhead.salesforce.com/en/modules/custom_metadata_types/units/custom_metadata_types_overview
and then create trigger and developer community will be able to help once you start based on solution you choose.