You need to sign in to do that
Don't have an account?
Kunal Purohit 4
How to write trigger for REST API?
Hello All,
I am having two Fields ZipCode__c and TimeZone__c, Now whenever user enters ZipCode__c, TimeZone__c should be updated accordingly. Here I have to use REST API for ZipCode. I am new to salesforce. Please help to write the trigger for same.
Thanks.
Try the below
trigger UpdateTimezone on Account (after insert) {
// Get the zipcode from the inserted records
Set<String> zipcodes = new Set<String>();
for (Account acc : Trigger.new) {
zipcodes.add(acc.ZipCode__c);
}
// Call the REST API to get the timezone information for the zipcodes
Map<String, String> zipcodeToTimezone = getTimezoneFromAPI(zipcodes);
// Update the timezone field on the records
for (Account acc : Trigger.new) {
acc.Timezone__c = zipcodeToTimezone.get(acc.ZipCode__c);
}
update Trigger.new;
}
private static Map<String, String> getTimezoneFromAPI(Set<String> zipcodes) {
// Code to call the REST API and parse the response to get the timezone information
}