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
Vaibhav Joshi 1Vaibhav Joshi 1 

After Update trigger..

Hi all
I am new to trigger and apex coding can somebody help me for the task given below..
Update an existing trigger on Realtionship object to add following logic


trigger execution: after update


- record criteria: Relationship.RecordType.Name = "Suspension"
- Loop through records meeting above criteria and check if "Suspend__c(new value)" = true and Suspend__c(new value) != Suspend__c(old value) then add record to suspended list
- Loop through suspended record list check for following
a) is suspended record is a primary(rC_Bios__Primary__c = true)? if yes, then add to Map<id(rC_Bios__Contact_2__c),id(relationship.id)>mapMemberToPrimMembership

NOTE: Requirements says if a membership is suspended and suspended membership is for primary lodge, then all other active membership for same member for non-primary lodge must be put on resigned status. If membership is suspended for non-primary lodge only, then only that lodge is suspended.

- Next find all membership(relationship) records for non-primary lodges that are still active and mark them as suspended
a) to find all other membership use following soql
[Select Id, End_Date__c, rC_Bios__Active__c, Resigned__c From rC_Bios__Relationship__c Where RecordType.Name = 'Membership' and rC_Bios__Contact_2__c in: mapMemberToPrimMembership.keySet() and Id not in: mapMemberToPrimMembership.values() and rC_Bios__Active__c = true];
b) loop through each records and check if End_Date__c == null, if so then update
rC_Bios__Active__c = false
End_Date__c = today's date
Resigned__c = true
c) update the records found in step b) above
Abhi_TripathiAbhi_Tripathi
Hi Vaibhav,

Its and easy one, go for this post hope this helps
http://abhithetechknight.blogspot.in/2014/06/basics-of-apex-trigger-for-beginners.html

Regards,
Abhi Tripathi
SFDC Certified Developer