To move your Visualforce (VF) page callouts to an **asynchronous** model, you must use **`@future(callout=true)`** Apex methods, as direct callouts from synchronous controller actions (like those choice advantage linked to `apex:actionFunction`) are forbidden. The overall architecture requires four steps: 1) The VF page's `apex:actionFunction` calls a new synchronous controller method (`DocumentCallDefaultAsync`). 2) This synchronous method immediately calls a separate static **`@future` method** (in a service class) to execute the actual external web service callout and stores the result (e.g., the JSON string) in a database record (like a custom status object). 3) The VF page uses an **`apex:actionPoller`** to periodically call a second synchronous controller method (`checkCalloutStatus`). 4) This status check method reads the database record; once it confirms the JSON result is present and the status is 'COMPLETE', the poller stops and the client-side JavaScript (e.g., `Tree1()`) renders the tree using the retrieved data.
3 answers