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
priya bhawna shettypriya bhawna shetty 

how to write a trigger for this scenario

hai all

guys help me with this issue...

how to write a trigger that has to fire only once at life time......

 

thanks

digamber.prasaddigamber.prasad

Hi Priiya,

 

The simplest scenario I can think of to have trigger on Insert event. Since, Insert event fires only once in life cycle of a particular record.

 

If you have any specific use case, please describe in detail. I will try to help you.

 

Happy to help you!

 

Regards,

Digamber Prasad

georggeorg

Hi,

 

If you want to fire only once when record saves, you have to keep some reference which tracks howmany times it has fired this trigger when record saves.

 

This can be implemented with static variable, for that defiene a global class and declare a static varibale.

 

global class tracking

{

Static int count=0;

}

 

In the trigger:

 

Trigger accountrigger on Account(before insert)

{

if(tracking.count==0)

{

/*Proces your logic here */

tracking.count = tracking.count+1;

}

else

{

/*Trigger already fired once, so no action needed here*/

}

}

 

Hope this helps:-)

 

visit my blog here here

 

Thanks,

George

learnsfdc.blogspot.com