- Appointiv allows you to add an encrypted token representing any object to your webform URL.
- When your customer books an appointment from a URL with this token included.
- If the object token represents a Contact, Lead or Person Account, then the webform will prefill their contact details so they don't need to manually enter them.
- If the object token represents any other Salesforce object, then the resulting Appointment Detail record will be related to that other object in Salesforce.
- Inserting those tokens into the URL is covered in another article.
This article focuses on generating the tokens on your records so that they can be used for that purpose later.
Summary of this process
The Appointiv managed package includes an invocable class that generates these randomized tokens onto your objects and inserts them into the Token_Id field.
First, we need to add that field to your object.
Next, we need to create a Process Builder that will run whenever a new object is created and will insert the Token_Id value into the new field.
Lastly, we need to use the Developer Console to run a batch that will create and insert the Token_Id onto all of the older objects that have already been created.
Step 1. Add the new field to your Object
Choose the object and add the field Token Id. The name has to match "Token Id" exactly - same capitalization of the letters. That TOKEN ID but capitalized as Token Id. So the second to the last letter is I as in Indigo not L as in Lima.
Make it visible to your appropriate profiles...
And visible in your appropriate page layouts...
Step 2. Create a new Process Builder
This is the most complicated step so pay attention.
Go to Setup then Process Builder and Create New Process
Click the Add Object box on the left side.
Then select your object in the dropdown on the right. In this example, we're doing the Contact Object.
Select only when a record is created to start the process.
Next, click on the Add Criteria diamond box on the left side below the step you just completed.
In the new pop-up, select the Token Id field that we created on the object in Part 1 above.
After choosing that field, a set of criteria appears on the right side.
Criteria Name should be "Generate Token Id"
Select the radio button by Conditions are met
In the row for the Conditions:
- Field = [Contact].Token_Id field
- Operator = Equals
- Type = Global Constant
- Value = $GlobalConstant.Null
Select All of the conditions are met (AND)
Under Immediate Actions, click on "Add Action"
Click the dropdown under Action Type and select "Apex"
Fill in Action Name with "Generate Token Id"
Select Generate Token Id for Sobject under Apex Class
Next, "Set Apex Variables" will appear.
Select Type = Field Reference
Select Value and enter the object ID - so in this example, it is Contact ID
Yours should look like this now:
Click "Save" to finish that step.
Ok.... still with me? Good. Let's keep going...
Click "Activate" on the top right of this page
You'll see this - click "Confirm" and we're done with Process Builder
Now, every time a new Contact is created (or whatever other object you want to swap into that process above) it will include the Token Id field.
Here's one to see how that looks:
Step 3. Run the batch to backfill the Token Id onto all of your older objects
Ok so we're wanting to add a token to Contact or Opportunity or Case or whatever. The Process Builder covers all newly created entries into Salesforce for that object but what about all the ones that are already sitting there that were created in the past? We need to run a batch that adds the Token Id to them.
So Salesforce can be a bit picky about who can run Apex Classes so before we even get to the Developer Console, you need to be able to access the Apex Class. This is done on your Profile.
Go to Setup > Users > Profiles
Find the profile you're using and click the profile name (because you're the one who is about to run the Developer Console)
Once on your Profile page -- Click on Enable Apex Class Access
Then, find that tiny little "edit" button and click it
Scroll around in the list - mine was at the bottom but yours may not be there - and find the two classes pictured below. These are specifically for Contact
Add them to your Enabled Apex Classes.
Now we can go and run the batch in the Developer Console.
Open the Developer Console
Open Execute Anonymous Window by clicking the Debug dropdown or by clicking CRTL+E
Type this into the resulting window:
GenerateSobjectTokenIdBatch obj = new GenerateSobjectTokenIdBatch('contact','');
Obvious - swap out contact with another object if you need it.
Less obvious - you can enter a parameter after the comma and between the '' For example, you could add a parameter so that this affects open opportunities only.