Skip to main content
Supriya Hirurkar (Salesforce) 님이 #Apex에 질문했습니다

Little confused about the scope of a static variable here. I have 2 scenarios:

  • Two recursive trigger methods A and B in the same transaction - Does it mean will I need two static variables a and b to apply the recursion control for each one? And if this is true, does this mean I will need , e.g. 6 static variables doing the same thing to control 6 recursive methods in a single transaction? 😮
  • How does this scenario differ when I rather have 2 users instantiating the same transaction at the same time?

I went through the SF documentation and I couldn't get a clear idea on this. Any help on this would be greatly appreciated.

답변 5개
  1. 2019년 8월 6일 오후 10:26
    I just tested and verified this. You will need two different variables if you have two recursive methods in a single transaction. 

    Because the static variable retains it's value for the scope of the transaction, for one method I will need the value of a static boolean true and for the other, I will need to be false - and in order to achieve this, I need to have 2 differnt variables. just one would not suffice.