You need to sign in to do that
Don't have an account?
Prashant Pandey.
Write a trigger to update the state as per the city on Contact. Trigger should work on insert, update. If city is C1 , State should be S1. If city is C2 , State should be S2. If city is C3 , State should be S3.
Avoid IF ELSE bcz if we have 100 or 1000 records then what we can do ?? Need Dynamic trigger or some thing new from you.
WARMS REGARD,
Prashant Pandey
WARMS REGARD,
Prashant Pandey
By using the below ways you can avoid the Multiple if conditions. But you have to create the data(City State combination ) in custom Setting or Metadata.
1. Use the Custom Setting to store the City, State Combination. For Storing the State in custom setting create one custom field in Custom Setting and use the Standard custom setting Name field to store the city name.
here am using Mailing State, Mailing City for example from Contact Object. Here i created the custom setting named CityState__c
Trigger :
2. You can also use the Custom Metadata instead of Custtom Setting. But you can't use the dataloader for custom metadate. If you want to use the Custom Metadata then change the trigger like below:
Create the custom field for storing the state and city in Custom Metadata. Here i created the custom Metadata named City_State_CMD
Trigger:
Thanks,
Maharajan.C
All Answers
Hi Prashant, I hope you are well. I am a little confused by your requirement. Is city and state on different objects? And what do you mean avoid if else? Using if else logic has nothing to do with the amount of records being processed. Also triggers should be only used when complex logic is required. You can most likely fulfill your requirement but using a process builder.
By using the below ways you can avoid the Multiple if conditions. But you have to create the data(City State combination ) in custom Setting or Metadata.
1. Use the Custom Setting to store the City, State Combination. For Storing the State in custom setting create one custom field in Custom Setting and use the Standard custom setting Name field to store the city name.
here am using Mailing State, Mailing City for example from Contact Object. Here i created the custom setting named CityState__c
Trigger :
2. You can also use the Custom Metadata instead of Custtom Setting. But you can't use the dataloader for custom metadate. If you want to use the Custom Metadata then change the trigger like below:
Create the custom field for storing the state and city in Custom Metadata. Here i created the custom Metadata named City_State_CMD
Trigger:
Thanks,
Maharajan.C