Start tracking your progress
Trailhead Home
Trailhead Home

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.
  1. 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.
  2. In Salesforce, from Setup, enter Apex Classes in the Quick Find box, then select Apex Classes.
  3. Click New.
  4. To create the JWT Apex class, copy all the code from JWT.apex to the Apex Class tab.
    The JWT class in the Apex code editor.
  5. Click Save.
  6. Select Apex Classes and then click New.
  7. 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.
  1. 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.
  2. In Salesforce, select Apex Classes and then click New.
  3. To create the HttpFormBuilder Apex class, copy all the code from HttpFormBuilder.apex to the Apex Class tab and click Save.
  4. Select Apex Classes and then click New.
  5. To create the Vision Apex class, copy all the code from Vision.apex to the Apex Class tab and click Save.
  6. Select Apex Classes and then click New.
  7. 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 }.
    The VisionController class in the Apex code editor.
  8. Update the jwt.sub placeholder text of yourname@example.com with your email address.
    Warning

    Warning

    Use your email address that’s contained in the Salesforce org you logged in to when you created an account. Be sure to use your email address and not your Salesforce username.

    The VisionController class after you update your email address.
  9. Click Save.
retargeting