How to poll Salesforce Record until future callout is completed and record has changed

Sam BeckerSam Becker ✭✭
edited July 23, 2019 in Questions
I'm most likely not understanding this problem correctly, so I may be barking up the wrong tree, but I'm going to do my best to explain the problem.


Short Version
How can I poll a Salesforce record until the asynchronous method has completed? I believe I have to use a asynchronous method because I'm calling out to a web service from a trigger and I can only do that with the @future method.  

Long Version
I have a Skuid page that is using Stripe Checkout API. I'm using the server-side method by using a custom object called Transaction__c.  When the transaction record status equals 'Process Payment' it triggers the Apex Class to do a HTTP call to Stripe to start processing the payment. 

I have to use a "@future method" to perform the callout since salesforce won't let me perform a callout from a trigger without making it asynchronous. How can I make the Skuid page wait and keep checking the Salesforce record until it has gone to the correct Status?

I hope this makes sense. I'm in very unfamiliar territory. 

Appreciate any help you can give!

Thank you  

Comments

  • edited July 23, 2019
    Hey Sam,

    There are 2 community post about the pieces you'll want here. It'll tell you how to:
    1. Query the data via JS - https://community.skuid.com/skuid/topics/polling-status-from-salesforce-remote-action-and-update-the-components-on-skuid-page
    2. Set a time interval with JS - https://community.skuid.com/skuid/topics/real-time-dashboards
    I believe this is how this could look:
    1. Your Salesforce record reaches a Status of "Done"
    2. Your Skuid page contains a Transaction model, with condition of Status = "Done" and Id = url parameter (or however you'd like to pass an id). The page continually querys for data until your Transaction model has a single row
    3. Your Skuid page triggers an action based on that row being updated or created or having data, finishing the process.
    Best of luck! Transactions are a tricky business. Feel free to post progress/road blocks as they come. :)

    And if I mis-represented your issue or need, feel free to clarify further.

    Best,
    Aaron

  • Sam BeckerSam Becker ✭✭
    edited July 6, 2019
    Hi Aaron,

    Thanks, I ended up using setTimeout() and polled for changes every 5 seconds until it either completed or updated to an error. 

    If anyone is looking to connect Skuid to Stripe Checkout, this is useful to make sure it goes to the payment collection step.

    Thanks!

    Sam
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!