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
Paula Jarvis 18Paula Jarvis 18 

Update an apex trigger

Our org is fairly new, 15 months and I have an Apex Trigger that auto creates a Membership record based on one day after the Expiration Date. The new Membership record is created with one day added, My question is related to the "deactivation" of the prevous record when the new reord is created. I am completely new to Apex as this is an urgent request to get this automated so we can remove the manual updates to the "older" Memberhsip records, either by individual or data load. here is my trigger. How to modify to deactivate the previous membership record?
**/
trigger MembershipTrigger on Membership__c (before insert, after insert, after update) {
    
    if(Trigger.isInsert && Trigger.isBefore) {
        MembershipHelper.SetPreviousMembership( (List<Membership__c>)Trigger.new );
    }

    if(Trigger.isAfter) {
        MembershipHelper.UpdateAccountJoinDate( (List<Membership__c>)Trigger.new );
    }
}
 
Andrew GAndrew G
Hi Paula

What you have there is the Trigger which is calling what is genericly refered to as a Trigger Handler.

You will need to post the code for the MembershipHelper class for any one to give some feedback.  Once someone sees the Handler class they can perhaps gives you some direction on what changes will be required.  Whilst many would have a few thoughts i their heads on how to do this, the Handler class may have some methods already created which would save the code effort.

note, if you could use the code sample button for the code component when posting, it does make the code easier to read and sample.
User-added image

Regards
Andrew