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
stollmeyerastollmeyera 

Any way to delay a Trigger or Visualforce save?

I am working with an integration between Salesforce and another third party software.  Needless to say the third party software has a bad database design that causes issues with sending over multiple API calls at once time.  Because of this I need a way to delay triggers so they fire asynchronous.  Is there anyway to do this within the Trigger?  If not, is there anyway to do this with the save method within an extension/controller?

Best Answer chosen by Admin (Salesforce Developers) 
Andy BoettcherAndy Boettcher

You're welcome!  Check it out - play around...if you need help, don't be shy to ask.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

All Answers

tes2tes2

This could be tough to time properly,  your  better off fixing your consuming service.

 


you could within the trigger schedule a run once apex job to handle the current processing in the trigger ,  you will first want to check if the job exists first so its not re-added.

 

 

Andy BoettcherAndy Boettcher

I'm not 100% clear on what you're getting at - are you saying that your integration DB is "slow" and you want to be able to "slow down" SFDC to accommodate?

 

What exactly is slow?  There are a couple of options that you could pursue, but knowing the exact cause / effect of the slowdown will help.

 

-Andy

stollmeyerastollmeyera

The other database is just as quick as Salesforce.  However, when two jobs are submitted at the same time to it, it assigns the same ID to both objects, which throws an error for duplicate values.  I need a way to delay the outboud calls from SF by at least one second, so one job can be created with a unique ID, and then a new job can come in without interupting.  Does that make sense?

Andy BoettcherAndy Boettcher

You could spawn off some Future Apex (@isFuture) out of the Trigger - that may be an option for you, but there is a limit of how many @isFuture calls you can have queued up at once.  How many records are we talking about here that will be firing off at the same time?

 

-Andy

stollmeyerastollmeyera

Ten would be the max, with the norm being around two to three records.  

Andy BoettcherAndy Boettcher

Yeah - that could get a little hinky, as the SF Governor Limit is 10 Future Apex calls per Apex invocation.

 

If that's a limit you're willing to accept, the Future Apex is pretty slick - it'll run "when SF resources are available"...which is typically within 0.5-1 seconds of the original code execution.

stollmeyerastollmeyera

I think I was being a little excessive by saying ten, meaning I am more than willing to cooperate with that limit.  Where can I find resources about future APEX?

 

btw, thanks for all of the help!!

Andy BoettcherAndy Boettcher

You're welcome!  Check it out - play around...if you need help, don't be shy to ask.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm

This was selected as the best answer