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
nwesoccernwesoccer 

Callout on object save.

If I were to need to call a external webservice on the save() of a object, how would I go about doing that?  The service needs to take in some of the new data for the object, and return a string that needs to be saved to a field inside the custom object.

 

I know that I can't use a trigger, since my callout needs to return data.

I've tried creating a Controller Extension, but don't know how to call that from the standard edit layout.

I've read that I might need to write custom VisualForce pages to replace the edit pages, but I don't need to change anything about the page other than the save call.

 

Is there a better way to do this that I don't know of?  Am I on the right track?  If so, how can my custom page easily contain the same info as the standard page does?  

 

Thanks

jhenningjhenning

You can do a callout from a trigger, you need to specify that it is asynchronous, use the @future(callout=true) annotation before the method declaration that the trigger calls. The method can update the object from the save, but it wil be "near" real time. Also, be aware that the trigger will fire if you import data via data loader ot some other tool.

 

You could also build a visualforce page and use the standardcontroller for the object and create an extension class for the save method. You will need to build the page from scratch or try using the free product from Etherios: Easy Page to convert a page layout to vf.

nnewbold-sfdcnnewbold-sfdc

You're on the right track.  You would need to override your page layout with a VisualForce page, or move your trigger logic to an asynchronous (e.g. @future) method.  Generally, it's be better to use the @future method because it won't interfere with your declarative (page layout) work.  However, if the callout absolutely has to be synchronous, you'll need to do the work of creating an edit page in VF.  At this point in time, there isn't any framework for dynamic fields, so you have to rewrite your page layouts as a VF page.