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

Static variable return null in lightning experience

I have 2 triggers.

1. trigger on parent object
2. trigger on child object

I have a class where I get and set static variables used in these triggers.

From trigger 1 I set the static variable for ex test = 'parent' and get the value of that variable in trigger 2. Works fine in classic.
But in lighning experience, the variable value comes as null in trigger 2 although I set the value in trigger 1.

In my scenerio, trigger 2 is called soon after trigger 1 and I am not using any VF or lighning components. Its a standard page.

So my question is:

Is there way to store the data (like we used static variables in classic) that is available through out that transaction in lightning experience?

NagendraNagendra (Salesforce Developers) 

Static variables are implicitly transient, which means their state is not stored in the view state (meaning each transaction starts all static variables as null). Use an apex:actionFunction if you expect to be able to interact with the view state, and make sure your variable is not static.

Hope this helps.

Thanks Nagendra. 

My scenerio is :

I have written 2 triggers, one on quote and other on quote line item. When I create quote, I want to set a value in my quote trigger which will be then accessed by  quotelineitem trigger. As you might be aware, when we create a quote for an opportunity, the opportunity line items are copied as quote line items that new quote. Hence quote trigger and quote line item trigger both are called in that trasaction.

Using static variable works perfectly in classic. No issues.

But the way static variable are called by lightning experiance(architecture wise) might be different. May be class is reset between each trigger.

So I am looking for alternative solution to store the data between these triggers in lightning experience.

Any suggestion is much appreciated.