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
VisualForceVisualForce 

How to avoid ininity loop in trigger

Hi..
      I have write one trigger in contact Custom object... It has a Account lookup
When I create a new contact I have assign a Account ..
If this contact is first child record for Account then I have to update one contact field (Parent__c checkbox=true)
 
Here I am try after insert
 
Any one has a sample code for update same object using trigger post it..
 
Is it possible in trigger
 
tmatthiesentmatthiesen
move your logic to a "before insert and before update" trigger.
mikefmikef
Just to make sure what you are trying to do.
You have a trigger on your custom contact object, it looks for the correct account to link to the new custom contact.
Then you have an account trigger that will update the newly added custom contact if it's the first contact under the account.

Not only move your logic to the before trigger like tmatthiesen suggested, but move the first contact logic to the contact trigger.

On insert or update look for all the contacts on the linked account and store them in a map.
Then do a simple map lookup to see if this contact has any friends on the account.
If no friends check the Parent box.

Take the account trigger out of the process, if it's there.


Message Edited by mikef on 11-05-2008 10:22 AM