Search code examples
salesforcevisualforcecallout

how to load Image in apex.execute


Wants some information about the image loading while my process is happening.

Actually I m calling a callout on Button click , for that I have used

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var url = parent.location.href;
sforce.apex.execute("ConsumeCallout","ConsumeData",{ObjName:"Contact",ConName:"{!Contact.Id}",MobileNumber:"{!Contact.MobilePhone}",PhoneNumber:"{!Contact.Phone}"});

But the result comes in after 4-5 secoonds . So I want to show a loading image in the mean time. Can someone suggest me how to do that.


Solution

  • Before you call the sforce.apex.execute, use javascript to show an image. I would suggest to use a javascript library like jQuery. Then you can do something like this:

    {!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
    var url = parent.location.href;
    $('the id of the element you want to change').html('<img src="image_url_here" />');
    sforce.apex.execute("ConsumeCallout","ConsumeData",{ObjName:"Contact",ConName:"!Contact.Id}",MobileNumber:"{!Contact.MobilePhone}",PhoneNumber:"{!Contact.Phone}"});
    

    If you use the element that is going to be updated by sforce.apex.execute it will disappear when that gets updated. But for a full answer you would have to post some more code (especially the html)