You need to sign in to do that
Don't have an account?
@future function needs to update Visualforce page
Hi all. I'm fairly new to saleforce development, and perhaps I've structured this all wrong. But here is what I have and what I would like to do:
I have a VisualForce page that is an extension of the Asset page. One of the fields, the serialnumber, needs to be filled in automatically based on parameters set on the parent Account along with the Product that the user selects for the asset. So, at the moment the user can select a product and I have a function that resolves the serialnumber when the product is selected.
To do this I must access code running on our web server and so I have made a WebService that accepts a request from SalesForce with the required parameters. As far as I've understood it, the function in my Apex class that calls the function of my SOAP class has to be declared as
@future(callout=true)
and will be called asynchronously.
So far so good, my function is called when an update button is pressed in the VisualForce page and the page is updated. However, since the call is asynchonous it hasn't returned yet, so now I'm thinking that in order to get the generated serialnumber (which I store in a static global variable of the Apex class) I need to have the asynchronous function somehow notify the VisualForce page when it returns... how do I do that? Or should this be done differently all toghether?
This callout does not need to be in an async method if you are calling it from your controller unless you are using transaction control semantics, i.e. Database.setSavepoint() or setting locks, i.e. SELECT .... FROM .... FOR UPDATE
I'm not sure I follow you. But if I change to callout=false I get the follwing:
Failed to invoke future method 'public static void requestNewSN(Integer, Integer, Integer)'
Debug Log:
System.CalloutException: Callout not allowed from this future method. Please enable callout by annotating the future method. eg: @Future(callout=true)
Hmm ok, but then I get this on the VisualForce page:
"You have uncommitted work pending. Please commit or rollback before calling out"