function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kaustubh chandratre 2kaustubh chandratre 2 

Create a trigger whenever Account industry field changess, please updates its all related Contact field Account_Indytry__c from Account.

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Kaustubh,

Can you try the below apex trigger on Account Object.
 
trigger AccountIndustry on Account (after update) {
    
    map<id,Account> mapacc= new Map<Id,Account>();
    for(Account acc: Trigger.new){
     Account   OldAccount = Trigger.oldmap.get(acc.id);
        
        if(acc.industry!=oldAccount.Industry){
            mapacc.put(acc.id,acc);
        }
        
    }
    if(mapacc.size()>0){
    List<Contact> clist=[select id,Account_Industry__c,Accountid from Contact where accountid in :mapacc.keySet()];
List<Contact> contoupdate= new List<Contact>();
    for(Contact con:clist){
        if(mapacc.containsKey(con.accountid)){
            con.Account_Industry__c=mapacc.get(con.AccountId).industry;
            contoupdate.add(con);
        }
        
    }
        
        if(contoupdate.size()>0)
            update contoupdate;
    }
}

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
CharuDuttCharuDutt
Hi Kaustabh
Try Below Trigger
trigger UpdateIndustryInContacts on Account (after Update) {
    map<Id,string>AccountIds = new map<Id,string>(); 
    if(trigger.IsAfter && trigger.IsUpdate){
        for(Account oAcc : trigger.new){
            if(oAcc.Industry != trigger.oldMap.get(oAcc.Id).Industry){
                AccountIds.put(oAcc.Id,oAcc.Industry);
            }
        }
    }
    list<Contact> lstContacts = [Select Id,AccountId from Contact Where AccountId In :AccountIds.keyset() ];
    for(Contact oCon : lstContacts){
        if(AccountIds.containsKey(oCon.AccountId)){
            oCon.Industry__c = AccountIds.get(oCon.AccountId);
        }
    }
    update lstContacts;
}
Please Mark It As Best Asnwer If It Helps
Thank You!