Skip to main content
Hi

I am new in apex coading and currently looking for a help on a particular scenario. I am trying to update an existing record when I am creating a record on that same object.

Example: I have a custom object associated with an account and only one active record can be present in that custom object. Let say there is an active record present in that object already and now I am creating another record in that particular object. On the creation of the new record will automatically deactivate the previous record.

Thanks in advance
3 answers
  1. Mar 10, 2020, 8:49 AM
    Hi Anutez,

    Thanks for providng the way. I tried to pull the record but now facing the challange to update the existing record and keeping the new record as active. Can you please help. I created the below code to pull the existing account information,

    trigger Deactivate_EP on Account_Plan__c(before insert) {

        Set<Id> AccountID = new Set<Id>();

        for(Account_Plan__cAP: Trigger.new)

        {

            AccountID.add(AP.Account_vod__c);

        }

         

       List<Account_Plan_vod__c> APLIST = new List<Account_Plan_vod__c>([Select ID, Active__c,Account__c,Recordtype.Name from Account_Plan__c where Active__c = TRUE and Account__c IN:AccountID]);

    }

    After this how can I update this record present in the list.

    Thanks in advance,

    Anirban
0/9000