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
Sravanthi GSravanthi G 

If Account has 10 Contacts then in Contact checkbox field inactive then the account checkbox also inactive ?(primary account) how to createe trigger

If Account has 10 Contacts then in Contact checkbox field inactive then the account checkbox also inactive ?(primary account) how to create trigger?
 
Gokula KrishnanGokula Krishnan
Hi Sravanthi,

If any 1/10 is inactive contact, then need to update the account inactive..?

Regards,
Gokula Krishnan
Sravanthi GSravanthi G
If any 1/10 is inactive contact, then need to update the account inactive..? yes then need to update the account checkbox inactive (primary account) how to create the trigger?
Gokula KrishnanGokula Krishnan
Hi Sravanthi,

You need to write a trigger on Contact object.

Try this,
 
Trigger ContactTrg on Contact(after insert, after update){
	
	List<id> AccLst = List<id>();
	List<Account> UpdateAcc = List<Account>();
	
	For(Contact c: Trigger.new){
		if(c.ContactCheckbox == False)
			AccLst.add(c.accountid);
	}
	
	if(AccLst.size()>0){
		For(Id i : AccLst){
			Account acc = new Account();
			acc.id = i;
			acc.AccountCheckbox = false;
			UpdateAcc.add(acc);
		}
	}
		
	if(UpdateAcc.size()>0)
		update UpdateAcc;
}

Thanks  !!!

If it helps you, please mark is as best answer, so it will be helpful for other developers.