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
noukasmaximusnoukasmaximus 

How do I display an hourglass or 'please wait' message while my Apex class is processing?

I have a custom button which I've placed on a standard layout.

It has javacript in it that calls an Apex class.

In the javascript I am disabling the button onclick.

But the Apex class can take up to 50 seconds to process, and during that time, I'd like to display an hourglass or 'please wait' message.  (The class is creating a bug in our JIRA system used by our RND team and using some complex formulas to set component, fix version, and assignee, so it takes some times to process.)

I believe I need to place this code in the Apex class.  All I can find is how to do it in a Visual Force page using the actionStatus function, but that doesn't apply here.

How do I do this?
kcpluspluskcplusplus
Are you executing this synchronously and waiting for a response, or do you put the request out there and go back later to check on it? I'm assuming you are waiting on the request to complete which is the challenge. I think one of the ways I would approach it would be getting away from waiting on the processing. If you make a custom setting with a row for the request processing, with even just a checkbox, that is checked while you are waiting for the request and your callout method unchecks it when it is finished processing You can then use jQuery to kick off a loading/waiting animation, and at the sametime use javascript remoting to call back to the controller and check to see if that box is still checked, and once it isn't you can end the animation. 

This also leaves you room to expand, as I assume you want to do more than that. You can have a message text field on that custom setting, where you can store errors, status codes, messages etc. to display on the page and return it via remoting, you can rerender the page or append return data back via javascript remoting. 

That's my take based on what I assume to be the challenge you are facing, hope it helps. 

--KC
noukasmaximusnoukasmaximus
Yeah, that sounds about right.  We want the animation to show until the processing is complete.

I don't want to put the code in the custom button as there are already validation rules that fire off the button and display messages, so it would be strange to have one of those rules fire and the 'please wait' fire.  That is what I experienced when I tested code in the button for this purpose.

So it seems the best place for the code is the APEX, I'm just stumped on how to make it work.

The APEX currently refreshes the salesforce browser when it is complete, if that helps.