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

Lock field value based on Status

HI All,

I have a custom object. I have a lot of apex code behind but i have come across a issue and i am not sure how to work around it.

Issue: I have custom fields taking in data from the Oppurtunity,account, and contacts object. I do this through Apex code. My issue is I want a value to be set on a field from that objects curretn record, BUT when the status is approved or pending, I want that current value to stay the same even if it changes in the related object. So, I want different versions in my custom objects records... This will show the values when it was approved on past records.

Here is a snippet of a piece of code that will return a incorrect value once this condition doesnt meet.

IF ( acctReq.Status__c!='Approved' && acctReq.Status__c!='Pending' )
            acctReq.CO_ID_Number__c = AR_Account.CO_ID_Number__c;
           acctReq.GPO_ID_Number__c = AR_Account.GPO_Id_Number__c;
            acctReq.Call_Volume__c = AR_Opportunity.Volume_Minutes_per_Month__c;
Side note: AR_Account is a object toward the accounts object and acctReq is coming from my custom object.
Could you use a workflow rule field update instead.  Only update those fields when the Status changes, except for Approved/Pending? 
Hi Gigi,

Thanks for the response. This will not work due to custom code we have on the apex page. We are doing some custom versioning on the fields. So when a user changes the value to something else they can hover over the field and see a previous value. Due to this custom code, I cannot use the work flow interface.