Create the Apex Classes
Create the JWT Apex Classes
Now you create the JWT classes that handle security and create the JWT
token.
In these steps, you copy code from the jwt
GitHub repo that you downloaded and paste it into Salesforce. You can use any code or
text editor to copy and paste the code.
- On your computer, find the directory that contains the code from the jwt repo. Depending on how and where you downloaded the code, it’s in a directory called jwt or jwt-master.
- In Salesforce, from Setup, enter Apex Classes in the Quick Find box, then select Apex Classes.
- Click New.
-
To create the JWT Apex class, copy all the
code from JWT.apex to the Apex
Class tab.
- Click Save.
- Select Apex Classes and then click New.
- To create the JWTBearerFlow Apex class, copy all the code from JWTBearer.apex to the Apex Class tab and click Save.
Create the Einstein Vision Apex Classes
In this step, you create the classes that create a web request and call the API
endpoint.
You copy code from the apex-utils GitHub repo
that you downloaded locally and paste it into Salesforce. You create three classes:
- HttpFormBuilder—Called by the Vision class to build the REST API request.
- Vision—Called by the VisionController class and contains the code that builds the request and calls the API.
- VisionController—Custom controller that initiates the API call and returns the results to the Visualforce page.
- On your computer, find the directory that contains the code from the apex-utils repo. Depending on how and where you downloaded the code, it’s in a directory called apex-utils or apex-utils-master.
- In Salesforce, select Apex Classes and then click New.
- To create the HttpFormBuilder Apex class, copy all the code from HttpFormBuilder.apex to the Apex Class tab and click Save.
- Select Apex Classes and then click New.
- To create the Vision Apex class, copy all the code from Vision.apex to the Apex Class tab and click Save.
- Select Apex Classes and then click New.
-
To create the VisionController Apex class,
copy only the VisionController code from
README.md to the Apex
Class tab. The class is all the code from public class VisionController { to the closing
brace }.
-
Update the jwt.sub placeholder text of
yourname@example.com with your email
address.
- Click Save.