You need to sign in to do that
Don't have an account?
Pushkar Gupta
hi, trigger on account to update contact information
i have a question regarding trigger. I have two custom field on Account namely Country And State., And same field on Contact Whenever i choose the country on contact state get automatically filled using account state field if the country is same in account field.
Please run this code.
//Apex Helper class//
public class automaticallyFillContactState {
public static void contactState(map<Id,Account> newAccMap){
set <id> IdCollect = newAccMap.keySet();
List<Contact> toUpdateconList = new List<Contact>();
if(IdCollect.size() > 0){
List <Contact> conList = [SELECT Country__c,AccountId From Contact WHERE AccountId IN :IdCollect];
if(conList.size()>0){
for(Contact c:conList){
if(c.Country__c==newAccMap.get(c.AccountId).Country__c){
c.State__c = newAccMap.get(c.AccountId).State__c;
toUpdateconList.add(c);
}
}
}
if(toUpdateconList.size()>0){
update toUpdateconList;
}
}
}
}
//Trigger Class//
trigger automaticallyFillContactStateTrigger on Account ( before update) {
if(Trigger.isBefore && Trigger.isUpdate){
automaticallyFillContactState.contactState(Trigger.NewMap);
}
}
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
Please try the below code
If you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay
Please run this code.
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
try this code to when Account and contact have no relation
if you found this answer helpful then please mark it as best answer so it can help others.
Thanks
Akshay