You need to sign in to do that
Don't have an account?
Tzemach Aronow 4
Trigger to create 2nd record when creating a record within the same object
Im trying to create a trigger simmilar to the npsp relationship pack, that when I create a reationship record on contact "A", it should create a duplicate relationship on the record of contact "B".
I'm new to SF and I have tried a few ways but I'm still having trouble with my code.
I'm new to SF and I have tried a few ways but I'm still having trouble with my code.
trigger NewRelationships on Relationship__c (after insert) { List<relationship__c> NewRelationship = new List <relationship__c> {}; for (relationship__c x : Trigger.new) { relationship__c NewRec = new relationship__c( First_person_in_relationship__c = x.Second_person_in_relationship__c, First_person_is_second_persons__c = x.Second_Person_is_first_persons__c, Second_person_in_relationship__c = x.First_person_in_relationship__c, Second_Person_is_first_persons__c = x.First_person_is_second_persons__c); NewRelationship.add(x); } insert NewRelationship; }
It is becuase of recursion
When you insert newRelationship records from Trigger, The trigger will again call after insertion.
You must stop this recursion using a static variable
Create a class
and use this static variable in the Trigger
Choose it as Best Answer if it resolves your issue