Invoke a Function From Apex
Now that your project and Function is deployed, you can invoke your Function from Apex.
In the command palette, run
SFDX: Create Apex class using the filename "FunctionApex". VS Code opens the new Apex class file. Edit the class file and use the following code:
This method gets the myfunction Function in the MyFunctionProject project deployed to the compute environment connected to your org. Next, the Function is invoked synchronously with a sample payload, and the response is printed.
Deploy your Apex code to your scratch org using
SFDX: Push Source to Default Scratch Org.
Now, invoke your Apex code to execute your function. Open a new file in VS Code and add the following:
With the new file still open, use the
SFDX: Execute Anonymous Apex with Editor Contents command palette command to run the file content as anonymous Apex.
The output panel should show the results: