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
v varaprasadv varaprasad 

Trigger For lookuprelationship

Hi All

   A and B are objects having lookup relationship
   A is parent and having status field
   B is child having status field
here my requiremeent is parent is having n on of childs in child what is the staus field value i need to update same thing in parent....

Thanks to alll
 
Amit Chaudhary 8Amit Chaudhary 8
Please try below code :- 
trigger AccountTrigger on Contact( after insert, after update)
{
	Set<String> setId = new Set<String>();
	for( Contact cont : trigger.New)
	{
		setId.add(cont.accountId);
	}
	Map<Id,Account> mapAcc = new Map<Id,Account>([select id,name,status__c from account where id in :setId ]);

	List<Account> listAccountToUpdate = new List<Account>();
	for( Contact cont : trigger.New)
	{
		if(mapAcc.containsKey(cont.AccountId))
		{
			Account acc =mapAcc.get(cont.AccountId);
			acc.Status__C = cont.Status__c;
			listAccountToUpdate.add(acc);
		}
	}
	
	if(listAccountToUpdate.size() >0)
	{
		update listAccountToUpdate;
	}

}

Please mark this as solution if this will help you
ManojjenaManojjena
Hi v varaprasad,

Here I have a small query if you have 5 child with diffreent status which status you need to update in parent ?
You want to update status from parent to child or from child to parent ?

 
sandeep sankhlasandeep sankhla
Hi V,

In this case trigger is not required, you can simply use process bulder to update parent status based on child status....

Please check and let me know if you haev any doubts.

Thanks,
Sandeep
v varaprasadv varaprasad
Hi thanks All