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
anu123anu123 

insert the value in the same object

Hi all,

     i have one object.the fields are in this object like f1__c,f2__c.These are picklists.i want the if  f1__c=='open' then

   f2__c='open'. 

              if( f1__c=='rejected') then f2__c=rejected.How to write this. using trigger or class. any one help me. can u please give me the sample code.

 

thanks in advance

anu

yashagarwalyashagarwal

You do not actually need code to do this , you can do this using one of the following :

 

 - either make F2__c as a formula field , where in teh formula value = f1__c

 

Or, if you want both to remain picklist , then you can create a workflow rule  to fire whenever the record is created or edited.

 

Teh action with it would be field update.

 

and you update f2 to f1 everytime the record is updated or created.

 

However , if you still want to do this thorugh code for object abc :

 

trigger populateF2 on abc__c (before insert,before update)

{

      for(abc x : trigger.new())

      {

              if(x.f1__c != NULL)

                     x.f2__c = x.f1__c;

      }

}

 

 

abc is ur custom object api name.

 

Hope this help. :)