Customers who have streamlined development processes typically use multiple non-production environments (one for each probably – development, QA, integration, data migration, SIT and UAT). And it is a general practice that development teams develop in development sandboxes or scratch orgs first, check in their code to a repository and add instructions to deployment trackers – for deployment teams to perform the deployment steps. These can include any manual steps – related to enabling features, adding data etc. Typically anything that cannot be done using the metadata API.
Context
It is NOT a good practice to expect the deployment teams to repeat these steps manually in every single Org. Reasons can be many. To quote a few – prone to human errors while executing manual steps, time consuming, too much detailed documentation will be required and some customers do NOT prefer a partner or consultant to have administrator access to environments other than development.
Guidelines while deploying Scheduler
While deploying Salesforce scheduler between environments – consider categorizing your components into the following areas
Pre deployment activities
Include steps that need to be performed before migrating the codebase using the Metadata API. Ensure the system administrator has the Scheduler Permission Set license assigned first, then consider any manual steps of the features that are NOT yet supported by the MetaData API (or) any dependent packages that are required for your implementation.
Deploy code using Metadata API
Step 1 – Include feature settings that are related to “Salesforce Scheduler Settings” which need to be either Enabled or Disabled, should be covered first. Refer the Industries settings here – https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_industriessettings.htm Note: The settings mentioned in Italic and which do NOT have a Metadata Reference are currently NOT supported by Metadata API – will be addressed in future releases (Safe harbor). If you are using these features – activate them manually as part of your pre-deployment steps
Salesforce Scheduler Settings
Metadata Reference
Event Management
enableEventManagementOrgPref
Block Resource Availability
enableBlockResourceAvailabilityOrgPref
Multi Attendee Event
enableCreateMultiAttendeeEventOrgPref
Appointment Distribution
appointmentDistributionOrgPref
Aggregate Resource Use
captureResourceUtilizationOrgPref
Publish Appointments as Platform Events
enableEventWriteOrgPref
Multi Resource Scheduling
enableMultiResourceOrgPref
Concurrent Scheduling
enableOverbookingOrgPref
Operating Hours for Service Territory Members for Work Type Groups
enableTopicTimeSlot
Salesforce Scheduler for Health Cloud
Resource Appointment Sharing
enableShareSaWithArOrgPref
Multiple Topics For Shifts
enableMultipleTopicsForShiftsOrgPref
Schedule Appointments Using Engagement Channels
enableAppFrmAnywhereOrgPref
Main Service Resource
enableAnyResourceTypeOrgPref
Drop In Appointments
enableDropInAppointmentsOrgPref
Drop In Skill and Skill Level Matching
enableDropInSkillMatchingOrgPref
Resource Availability Sharing Using Actionable List
enableActionableListOrgPref
Step 2 – Include any customizations done to the product offering should be added to the Codebase (repository). Consider evaluating your customizations around
Sharing settings – OWD and Sharing rules (include groups or roles – if sharing rules are around those)
Custom fields on Scheduler objects
New Picklist values on Scheduler objects
Custom buttons, actions and links
Changes to page layouts
Flows
Custom components that are added to the flows
Custom classes and triggers
Validation Rules
Experience Cloud
Lightning Out for Guest user on a customer website (endpoint URLs will be different)
Post deployment activities
Include steps that need to be performed for the scheduler solution to work. This will mostly include migrating your data and setting up the users and adding scheduler PSLs. Consider leveraging data loader or an ETL tool for data migrations and ensure data integrity (order of loads) and references are maintained post migration between the records in multiple objects.
Plan a load sequence order. A sample load sequence would look like this. Evaluate your customizations to make sure this order applies to your implementation as well
Salesforce Foundation Objects
SObjectName
Load Sequence
Relationships to Establish
Profile
1
UserRole
1
PermissionSet
1
PermissionSetGroup
2
PermissionSet
User
2
Profile, UserRole
Product
1
PermissionSetAssignment
3
PermissionSet Or PermissionSetGroup, User
Salesforce Scheduler CORE Objects
SObjectName
Load Sequence
Relationships to Establish
Skill
1
Can also be migrated as Metadata (But recommendation is to do it as data migration)
Skill Requirement
2
Skill
Holiday
1
Operating Hours
1
Operating Hours Holiday
2
Work Type Group
1
Service Territory
2
Operating Hours
Work Type
2
Operating Hours
Work Type Group Member
3
Work Type Group, Work Type
Service Territory Work Type
3
Service Territory, Work Type
Service Resource
3
User
If using Assets as Service Resource, the order should be after Assets
Service Resource Skill
4
Service Resource, Skill
Time Slot
4
Operating Hours, Work Type Group
Service Territory Member
4
Operating Hours, Service Territory, Service Resource
Appointment Assignment Policy
1
Appointment Scheduling Policy
2
Appointment Assignment Policy
Appointment Topic Time Slot
5
Work Type Group, Work Type, Time Slot
Salesforce CORE Transactional Objects
SObjectName
Load Sequence
Relationships to Establish
Account
3
User
Owner of the Account Parent Account Id should be an additional Step if you manage hierarchy of Accounts And probably any custom look-ups if you have included Custom Fields
Contact
4
Account, User
Opportunity
5
Account, Contact, User
Lead
6
Account, Contact, Opportunity, User
When migrating Converted Leads
Asset
5
Product, Account, Contact
Salesforce Scheduler Transactional Objects
SObjectName
Load Sequence
Relationships to Establish
Resource Absence
4
Service Resource
Resource Preference
6
Service Resource, Related (Account, Lead OR Opportunity)
Shift
6
Service Resource, Work Type, Appointment Topic TimeSlot
Service Appointment
7
Service Territory, WorkType, Account, Parent Record (Either Account, Lead OR Opportunity)
Assigned Resource
8
Service Resource, Service Appointment
Event
9
Service Appointment, WhatId (Asset, Account OR Opportunity), Owner (Users), WhoID (Lead OR Contact)
Appointment Invitation
8
Work Type OR Work Type Group, Service Territory
Appointment Invitee
9
Appointment Invitation, Service Resource
Note – even the scheduling policies and assignment policies have objects (AppointmentSchedulingPolicy and AppointmentAssignmentPolicy) – they can be migrated.
Few best practices to keep in mind
Consider deactivating picklist values that come OOTB if there is NO plan to use them in your solution
If you have hardcoded any IDs in your flows (for defaulting any records like Work Type Group, service territory etc.) – replace with Production IDs wherever appropriate
Turn OFF Rules (Validation, Escalation, Assignment, Workflows, Process builders, Flows, Sharing Rules) to avoid getting errors while performing data loads
Re-calculate Sharing Rules post migration of all data
And Finally explore sfdx-cli data tree import option to load in fewer amount to steps
Make sure the number of records getting loaded are fewer than 200 in a single step (thats the limitation to look for when using the data tree import option with sfdx-cli)
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Sunilhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngSunil2022-08-22 00:26:392023-08-31 23:23:54From Sunil Nandipati: Deploying Salesforce Scheduler from Sandbox to Production Environments
In recurring shift we have added 2 new fields which will allow users to upload daily weekly and monthly shift. A sample request payload is given below for the steps 7 in the above doc.
/services/data/<version number>/jobs/ingest/<job Id>/batchesUse the contentUrl from the POST method and append a forward slash (/) at its beginning.Example:/services/data/v54.0/jobs/ingest/7505j000005JqZrAAK/batches
HTTP Method
PUT
Headers
Content-Type: text/csvAccept: application/json
Request Body
The contents of the CSV file. Example:ShiftId,WorkTypeId,WorkTypeGroupId,AreAllTopicsSupported0a0x000000003Q6AAI,,,TRUE0a0x000000005kuAAA,,,TRUE0a0x000000003QBAAY,,0VSx00000002UgzGAE,0a0x000000003QBAAY,,0VSx00000002Uh4GAE,
C. Rest same from steps number 8 from above reference doc
Bulk shift upload for multiple channels and multiple topic
Upload Channel to Shift
Create the Shift and get the Shift Id for which the user want to add multple chanel
Get all the channel Id which user wants want to add to shift
/services/data/<version number>/jobs/ingest/<job Id>/batchesUse the contentUrl from the POST method and append a forward slash (/) at its beginning.Example:/services/data/v54.0/jobs/ingest/7505j000005JqZrAAK/batches
HTTP Method
PUT
Headers
Content-Type: text/csvAccept: application/json
Request Body
The contents of the CSV file. Example:ShiftId,EngagementChannelTypeId,AreAllEngmtChnlSupported0a0x000000005vZAAQ,0eFx00000000006EAA,0a0x000000005vaAAA,0eFx00000000006EAA,0a0x000000005vaAAA,0eFx0000000000BEAQ,0a0x000000005vbAAA,,TRUE0a0x000000005vcAAA,,TRUE
Rest same from steps number 8 from above reference doc
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Akshayhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngAkshay2022-08-09 20:34:552022-08-09 20:38:07By Mrityunjoy Chowdhury: Bulk Shift upload with recurring Shift and Add multiple topic and channel
With Salesforce Scheduler, it’s easy to embed appointment scheduling into standard Salesforce workflows, such as leads and referrals, opportunities, accounts (and person accounts in the B2C Model) and ALSO cases (as of Winter ’23 release).
But NOT for Contacts (with B2B model).
In this blog, we will look at options to schedule a contact.
Note: Field Service Lightning Product extends this to additional objects – Work Order, Work Order Line Item and Asset.
Understand Scheduler OOTB Behavior
Before we start looking at an option how we can customize the experience for scheduling around a contact, lets try to understand the core objects we have from Salesforce Scheduler that capture a booked appointment using the OOTB behavior and how we can reuse the existing OOTB available references.
Service Appointment
Assigned Resources
Event
We will keep our focus understanding the relationships and the references
Object
Field
Data Type
Usage
Service Appointment
ParentRecord
Lookup(Account, Opportunity, Lead, Case)
Using Salesforce Scheduler we can create a Service Appointment only around Account, Opportunity, Lead or Case.
Service Appointment
Account
Lookup(Account)
Defaults to the Customer account’s for inbound, Left blank for a Lead, Case and related account if booking around an opportunity.
Service Appointment
Contact
Lookup(Contact)
Defaults to the user’s contact record when requesting from a customer community via an inbound authenticated user booking scenario. Left blank otherwise.
We will use this standard field to Stamp the Contact ID – during Service Appointment creation when doing an Outbound Scheduling from Internal Salesforce in this blog.
Assigned Resource
ServiceAppointment
Master-Detail(Service Appointment)
Service Appointment object does NOT hold the service resource information, it is primarly stored in the Assigned Resource object. This is the reference to Service Appointment.
Assigned Resource
ServiceResource
Lookup(Service Resource)
Service Resource reference (can be either a user or an asset)
Service Resource
RelatedRecord
Lookup(User)
Service resource object reference to a User – which can be either a Platform Starter / Partner Community / Customer Community Plus / Salesforce license type user
Event
WhoId
Lookup(Contact,Lead)
Events are like your calendar events. The person who will attend this event is captured here.
Event
WhatId (Related To)
Except Lead and Contact, Other objects
And this event is related to what in Salesforce
Event
ServiceAppointment
Lookup(Service Appointment)
When Event Management is turned ON on the Scheduler settings, every time a service appointment is created, it creates a related Event – this is to hold that references
Event
Owner (Assigned To)
Lookup(User,Calendar)
Represents the owner of the record (internal user or an external calendar)
Customization Guidance to schedule a Contact
Having looked at the above objects and references, it is pretty much clear that we CAN reuse the existing Contact lookup on Service Appointment. When using Events, we WILL have to make sure the related EVENT gets created with this Contact reference as well.
To achieve this we need to modify the existing template slightly. Try these steps outlined below
Start with a cloned flow from the template (In this example we have cloned the “Outbound New Appointment” template to create a flow called “Outbound New Appointment for Contact”)
Since we plan to launch this from a Contact record, the recordId will be the Contact.Id that will be passed to the Flow. So we need to make sure we capture the Contact.AccountId as well. Create a variable to capture the AccountId. Service Appointment ParentID field can only accept records from Lead, Account and Opportunity, so lets make sure we pass the account information from the Contact
Assignment – Set Initial Values :: make sure the recordId is assigned to ServiceAppointment.ContactId
Screen – Attendees Screen :: ensure the Contact ID assignment is NOT empty – change it to {!ServiceAppointment.ContactId}
Screen – Review Screen :: ensure the Contact ID and Parent Record ID assignments are correct
Finally make sure the Event Management is turned ON
Save the Flow and Activate it
Add a Lightning Action to Launch this flow
Add this Lighting Action to your Contact Page Layout
Finally, test it for yourself. Here is a demo of the same configuration tested on a developer trial org
Considerations when using with Field Service
As mentioned in the preface – Scheduling an appointment gets extended to additional Objects which are NOT supported by Salesforce Scheduler when using Salesforce Field Service product (Earlier Field Service Lightning).
Especially with both the products (Scheduler and Field Service) in the same org, ensure you take extra care around Event Management using a custom route rather than turning ON the Event Management option as mentioned above.
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Sunilhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngSunil2022-08-04 20:29:162022-11-10 00:14:17From Sunil Nandipati: Scheduling a Contact
The Summer ’22 release of Salesforce Scheduler introduces an amazing new feature called Share Service Resource Availability by Using an Invitation URL. This feature allows a service resource to easily generate a URL that their customers and prospects can use to schedule appointments with them.
Above: Help and Training Article describing the new feature
At the heart of this feature is a new object called Appointment Invitation. When a service resource generates their URL, a record is created in this object.
Like most objects in Salesforce, you can add custom fields to this object.
Why would you do this?
This allows the service resource to personalize the invitation, meaning you could do something as simple as displaying information to the customer while they are scheduling an appointment from this invitation. Additionally, you can perform more complex processes such as writing the information to the service appointment that is created.
Example Configuration – Basic
Let’s look at a simple example.
We are going to allow the Service Resource to enter a friendly message that they want the customer to see when the run the scheduling flow.
Add a new field to the Appointment Invitation object. In my example, I added a text field called additional info.
Grant field level security to the service resources that will use this and the community/guest community profiles that will be viewing this information.
Modify the Generate Appointment Invitation flow to prompt the service resource for the additional information and then save that to the Appointment Invitation object, as depicted in the screens below.
Seeing the Results
Here we see our Service Resource entering a message while running the flow to create the invitation URL.
Displaying the additional information message to the Service Resource on the confirmation screen.
Here we see the customer running the flow. They received an email with the URL (not depicted), clicked on it and landed here, with the additional information message displayed to the user.
Example Configuration – just a smidge more configured than the basic example above
What if we wanted our Service Resource to select a related Marketing Campaign and then send an invite. All service appointments created from that invite should be linked to that campaign.
Data Model, Security and Sharing Changes
Add a lookup relationship field on Appointment Invitation to the Campaign object
Add a lookup relationship field on Service Appointment to the Campaign object
Grant field level security on these fields to community/guest community users
Create sharing rule on Campaign object to share campaign data with community/guest community users
Data model changes depicted below
Flow Changes
Generate Invitation Flow
Add a Campaign picklist and related Record Choice Set
Save the selected Campaign to the Appointment Invitation Object
Generation Invitation changes depicted below
Book Appointment from Invitation Flow
Add an Update Record Step after the Save Appointment step to save the Campaign Id to the Service Appointment
For guest users, make sure you run this flow in the System Context without Sharing – Access All Data
Book Appointment from Invitation changes depicted below
Running the Flow
Service Resource
Service Resource running the Generate Appointment Invite flow and selecting a Campaign
Customer/Prospect
Their experience has no change. But when the schedule an appointment, the service appointment stores the campaign id.
Service Resource
Service Resource reviewing Service Appointment. Note Campaign is associated with the service appointment.
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Sunilhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngSunil2022-07-15 05:37:442022-07-15 05:39:09From Chris Albanese: Enhancing the Share Availability Feature with Appointment Invitation configurations
What if your business offers appointment booking for multiple services with a single appointment. For example, you offer auto services and allow customers to select from a menu of options, such as oil change, tire rotation, brake service and others. The customer may select 1 service or multiple services, and depending on the services selected, the duration of the appointment should be long enough enough to accommodate the selected services.
Above: Example of a flow screen prompting a user to select 1 or more auto services
What if you also had many store locations, and each store might offer a different menu of options. For example, the Wakefield store offers all services but the Reading store does not offer brake services.
With Salesforce Scheduler, you can accommodate this out of the box by creating many Work Type Groups to represent the combinations of services.
Consider the following table of Work Type Groups with its limitless number of combinations
Services
Duration
Oil Change
30
Brakes
60
Tire Rotation
30
Wiper Service
15
Oil Change and Brakes
90
Brakes and Tire Rotation
90
Tire Rotation and Wiper Service
45
Oil Change and Wiper Service
45
Brakes and Wiper Blades
75
…and many more combinations
But, this is probably not the most practical way to offer a menu of services. This document describes an alternative approach which includes 2 custom fields and a small bit of Apex code. Check out the details below.
Solution Overview
This solution allows you to run the Scheduler flows with a few minor configurations and an Apex @invocableMethod, allowing the user to select the desired services and perform precision scheduling without all of the permutations of work type groups.
The solution consists of custom fields on the Work Type object and Service Appointment object, an Apex Class, Work Type Group and Work Type data organized in a specific way and a configured flow. The flow makes use of the FilterByResourceIds parameter to ensure only those resources who have the skills needed are returned.
Objects
Work Type Groups
Create Work Type Groups only to reflect the duration of the services required. For example, Work Type Groups called 30 Minutes, 45 Minutes, 60 Minutes, 90 Minutes, etc. These are tied to Work Types with the respective durations.
Skills
Create Skills for each service required. For example, create an Oil Change Skill, a Brake Service Skill, a Tire Rotation Skill and so on.
Service Resources and Service Territories
Create Service Territories to represent the store locations and create 1 resource for each service lane or bay present in the store. Assign skills to service resources to define the services offered. For example, if the store offers oil changes and brake service, but no other services, then assign only those 2 skills to the service resources associated with the store.
Service Appointment
Add a custom text (255) field called Selected Services. This will store the id’s of the work types that were selected by the user. This can be used by a rescheduling flow (not described in this document).
Work Types
Add a custom picklist field called Service Type, with values of Service and Scheduling.
Create 2 types of Work Types:
Service Work Types
These are work types that represent each service, the skill required and the expected duration. For example,
WT Name = Oil Change, Skill Required = Oil Change, Duration = 30 Minutes, Service Type = Service
WT Name = Brakes, Skill Required = Brake Service, Duration = 60 Minutes, Service Type = Service
These work types are not assigned to any work types groups or service territory work types.
Scheduling Work Types
These are work types that represent a total duration, have no skills required and the expected duration. For example,
WT Name = 30 Minute Service, Duration = 30 Minutes, Service Type = Scheduling
WT Name = 60 Minute Service, Duration = 60 Minutes, Service Type = Scheduling
These work types are assigned to Work Type Groups (see screenshot below) and they are assigned to service territory work types.
Pic above: Work types for Service (with Skills required) and work types for Scheduling (no Skills required)
Pic Above: Work Type Groups just for Scheduling
Apex Class
An Apex class is used to determine the scheduling Work Type Group which is just large enough to cover the list of input Services. It accepts a list of Work Type ids and returns a Work Type Group id and a text field containing a comma separated list of Service Resource ids who have the skills required for the input Services.
The code for the apex class and a test class is contained in the package file at the end of this document.
Flow
Modify the Inbound New Guest Appointment flow to prompt for the services required (service work types), call the apex class and then present the list of time slots available.
Pic Above: Flow with new steps added to prompt for services and call the apex class.
Pic Above: New Screen which prompts for services. Select services is a picklist tied to a record choice set which selects only Work Types where Service Type = Service.
Call to Apex which returns the applicable work type group id with the duration large enough to accommodate the selected services. Also set the FilterByResourceIds field, which will be used in the select location and select time slots screens.
Video of it in action
Check out the short video below.
Package
Try it yourself in your own sandbox. The custom fields, Apex Class, Test Classes and an example of a configured Inbound New Guest Appointment flow are included in this repo.
Since FilterbyResourceIds is limited to 50 service resource ids, you should ensure that you pass in a service territory id to the Apex Method so as not to exceed this limit.
Modify line 24 of the Apex code to select the specific service territory selected by the user.
listST = [select id from serviceterritory where isactive = true];
Lines 50-56 contain code to limit the total number of service resource ids to a maximum of 50. If the limit of 50 changes in a future release, you should change this code to reflect the new limit.
Rescheduling Flow
A rescheduling flow is not included here. If rescheduling is part of your use case, use the Service Appointment custom field created in this package to retrieve the services selected by the user when the appointment was scheduled. Add the custom screen and call to the Apex method to retrieve the corresponding scheduling Work Type Group, similar to how the flow in the package has been configured.
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Sunilhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngSunil2022-05-24 21:34:002022-05-25 02:24:39From Chris Albanese and Chris Hartt – Scheduling 1 appointment with multiple work types
The use case is fairly straightforward, as a customer of a bank, I want to schedule an online meeting with my advisor and discuss my accounts. The technology the bank wants to use is MS Teams.
The technology usage behind this particular demo is to simply create a meeting in MS Teams via an API which returns a URL that parties can click on to launch Teams( either browser or desktop ) and have a meeting. There is a lot more that can be done, but this integration is to show the possibilities with the connection
Technology Utilized
Listened below are the main technologies and configurations used in the demo preparation.
Main SaaS Tech Stacks
Salesforce Scheduler
MS Teams Online Meeting
MS Graph Rest API’s
Demo Setup Technology
MS Azure Development Account – Needed to setup a MS Teams Environment
Salesforce Org
Postman – To easily test the setup and API’s
<optional>MS Visual Studio – Used to write and deploy code
Apex Classes
Invocable Methods setup to make available in Flows
Test Classes
Auth Provider Setup in Salesforce
Named Credentials
Salesforce Flows – To provide the screen navigation, call Azure to get the meeting, and update the appropriate records.
Demo Flow High Level
This section describes the general flow of the demo from start to finish when showing to the customer. This is a specific flow for the customer this demo was prepared for. You can tailor or make your own flow(s) for your customer.
Customer goes to the portal to schedule a meeting, leveraging the Salesforce Scheduler.
This demo has an authenticated flow, there is a person account associated with the demo.
Enter the required information from the screen
Click by previously scheduled service appointments or search for a banker.
Click Next
Click on a Work Type Group → Select the type => Click Next
Select Video Call
Enter a address → San Francisco → Select a branch
Choose a date in scheduler
The call to MS Teams is done at this point and a URL is returned to the “Additional Information” Section. Note, this could be put anywhere but for the purpose of the meeting we chose here.
Click on next and a new Service Appointment is created with the Meeting URL in a custom field that can be accessed to launch a teams meeting.
The integration behind the scene created a MS Team meeting valid link that can be clicked on to start a team meeting. This utilized the MS Graph API, OAuth/Open ID authentication/authorization, and Apex Callout to create and return the meeting.
Demo Details
This section will describe the setup needed to execute the demo. What is described is the particular flow used to validate and test the integration. The entire section for Postman is completely optional, but it is suggested to do this to validate and debug. In our case, it was invaluable in determining the exact headers to place into the API. In the initial development, Postman was first used outside of Salesforce to ensure the API format was correct and the authentication/auth was setup correctly in Azure.
Microsoft Azure Setup
The first piece that is needed is a Microsoft Developer Account to be able to setup a new Azure environment. We won’t go into the details here on all of the steps, the directions are straightforward. When it gets to the point of asking what features you want to add, make sure you add in the MS Teams option that will be available.
Specific API format for the Online Meeting API’s. Note: We are using Delegated API but the Application API could be used as well with more customer setup for permissions.
Setup Salesforce/Postman Application in Azure
The first thing needed is to setup a new custom application in Azure AD that will be used to generate the authentication and authorization needs for Salesforce connections and optionally Postman Connections. You can create two apps, or in my case, I just created one to handle both.
App Setup
Create a new App from the App Registrations link along the left hand side and click on New Registration
Fill out the form and leave the defaults as they are. We will fill in multiple redirect URI in a later step.
API Permissions Setup
Click on the API Permissions from the left-hand side of the application you have created. (Click the application from the previous step)
Create the API Permissions needed for MS Teams Online Meetings. In addition, add a few extra permissions to ensure the token can be refreshed. The permissions can be found in the Graph API docs. We added a generic one for read and Mail.Read for testing purposes, they are not fully required. Once the permissions are added click on the “Grant Admin Context for … ”. The status will be red until this is done.
In this section we will create the client key and secret which will be used in the Postman and Salesforce integrations to authenticate into Azure and Teams.
Click on the Certificates & Secrets Menu item on the left hand side.
Click on New client secret
Enter a new description and the expiration of the secret. You can choose whatever you like or keep the default.
Copy the Secret Key Value for use later when setting up the authentication sections of Salesforce and Postman
The Secret ID is an Azure ID, it will not be used anywhere. The ID that is used is the Application(client) ID from the application you created. We will show this in detail later.
Authentication Setup
This section covers the Authentication Setup that will be needed. This section will be done when you are ready to setup either Salesforce and/or Postman to Authenticate and setup the redirect URI authorization from the client request. Additionally, the Endpoints needed for authorization and token endpoints locations are covered in this section. If this is the first time through the setup, you most likely won’t have the redirect URI’s available but for document cleanliness, we are keeping the Azure setup all in one section.
Click on the Authentication menu item on the left hand side.
Click on Add a Platform link to add a platform.
Click on Web Platform
Add the redirect URI from your application( the location of these URI’s from Salesforce and Postman will be shown later ).
The image below is an example where the Postman and Salesforce API’s have been added. In this case, 1 Postman and 2 Salesforce Demo Environments are part of this application.
The Endpoints needed for the configuration of the applications can be found on the overview section of the application you have configured. Click on the Endpoints link from the overview and the first two endpoints are used when configuring the authentication.
Salesforce Setup
This section describes the Salesforce Setup needed to access MS Teams. It is strongly advised to setup Postman first to validate and test the API as well as get familiar with the API before jumping into Apex coding setup. This section will consist of Authentication setup, the Named Credential, and the Apex code needed to create a Teams meeting and retrieve a URL. Additionally, this will provide the callback referenced in the Azure section which will be needed to complete the Authentication section in Azure.
Auth. Provider Setup
The first step is to create the Authorization Provider configuration to connect to Azure. You will need the Secret Key(Value) from the Certificate setup in Azure as well as the application id.
Enter Salesforce Setup→Auth.Providers→New
Choose Open ID Connect from the Provider Type drop-down.
Name the Auth Provider.
URL Suffix → Can make the same as the name.
Consumer Key → This is the Application ID from Microsoft Azure. This is found in the Overview Section of your App in MS Azure.
Consumer Secret → This is the Secret Value from the Certificate setup done previously in MS Azure.
Authorization Endpoint URL – This is the OAuth 2.0 Endpoint given in the Azure Setup Above
Token Endpoint URL – This is the OAuth 2.0 token endpoint given in the Azure Setup above.
Default Scopes<optional> – We set the scopes in the named credentials but they could also be set here. In this example we just set the online meeting read/write. When setting the scope, the values are delimited with a space.
Make sure all 3 options are checked for Send Access token in Header, Send client credentials in header, and include customer secret in API response.
Use the defaults for the remainder.
Save
Click on the newly defined Auth Provider to open it up
Copy the Callback URL that is shown in the Salesforce Configuration. If you have Experience Cloud setup and you are using those domains, then add those callback URLs as well to the Azure configuration.
Take the callback URL you copied above and back in the MS Azure AD setup for your application, add this to the redirect section. Do this by clicking on Add URI.
Named Credential
Creating a named credential will perform the authentication to MS Azure and do the Oath validation. Here is where the MS Authenticator is used( I set mine to auto approve ) to validate the OAuth connection. It will prompt you to login to your instance of Azure. The login will be the MS Azure login/id that was created during the setup of the developer instance.
A couple of notes for this setup. The example shown only accesses the one API for creating an online meeting in MS Teams. This could be a general named credential to just the Graph root level and you can append the rest of the API in the code. Alternatively, you can create a named credential for each of the API’s or perhaps the most commonly used ones.
In Setup→Named Credentials click on New
Enter the label and the URL of the API Endpoint you wish to access. In this case, the full API is used for the onLineMeeting for Delegated access. The application access has a different signature.
Identify Type will be Named Principal.
Auth Protocol will be be OAuth 2.0
Select the Auth Provider created in the previous step.
Scope: very important! The scope here will match the scope you created in MS Azure for the application. It is space delimited.
Click Save and this will trigger the actual connection to Azure and validate the Authentication
When you Save, the Oauth flow will initiate.
If successful, you will see Authenticated in the Authentication Status in Salesforce. If it fails, you will get a failure screen from MS Azure.
Common Issue: Used the wrong secret key or id. Double check in the Auth. Provider those are correct.
URL Endpoint is in valid: Check your URL Endpoint. (one reason to use Postman first)
Salesforce Application Code
This section will review the Apex application code needed to make the Rest API call to set up a teams meeting and retrieve the meeting URL from the Teams Server. The code is not production quality but instead is a sample to prove the concepts. The current iteration does not accommodate error handling in a meaningful way nor does it do much more than create a meeting. The goal of this good is to demonstrate the basic connection for customers and proof of concept the meeting invite is ready. The sample code will be in two parts, the first part is a test class that can be used to validate the connection and result. Once that is working, then the 2nd class uses @InvocableMethod so that it can be used in flows. Obviously this can be tailored however desired.
This section does not instruct how to set up command line tools, deploy the source, or other development tasks. It is assumed the reader understands how to deploy, run the developer tools/debugger in Salesforce.
Test Apex Class – Simple Class to Create the Meeting utilizing Named Credentials
public class TestAzure {
/* Test Method for Unit Testing Connection */
public static String getMeetingUrl()
{
HttpRequest req = new HttpRequest();
Http http = new Http();
//Setup the Endpoint and append the name of the file
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
(parser.getText() == ‘joinWebUrl’)) {
parser.nextToken();
webLink = parser.getText();
System.debug(‘joinWebUrl= ‘ + webLink);
}
}
return webLink;
}
}
Common Issues/Errors
MS Teams will return a 201 in the HTTP Response. This is a success. It is documented in the API
HTTP Error 500 – Internal Server Error
Notice the headers that are set. The MS Graph documentation does not state it explicitly, but in our testing we found that the 2 accept lines need to be in the header when sending the request. You need to add the gzip, etc and the “*/*” accept lines.
401 – The 401 unauthorized generally means the scope is incorrect in the Named Credential or both in the Named Credential or the Azure setup. Make sure the permissions are correct and the scope is space delimited.
403 – Forbidden – This occurs when the secret keys are incorrect. You should have fixed this when you saved the name credential so it shouldn’t show up.
Note: When using the Apex Debugger – Look for the debug line to joinWebURL populated with a long string for the meeting. It will start with something like this: 12:40:52:477 USER_DEBUG [37]|DEBUG|joinWebUrl= https://teams.microsoft.com/l/meetup-join/19%3am
Salesforce InvocableMethod Class Utilizing the Apex Code and Callout
This is the actual code used in the demonstration. This code is accessible in the Flow Builder inside of Salesforce as an Apex Action.
global class GetTeamsMeetingURL {
@InvocableMethod(label=’Get MS Teams Meeting URL’ description=’Returns a meeting URL For MS Teams’)
global static List<String> makeApiCallout(List<List<String>> inputTeamsParms)
{
// Setup the HTTP Initial Request
HttpRequest req = new HttpRequest();
Http http = new Http();
//Setup the Headers, format the body, and call the MS Graph API
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
(parser.getText() == ‘joinWebUrl’)) {
parser.nextToken();
webLink = parser.getText();
System.debug(‘joinWebUrl= ‘ + webLink);
}
}
// Apex Actions Return. The method signature for invocable method requires a List of Strings to be returned.
return new List<String>{webLink};
}
}
Salesforce User Experience Setup
This section is optional but describes how the above code can be accessed in the low-code building tools inside of Salesforce.
This section in a flow shows how this action is called to retrieve a URL for the MS Team Meeting and then assigns it to a Record in Salesforce. A larger flow will then do further processing as part of a full scheduling flow. The takeaway is that the Apex Code above is an option to drag and drop into the low code builder and use it when running a flow. It could also be embedded within a Lightning Web Component(LWC) and used in other places. Lastly, it can always be accessed from another Apex Class to get the required information.
Postman Setup
This section describes how to setup Postman to access MS Graph API and test the API integration outside of Salesforce in a developer-centric manner. This is completely optional, but oftentimes if it works in Postman and not in another application or Salesforce, you can see what is different in Postman versus the other applications. This tutorial assumes the reader is familiar with Postman and has downloaded the application or is using the web version. This document will use the desktop installation for reference. This section does not require knowledge of the Salesforce Setup. We recommend starting with Postman before the setup in Salesforce.
To make life easier, download the Postman Collection already created for MS Graph. It does not contain the Teams integration unfortunately, but it does have a big chunk of other API’s that can be used to make sure the authorization is all setup as well as plenty of examples. To do so:
Click on Explore on the Menu at the Top of Postman
Search for MS Graph Workspace
It will be either MS Graph or MS Graph Fork Workspace
You can also find it by clicking on Workspaces and scrolling to it.
Create a new Fork from either the Graph or the Fork Graph – Right click on the Microsoft Graph Space to get the Fork Option
You should end up with something like this in your My Workspace or wherever you saved the forked Graph Collection to.
What this provides is a whole list of MS Graph APIs broken up into folders. In our testing, we used Delegated to validate with.
Setup Postman Authentication
Setting up Authentication is straightforward and will require the client id and secret key from the MS Azure setup done previously. Additionally, you will need to add the callback URL to the Authentication section in MS Azure. You also need to set up Environment variables as part of this step.
Setup Environment Variables
Postman needs to pass in environment variables to the headers in the API. To set these up, create a new environment to be used with MS Graph.
Click on Environments on the left hand side of Postman and click the Plus sign at the top of the environment list
Name your Environment and add in the 3 values needed
ClientID – This will be the Application ID of the App you created in MS Azure.
Client Secret – This will be the Secret Value created in the Client Secret step of Azure
TenantID – This is the tenant id found in the overview of your app.
Now that you have set up the environment variables – make sure to make that environment your active environment. It should show up here. You can access it from the drop down as well.
Setup Authentication
Click on the Delegated Folder in the MS Graph Collection on the left hand side of Postman. This will bring up the Authorization Screen.
Selection OAuth2.0 from the drop down.
Select Add Auth data to the Request Headers
Access Token → Available Tokens ( this will get filled in later )
Header Prefix – Bearer
Configure New Token Section
Token Name – Fill in something for this
Grant Type – Authorization Code
Leave the rest defaulted.
3. It will look much like this after filling out.
Set the Callback URL in MS Azure – Note: This step must be done or your auth will fail. Take the Callback URL above with the oauth URL for Postman and add it to the Callback URLs in your application in MS Azure.
Get a New Access Token – Use this to debug whether you can get authorized or not and once authorized use the token.
Click on the Get New Access Token at the bottom of this screen in Postman on the Authorization screen.
This will kick off the OAuth Flow, which will have you login to MS Azure and Authenticate. I used the Microsoft Authenticator download to my phone for MFA purposes which makes this more automatic.
Note: This is where if you have an incorrect setup, you’ll get a bunch of errors. Check your setup against the above, do you have the right token id?
You will go through the screens until you get a very long access token. Click on the Use Token button.
Create and Run the MS Graph Online Meeting API
Although there are several Teams APIs in the Team Folder, they are chat related versus the Online Meeting. We need to create a new API for the OnlineMeeting to be accessed. In this section we will cover creating the new API, adding parameters, and testing the API.
Navigate to the Teams Folder
Click New at the Top( or right click to add a request ) and add a new Web HTTP Request
Switch the type from GET to POST
Put in the name of the method in the POST
On the Body, use the JSON application type.
Add the body in JSON format, Subject was added for the example.
Click Send
Results are shown below from the meeting when successful.
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Sunilhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngSunil2022-05-24 05:57:032022-05-24 06:35:14From Brad Shively: Create MS Team Meetings from Salesforce (with Salesforce Scheduler)
Shift is one of the major additions made in Salesforce Scheduler, It provides the user with enormous flexibility and makes the entire process of appointment scheduling less cumbersome. The diagram below shows the interaction between Shift and various other entities involved in scheduling a Service Appointment.
A Service Territory Member can have multiple Shifts associated with it and as a result the time slot selected for the Service Appointment can fall between more than one overlapping shifts (considering both the required and primary Service Resources).
In the following sections we will figure out a way to reverse map all the associated Shifts with corresponding Service Appointment.
Creating a custom object
For completing the purpose of reverse mapping Shift with Service Appointment a custom object(Service appointment shift) is used as a junction object. It comprises of the following custom fields:-
ServiceAppointnmentId – Referring to a Service Appointment.
ShiftId – Referring to a Shift whose startTime and endTime completely encloses the Service Appointment’s time slot.
Modified – A boolean flag to help backtrack all the updates made to Service Appointment.Only the records with the flag value false should be considered as reliable entries.
Canceled – A boolean flag which is set to true only when the associated Service Appointment is canceled.
As evident from the design proposed whenever a Service Appointment is scheduled we need to obtain all the Shifts associated with the Service Appointment.For each associated Shift, one record comprising of ServiceAppointmentId,ShiftId
and Modified(initially false) must be made.
For achieving our goal of reverse mapping we will be writing triggers on two entities:
Service Appointment
Assigned Resource
Creating a Service Appointment
We must do the reverse mapping the moment a Service Appointment is created.Whenever a Service Appointment is created necessary inserts are made in Assigned Resource and this will invoke the trigger that we will be writing for Assigned Resource .
Pseudocode
Let us first discuss the pseudocode for triggers when new Service Appointments are created.
Create a trigger which runs after inserts are made in Assigned Resource.
Fetch all the linked Service Appointments using the just inserted Assigned Resource records.
Check for any previous entries for obtained Service Appointments in the custom object and for all those records set the Modified as true.
Design a map of Service Appointment and all the required resources for that appointment.
Loop through all the Service Appointments in the map and obtain the associated Shifts of the Service Resource.
Do the inserts for Service Appointment and Shift mapping records.
Updating a Service Appointment
Whenever a Service Appointment is modified we can make changes in the time slot and the required resources of the Service Appointment.Once a Service Appointment is updated we must set the Modified field for all the records of this Service Appointment in the custom object to true and obtain new associated Shifts. Let’s have a look at the possible scenarios and the way we are handling it.
Deletion of required SR from Appointment(will invoke an after delete trigger on Assigned Resource)
Addition of required SR to Appointment(will invoke an after insert trigger on Assigned Resource)
Moving of SR from required to optional resource(will invoke an after update trigger on Assigned Resource)
Moving of SR from optional to required resource(will invoke an after update trigger on Assigned Resource)
Change in Appointment start time and/or end time
Change in Appointment WTG/WT (Appointment duration)
Changing the time slot at the same time altering the Assigned Resources.
For these cases we will be using one update and a delete trigger on Assigned Resource wherein we implement a similar logic as mentioned above.
Disclaimer: The following code is meant to be verbose and easily understandable from a Salesforce Developer perspective. Given a choice between performance vs readability I have strived for the latter. It is a proof of concept to demonstrate the feature and should be modified and tested thoroughly as per different data shapes and existing code in the org.
trigger getassociatedshifts on AssignedResource (after insert,after update,after delete) {
/* fetching all the linked service appointments from the trigger */
List<ServiceAppointment> AllAppointments = new List<ServiceAppointment>();
if(Trigger.isDelete) {
List<String> AffectedAppointments = new List<String>();
For(AssignedResource a:Trigger.old) {
AffectedAppointments.add(a.ServiceAppointmentId);
}
AllAppointments = [Select Id,ServiceTerritoryId,SchedStartTime,SchedEndTime,WorkTypeId from ServiceAppointment where Id In :AffectedAppointments];
} else {
AllAppointments = [Select Id,ServiceTerritoryId,SchedStartTime,SchedEndTime,WorkTypeId from ServiceAppointment where Id In (Select ServiceAppointmentId from AssignedResource where Id In :Trigger.New)];
}
/*
check for any previous entries for obtained service appointments in the custom object
and for all those records set the modified flag as true
ServiceResourceToServiceAppointment = [Select ServiceResourceId,ServiceAppointmentId from AssignedResource where ServiceAppointmentId in:AllAppointments
For(Service_appointment_shift__c all:[Select id,modified__c from Service_appointment_shift__c where Service_Appointment__c In :changed]) {
all.Canceled__c =true;
all.Modified__c = true;
ServiceAppointmentShiftToUpdate.add(all);
}
/* updating the records */
update ServiceAppointmentShiftToUpdate;
}
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Sunilhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngSunil2022-04-28 03:54:132022-06-22 01:58:39From Adwait & Mrityunjoy Chowdhury: Reverse Map Service Appointment to the appropriate shift
A customer of Salesforce is looking to integrate with Zoom and the Online Meeting capabilities from Salesforce using Portal / Internal screens. The use case is fairly straightforward, as a customer of a bank, I want to schedule an online meeting with my advisor and discuss my accounts. The technology the bank wants to use is Zoom.
The technology usage behind this particular demo is to simply create a meeting in Zoom via an API which returns a URL that parties can click on to launch Zoom( either browser or desktop ) and have a meeting. There is a lot more that can be done, but this integration is to show the possibilities with the connection
Technology Utilized
Listened below are the main technologies and configurations used in the demo preparation.
<optional> Visual Code – Used to write and deploy code
Apex Classes
Invocable Methods setup to make available in Flows
Test Classes
Auth Provider Setup in Salesforce
Named Credentials
Salesforce Flows – To provide the screen navigation, call Zoom to get the meeting, and update the appropriate records.
Demo Flow High Level
This section describes the general flow of the demo from start to finish when showing to the customer. This is a specific flow for the customer this demo was prepared for. You can tailor or make your own flow(s) for your customer.
Customer goes to the portal to schedule a meeting, using the Salesforce Scheduler.
This demo has an authenticated flow, there is a person account associated with the demo.
Enter the required information from the screen
Click by previously scheduled service appointments or search for a banker.
Click Next
Click on a Work Type Group → Select the type => Click Next
Select Video Call
Enter a address → San Francisco → Select a branch
Choose a date in scheduler
The call to Zoom is done at this point and a URL is returned to the “Additional Information” Section. Note, this could be put anywhere but for the purpose of the meeting we chose here.
Click on next and a new Service Appointment is created with the Meeting URL in a custom field that can be accessed to launch a Zoom meeting.
The integration behind the scene created a Zoom meeting valid link that can be clicked on to start a Zoom meeting. This utilized the Zoom API, OAuth/Open ID authentication/authorization, and Apex Callout to create and return the meeting.
Demo Details
This section will describe the setup needed to execute the demo. What is described is the particular flow used to validate and test the integration. The entire section for Postman is completely optional, but it is suggested to do this to validate and debug. In our case, it was invaluable in determining the exact headers to place into the API. In the initial development, Postman was first used outside of Salesforce to ensure the API format was correct and the authentication/auth was setup correctly in Zoom.
Zoom Setup
The first piece that is needed is a Zoom Developer Account. Please note you cannot use a Salesforce Zoom account as they have disabled permission to use the API. Best bet create Personal Zoom account with personal ( no salesforce account) or working with your client account that allows to create meeting via API
Name it, choose an account level app and toggle off the publish button like this.
Next screen
Screen will show the client key, client secret. Copy & store in a secure place. You will need these in the Salesforce setup.
Populate the redirect url and add the allow list.
You will find the redirect url to use in Salesforce → Setup → Authentication provider → Callback URL. (You can change this once you setup authentication provider in Salesforce.)
This section describes the Salesforce Setup needed to access Zoom API meetings. It is strongly advised to setup Postman first to validate and test the API as well as get familiar with the API before jumping into Apex coding setup. This section will consist of Authentication setup, the Named Credential, and the Apex code needed to create a Zoom meeting and retrieve a URL. Additionally, this will provide the callback referenced in the Zoom section which will be needed to complete the Authentication section in Zoom.
Auth. Provider Setup
The first step is to create the Authorization Provider configuration to connect to Zoom. You will need the Secret Key(Value) from the Certificate setup in Zoom and the application id.
Enter Salesforce Setup → Auth Providers → New.
Choose Open ID Connect from the Provider Type drop-down.
Name the Auth Provider.
URL Suffix → Can make the same as the name.
Consumer Key → This is the client key in Zoom.
Consumer Secret → This is the client secret in Zoom.
Make sure this option is checked: Send client credentials in header.
Use the defaults for the remainder.
Save.
Click on the newly defined Auth Provider to open it up.
Copy the Callback URL that is shown in the Salesforce Configuration. If you have Experience Cloud setup and you are using those domains, then add those callback URLs as well to the Zoom Dev configuration.
Take the callback URL you copied above and paste back in the Zoom redirect url & allow list. (Use the exact same word to word, no space.)
Named Credential
Creating a named credential will perform the authentication to Zoom and do the OAuth validation. Here is where the Zoom Authenticated App is used to validate the OAuth connection. (I set mine to auto approve.) It will prompt you to login to your instance of Zoom. The login will be the Zoom Developer login/id created during the setup of the developer instance.
In Setup → Named Credentials, click New.
Enter the label and the URL of the API Endpoint you wish to access. In this case, the full API is used for the onLineMeeting for Delegated access. The application access has a different signature
Select the Auth Provider created in the previous step.
Scope: very important! The scope here will match the scope you created in Zoom for the application. It is space delimited.
meeting:write:admin
Click on Generate Authorization Header.
Check on Start Auth Flow on Save.
Generate Auth Header is checked.
Click Save. This will trigger the actual connection to Zoom and validate the Authentication.
When you Save, the OAuth flow will initiate.
Zoom Login Screen will popup.
Login.
If successful, you will see Authenticated in the Authentication Status in Salesforce. If it fails, you will get a failure screen from Zoom. Common Issues:
Used the wrong secret key or id. Double check the values in the Auth. The Providers are correct.
URL Endpoint is invalid. Check your URL Endpoint. (Using Postman first helps avoid this issue.)
Salesforce Application Code
This section will review the Apex application code needed to make the Rest API call to setup a Zoom meeting and retrieve the meeting URL from the Zoom Server. The code is not production quality but instead is a sample to prove the concepts. The current iteration does not accommodate error handling in a meaningful way nor does it do much more than create a meeting. The goal of this good is to demonstrate the basic connection for the customer and proof of concept the meeting invites. The sample code will be in two parts, the first part is a test class that can be used to validate the connection and result. Once that is working, then the 2nd class uses @InvocableMethod so that it can be used in flows. Obviously this can be tailored however desired.
This section does not instruct how to setup command line tools, deploy the source, or other development tasks. It is assumed the reader understands how to deploy, run the developer tools/debugger in Salesforce.
Test Apex Class – Simple Class to Create the Meeting utilizing Named Credentials
public class TestZoomApi {
/* Test Method for Unit Testing Connection */
public static String getMeetingUrl()
{
HttpRequest req = new HttpRequest();
Http http = new Http();
//Setup the Endpoint and append the name of the file
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
(parser.getText() == ‘join_url’)) {
parser.nextToken();
webLink = parser.getText();
System.debug(‘join_url= ‘ + webLink);
}
}
return webLink;
}
}
Common Issues/Errors
Zoom will return a 201 in the HTTP Response. This is a success. It is documented in the API.
HTTP Error 500 – Internal Server Error
Notice the headers that are set. The Zoom documentation does not state it explicitly, but in our testing we found that the 2 accept lines need to be in the header when sending the request. You need to add the gzip, etc and the “*/*” accept lines.
401 – The 401 unauthorized generally means the scope is incorrect in the Named Credential, or in the Named Credential and/or the Zoom setup. Make sure the permissions are correct and the scope is space delimited.
403 – Forbidden – This occurs when the secret keys are incorrect. You should have fixed this when you saved the name credential so it shouldn’t show up.
Note: When using the Apex Debugger – Look for the debug line to joinWebURL populated with a long string for the meeting. It will start with something like this: 12:40:52:477 USER_DEBUG [37]|DEBUG|joinWebUrl= https://us04web.zoom.us/j/xxxxxxxxxx?pwd=xxxxxxxxxxxxxxxxx
Salesforce InvocableMethod Class Utilizing the Apex Code and Callout
This is the actual code used in the demonstration. This code is accessible in the Flow Builder inside of Salesforce as an Apex Action.
global class GetZoomMeetingURLwithInput {
@InvocableMethod(label=’Get Zoom Meeting URL with Input’ description=’Returns a meeting URL For Zoom’)
global static List<String> makeApiCalloutwithInput(List<List<String>> inputZoomsParms)
{
HttpRequest req = new HttpRequest();
Http http = new Http();
//Setup the Endpoint and append the name of the file
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
(parser.getText() == ‘join_url’)) {
parser.nextToken();
webLink = parser.getText();
System.debug(‘join_url= ‘ + webLink);
}
}
// Apex Actions Return. The method signature for an invocable method requires a List of Strings to be returned.
return new List<String>{webLink};
}
}
Salesforce User Experience Setup
This section is optional but describes how the above code can be accessed in the low-code building tools inside of Salesforce.
This section in a flow shows how this action is called to retrieve a URL for the Zoom Meeting and then assigns it to a Record (such as the Service Appointment, and/ or its associated Event) in Salesforce. A larger flow will then do further processing as part of a full scheduling flow. The takeaway is that the Apex Code above is an option to drag and drop into the low code builder and use it when running a flow. It could also be embedded within a Lightning Web Component(LWC) and used in other places. Alternatively, it can be accessed from another Apex Class to get the required information.
Postman Setup
This section describes how to setup Postman to access Zoom APIs and test the API integration outside of Salesforce in a developer-centric manner. This is completely optional, but oftentimes if it works in Postman and not in another application or Salesforce, you can see what is different in Postman versus the other applications. This tutorial assumes the reader is familiar with Postman and has downloaded the application or is using the web version. This document will use the desktop installation for reference. This section does not require knowledge of the Salesforce Setup. We recommend starting with Postman before the setup in Salesforce.
Postman Collection – use version 2 link below. (Do NOT use v1.)
To make life easier, download the Postman Collection already created for Zoom as plenty of examples. To do so:
Setup Postman Authentication
Setting up Authentication is straightforward and will require the client id and secret key from the Zoom setup done previously. Additionally, you will need to add the callback URL to the Authentication section in Zoom. You also need to setup Environment variables as part of this step.
Salesforce Scheduler gives tools needed to simplify appointment scheduling in Salesforce. We can create a personalized experience by scheduling customer appointments in person, or by phone or video; with the right person at the right place and time. One of the strong feature of the product is its ability to manage availability of multiple Service Resources for various Work Types across multiple Service Territories.
Now the biggest question is if there is an out of the box Salesforce Report that can provide a list of service appointment slots available for all or a specific set of service resources. The Answer is NO.
So, how do we solve for it?
Salesforce Scheduler calculates the availability of a service resource at runtime on demand (when a user is scheduling an appointment). Salesforce Scheduler uses multiple entities along with data from external systems to calculate availability data. This information is NOT stored anywhere to report on.
To solve for the reporting Question – we need some complex level of customization. This can be achieved using the power of the Salesforce Scheduler and Salesforce platform to generate reports on Service Resource’s availability information.
Approach we will use in this blog post
Salesforce Scheduler provides the LxScheduler namespace which offers the apex method getAppointmentCandidates which provides the availability information. We will use this method to
retrieve the information using Apex
dump the retrieved information into a custom object that we will create and
report on top of the custom object
Create Custom Object – Appointment Slots
Let us create a custom object, “Appointment Slots” with these custom fields to store availability information
Service Resource (lookup)
Service Territory (lookup)
Work Type Group (lookup)
Start Date (Date/Time)
End Date (Date/Time)
Remaining Appointments (Integer, default value = 1)
Enable reporting for this custom object.
Query and Dump retrieved information into the Custom Object
public without sharing class ReportDump implements Database.Batchable<sObject>{ public Database.QueryLocator start(Database.BatchableContext BC){ String query = 'SELECT Id FROM ServiceResource where isActive = true'; return Database.getQueryLocator(query); }
public void execute(Database.BatchableContext BC, List<ServiceResource> srList){ Integer DUMP_DURATION = 30; String ACCOUNT_ID = '001xx000003GYQRAA4'; String SCHEDULING_POLICY = '0Vrxx0000004C92'; //Hardcoding WTG for now List<String> wtgs = new List<String>(); wtgs.add('0VSxx0000004C92GAE');
List<Appointment_Slots__c> slots = new List<Appointment_Slots__c>();
for (ServiceResource sr : srList){ //Find all territories he works in List<ServiceTerritoryMember> stms = [Select Id, ServiceTerritoryId from ServiceTerritoryMember where ServiceResourceId = :sr.Id]; List<String> territories = new List<String>(); for (ServiceTerritoryMember stm : stms){ territories.add(stm.ServiceTerritoryId); }
for (String wtg : wtgs){ lxscheduler.GetAppointmentCandidatesInput input = new lxscheduler.GetAppointmentCandidatesInputBuilder().setWorkTypeGroupId(wtg).setTerritoryIds(territories).setStartTime(System.now().format('yyyy-MM-dd\'T\'HH:mm:ssZ', 'America/New_York')).setEndTime(System.now().addDays(DUMP_DURATION).format('yyyy-MM-dd\'T\'HH:mm:ssZ', 'America/New_York')).setAccountId(ACCOUNT_ID).setSchedulingPolicyId(SCHEDULING_POLICY).setApiVersion(Double.valueOf('54.0')).build(); String response = lxscheduler.SchedulerResources.getAppointmentCandidates(input);
public void finish(Database.BatchableContext BC){ }
}
Create a Report using the Custom Object
Create a Salesforce report using this custom object. Refer – https://help.salesforce.com/s/articleView?id=sf.rd_reports_overview.htm&type=5 on how to create reports. Here is a sample matrix report we created which reports a Service resources total available hours at a Service location for an appointment topic / template – and this is how it looks.
Truncating records in custom Object
The example quoted above requires the Appointment Slots object to be empty in order to calculate the Service Resources availability. Ensure you truncate the data in the custom object before running the above batch job. Please refer this help article on Truncating Salesforce Obejcts https://help.salesforce.com/s/articleView?id=sf.dev_object_trunc.htm&type=5.
In the Spring ‘22 release, Scheduler introduced Shift Rostering Management which can be used to setup working hours for resources.
Shifts is a paradigm changing update to Salesforce Scheduler product. It eases pain of setting adhoc or non-recurring time slots for Service Resources to work. It also gives flexibility to work outside Service Territory’s operating hours.
One of the advantages of using Shifts is the ability to use Custom reports to report on working hours of a resource but that goes away if we allow resources to setup shifts beyond the working hours of a Territory. So here one would want to restrict the Service Resource to only create Shifts within the working hours of a Service Territory. This way, you could use create a custom report on the Shift record to understand the working hours of previous weeks or months.
Another scenario where this could be a need is when we have two types of Service Resources:
Service Resources who work within the constraints of their Service Territory’s Operating Hour
Service Resources who can go beyond their Service Territory’s Operating Hours. For eg: contractors (independent wealth managers) who can even take important appointments after working hours of the Service Territory (Branch)
Selectively restraining working hours of resources
First we need to define which resources can work beyond their branches working hours.
For this we are going to simply add a custom field to Service Resource of type boolean. Let’s call this field OvertimeEnabled for now.
If OvertimeEnabled is True then the Service Resource can work extra hours else they cannot.
Data Model
Next we need to set our Scheduling Policy such that we don’t restrict Shifts as per Service Territory’s Operating Hour by default. For this we will se up policy to use Shifts but uncheck the box ‘Use service territory’s operating hours with shifts’
Now we can add a trigger on Shift entity which runs before insert and update on the entity. In this trigger we will check validate that shift timings are within Branch’s Operating Hours only for resources who have OvertimeEnabled flag set to false.
Set<Shift> confirmedShifts = new Set<Shift>(); Set<String> territoryIds = new Set<String>(); //We will only run this validation for Shifts with Status Category = "Confirmed" AND Service Resource can work extended hours for(Shift shift: shifts) { if(shift.StatusCategory == 'Confirmed' && srIds.contains(shift.ServiceResourceId)) { confirmedShifts.add(shift); territoryIds.add(shift.ServiceTerritoryId); } }
if(confirmedShifts.size() > 0) { //Get all Service Territory IDs along with their OperatingHourId ServiceTerritory[] territoryIdsWithOperatingHours = [SELECT Id, OperatingHoursId FROM ServiceTerritory WHERE Id IN :territoryIds];
Set<String> operatingHourIds = new Set<String>(); for(ServiceTerritory st: territoryIdsWithOperatingHours) { //Service Territory may not have Operating Hour defined if(st.OperatingHoursId != null) { operatingHourIds.add(st.OperatingHoursId); } }
//Get Timeslot information for all Operating Hours got in previous step. We disregard all STM level concurrent timeslots (Shifts with MaxAppointments set to 1) TimeSlot[] timeSlots = [SELECT Id, DayOfWeek, StartTime, EndTime, OperatingHoursId FROM TimeSlot WHERE MaxAppointments = 1 AND OperatingHoursId IN :operatingHourIds];
//Complex data structure to store Working hours for all Service territories. We will store empty inner map in case Service Territory does not have Operating Hour defined Map<String, Map<String, TimeSlot>> serviceTerritoryWithTimeSlotsPerDay = new Map<String, Map<String, TimeSlot>>();
if(dayOfShiftStart != dayOfShiftEnd) { s.addError('Shift should be within Service Territory\'s Operating hours '); } else if(slots.get(dayOfShiftStart) == null || slots.get(dayOfShiftEnd) == null) { s.addError('Operating Hours for Service Territory not set up correctly'); }else if(s.StartTime.time() < slots.get(dayOfShiftStart).StartTime || s.EndTime.time() > slots.get(dayOfShiftEnd).EndTime) { //Eureka s.addError('Shift should be within Service Territory\'s Operating hours '); } } } }
P.S. For this code we have considered that Service Territory’s OH are in same timezone as shifts being created.
https://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.png00Akshayhttps://unofficialsf.com/wp-content/uploads/2022/09/largeUCSF-300x133.pngAkshay2022-02-09 04:38:062022-02-09 04:38:44From Ankit Srivastava: Restraining Shifts within the Service Territory’s Operating Hours