+ Start a Discussion
SamuSamu 

Update one one child record while updating parent record

HI All,

 

I have one child record in opportunit y named opportunity tool gate .On update of one field in opportunity I want to update otwo field in oppportunity tollgate.Can any one help me to do this.Advanesly appreciated for this help.

 

Thanks

Samu

Noam.dganiNoam.dgani
trigger update_app_tools on Opportunity (after update)
{
	map<Id,Opportunity> opps = = new set<Id>();
	
	for(Opportunity opp : trigger.new)
		if(opp.FIELD_YOU_WANT_TO_CHECK_IF_CHANGED != trigger.oldMap.get(opp.Id).FIELD_YOU_WANT_TO_CHECK_IF_CHANGED)
			opps.put(opp.Id,opp);
			
	List<Opportunity_tool_gate__c> opp_tool_gates;
	
	try
	{
		opp_tool_gates = [select THE_FIELD_YOU_WANT_TO_UPDATE from Opportunity_tool_gate__c where Opportunity__c IN: opps.keySet()];
	}
	catch(Exception e)
	{}
	
	if(opp_tool_gates != null && !opp_tool_gates.isEmpty())
	{
		for(Opportunity_tool_gate__c opp_tool_gate : opp_tool_gates)
		{
			opp_tool_gate.FIELD_1_TO_UPDATE__c = 'whatever you want 1';
			opp_tool_gate.FIELD_2_TO_UPDATE__c = 'whatever you want 2';
		}
		
		update opp_tool_gates;
	}
}