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
imAkashGargimAkashGarg 

update trigger only for the first time

i want to write a update trigger. what is the best practise approch to fire this update trigger only for the first time?

Best Answer chosen by Admin (Salesforce Developers) 
ashish raiashish rai

Hello,

  You may use this also:

 



triegger xyz on myobject(before update)

{

     if(triggenr.new[0].createddate == trigger.new[0].LastModifiedDate )

    {

         put your entire code here.

    }

}

 

Think this will  help you.

All Answers

ashish raiashish rai

Hello,

    Well you can achieve through by creating a new customfield inside your object and assign a value to that field whenever a record is created or updated. You may write a workflow to update that field. For example supoose you have assign that field value i.e. 1 at the time of creation.Now write a workflow for upation of that object and update that field value with one. So now inside your trigger mention that condiotion like this:

 

triegger xyz on myobject(after update)

{

     if(triggenr.new[0].yourcustomfield == 1)

    {

         put your entire code here.

    }

}

 

Think this will help you.

ashish raiashish rai

Hello,

  You may use this also:

 



triegger xyz on myobject(before update)

{

     if(triggenr.new[0].createddate == trigger.new[0].LastModifiedDate )

    {

         put your entire code here.

    }

}

 

Think this will  help you.

This was selected as the best answer
imAkashGargimAkashGarg

Thanks Ashish,

 

i was trying with the first approch you told. But i think, the second one you told should be the best practice approach.

ashish raiashish rai

Hello,

    Yeah r8.In second case you dont have to create any custom field and make sure that you are using before update not after update,for after update you have to use the first one.Any way happy to know that it resolve your issue.Cheers