Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

Setting values on a before insert trigger from apex class static variables

  • Request from staff

Requested business process: before insert trigger runs to validate email before insert (using managed package) > process builder runs > process builder calls flow to [do stuff].

  • Details

To make a callout I call an @future method in a class from my trigger, executing a method from managed package (listed as global).
@future method runs successfully and updates managed package fields, but not my custom fields on the lead.
I created static String fields in the class and set them during the @future method run.
I have created other static methods to return the static variable value (return myClass.variable).
In my before insert trigger, I am using the static class methods to assign values like l.custom_field__c = myClass.getVariable().
I added debug statements to the trigger, and the lead fields are coming back null, thus the lead fields are not being populated by calling the class methods.

  • Ideas

I have a feeling this is related to the transaction context (from trigger I call class callout method > from @future method set static variable values then call static method getters from trigger to assign the values back to the lead before insert).
Am I correct in thinking by the time my lead trigger calls the static getter methods, the transaction context is done, so they are back to null?
If that's correct, how can I get those values to the lead fields in the trigger?

I can post my code if that will help (although it will be ugly - novice developer). Otherwise, I feel like there is something small I am missing!

Thanks

question from:https://stackoverflow.com/questions/65940801/setting-values-on-a-before-insert-trigger-from-apex-class-static-variables

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...