+ Start a Discussion


Hi ....i am new to salesforce.....can u plzz guide me.....


Actullay i have a standard and Custom object..Account and Webinfo ...relationship is master-detail....

...now i have to update account fields ....the query is follows:::


select National_Code__c, PersonEmail,  Account where National_Code__c=:input.UserId  but now i have to update Webinfo custom object based on this::::   In webinfo i have to update professional and two more fields.....Account id is used to link with professional in webinfo...


Thanks in advance........


Can you explain bit more?


Where have you written the mentioned query ?

Andy BoettcherAndy Boettcher

Taking a stab at this...


It sounds like you are updating the child object when you update the parent?


In the vein of always do declaratively before doing it programatically:


  • You could use formula fields on your child object that reference the parent
  • You could use workflow (cross-object coming in Spring)

There have been times when I have had to use APEX to update parent or child objects due to certain business requirements, and to do so (assuming you're updating the parent)..


trigger UpdateChildObject on Account (after update) {

	// This code will update all child objects with parent values
	// This is pseudo-code, please verify object and field names!
	if(trigger.isAfter && trigger.isUpdate) {
		// Create Map of Account Values
		Map<Id, Account> mapAccounts = new Map<Id, Account>();
		for(Account a : trigger.new) { mapAccounts.put(a.Id, a); }
		// Query all Child Objects
		List<ChildObject__c> lstChildren = [SELECT AccountId__c, ChildField1__c, ChildField2__c FROM ChildObject__c WHERE AccountId__c IN :Trigger.newMap.keySet()];
		// Loop through Child Objects and update
		for(ChildObject__c c : lstChildren) {
			c.ChildField1__c = mapAccounts.get(c.AccountId__c).ParentField1__c;
			c.ChildField2__c = mapAccounts.get(c.AccountId__c).ParentField2__c;
		// Update List
		if(lstChildren.size() > 0) { update lstChildren; }




 Check that out - let me know if that does it for you.