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
katrinaxxkatrinaxx 

Is it possible to save a record twice in a method?

Here's the scenario:

When a user sets the Status of a Case to "Complete" and its previous Status is "New", I want it to be saved as "In Progress" first (for some trigger logic to run for "In Progress" Cases), before finally saving it as "Complete".  Is this possible?  Here's a snippet of code that I tried but it did not work:

if(originalStatus == 'New' || currentSR.OwnerId != Userinfo.getUserId()) {
             String holdOnToStatus = currentSR.Status;
             String holdOnToActionTaken = currentSR.ACTN_TAKEN_TXT__c;
            
             if(originalStatus == 'New') {
                 currentSR.Status = 'In Progress';
             }
             if(currentSR.OwnerId != Userinfo.getUserId()) {
                 currentSR.OwnerId = Userinfo.getUserId();
             }
             
             controller.save(); 
             //update currentSR;           // I also tried calling update instead of standard save but neither worked 
            
             currentSR.status = holdOnToStatus;
             currentSR.ACTN_TAKEN_TXT__c = holdOnToActionTaken;
}
controller.save(); 

Thanks!
MaxPowerForceMaxPowerForce
Are you getting an error or does the record simply not have the expected values?  Is this a standard list/set controller save method?  Can you move the trigger logic to a seperate class and invoke that directly so you don't need to perform multiple database updates?  That would be a better practice if possible.