4

I have a visual force page and on save of which i have to pass around 500+ records to save to db. Now issue is

  1. I have a trigger which is on and does some logic
  2. I have a workflow rule which updates a field and this will re trigger my trigger .I dont want this to happen

Now i have an option to put a static variable to make sure trigger is only run once.

But if i do this, since i am passing 500 records ,trigger logic will execute only for first 200records (trigger size).

I do want trigger logic to be executed for all 500 records

How do i handle this?

I can put some logic to check against the workflow update and stop trigger from executing.But that means for every new development in organisation i need to update this trigger.

any solution?

1
  • Can you adjust the trigger logic so that the WF-updated records aren't reprocessed? Or set a value to bypass the WF/trigger?
    – Mike Chale
    Commented Jan 7, 2015 at 3:56

2 Answers 2

3

Perhaps you could introduce a static set of Ids, and on each trigger execution you could check if that set already contains all elements of trigger.newMap.keySet(). Then if the static set already contains all those IDs, you could skip that trigger run.

1
  • Or check each record individually.
    – Dominic
    Commented Jan 7, 2015 at 10:00
1

I came across this issue once but then I noticed it was working when updating as expected when using data loader but not on a test method as the static variable is mantained across the chunks of records (200 records). Having said that, this approach is proven to work in a real scenario.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .