Manage your team's calendar and become more productive with Salesforce's Field Service Lightning

Learn how to implement the solution by having a few API’s calls from Salesforce to Cronofy and manage your team’s calendar from one platform. 

 

Field Service Lightning is Salesforce’s onsite job management platform that helps organizations to dispatch technicians/agents to do a particular job, by taking into account their skills and tools and also their driving and service times.

To help the technicians/agents, Salesforce also provides Field Service Mobile App for Android and iOS, which, at the moment this article is being written, lacks the end-user’s calendar synchronism capability. 

Cronofy is a service that enables software applications to connect to users’ calendars and perform actions on their behalf, like create calendar events, check scheduling availability, etc..

 

To have Salesforce communicate with Cronofy, you’ll have to perform OAuth 2.0 calls and to do that, you’ll need first to create an application on Cronofy, that will provide you API Host, Site Host, Client Id and Client Secret. 
In order to perform actions with Cronofy (create event, update event, check availability, etc.) on behalf of a user, you’ll need your users to navigate to a URL that you’ll need to create, for them to do the authorization.
 
String autorizationUrl = 'https://app.cronofy.com/oauth/authorize?
    response_type={RESPONSE_TYPE}
    &client_id={CLIENT_ID}
    &redirect_uri={REDIRECT_URI}
    &scope={SCOPE}';

Explaining the parameters:

  • RESPONSE_TYPE - must always be code

  • CLIENT_ID - it’s the one from Cronofy App

  • REDIRECT_URI - you’ll need to send this back to a Salesforce page that you also need to create, because when the user approves this authorization, it will send you back a code.

  • SCOPE - This parameter is the scope of privileges you want to perform your actions

  • On the REDIRECT_URI page, you will receive a code on URL, that you must use to request an access token, which will provide you with several important parameters to be used on the following calls. This is an example of what the response should look like:

 

{

  "token_type""bearer",

  "access_token""P531x88i05Ld2yXHIQ7WjiEyqlmOHsgI",

  "expires_in"3600,

  "refresh_token""3gBYG1XamYDUEXUyybbummQWEe5YqPmf",

  "scope""create_event delete_event",

  "account_id""acc_567236000909002",

  "sub""acc_567236000909002",

  "linking_profile": {

    "provider_name""google",

    "profile_id""pro_n23kjnwrw2",

    "profile_name""example@cronofy.com"

  }

}

Next step you’ll need to perform is a call to calendars, which will provide the list of calendars the user has authorized. This is an example of what the response should look like:

 

{

    "calendars": [

      {

        "provider_name""google",

        "profile_id""pro_n23kjnwrw2",

        "profile_name""example@cronofy.com",

        "calendar_id""cal_n23kjnwrw2_jsdfjksn234",

        "calendar_name""Home",

        "calendar_readonly"false,

        "calendar_deleted"false,

        "calendar_primary"true,

        "calendar_integrated_conferencing_available"true,

        "permission_level""sandbox"

      },

      {

        "provider_name""google",

        "profile_id""pro_n23kjnwrw2",

        "profile_name""example@cronofy.com",

        "calendar_id""cal_n23kjnwrw2_n1k323nkj23",

        "calendar_name""Work",

        "calendar_readonly"true,

        "calendar_deleted"true,

        "calendar_primary"false,

        "calendar_integrated_conferencing_available"false,

        "permission_level""sandbox"

      }

    ]

  }

You’ll need calendar_id parameter for the next call. 

The final step will be to create a Record-Triggered Flow or a Trigger with Apex to call Cronofy’s upsert-event when Schedule Start and Schedule End dates are set on Service Appointments. This is an example of what the call should look like:

 

POST /v1/calendars/{CALENDAR_ID}/events 

Host: {API_HOST}

Authorization: Bearer {ACCESS_TOKEN}

Content-Type: application/json; charset=utf-8

 

{

  "event_id""qTtZdczOccgaPncGJaCiLg",

  "summary""Scheduled Appointment",

  "description""Work on ...",

  "start""2021-03-27T15:30:00Z",

  "end""2021-03-27T17:00:00Z",

  "location": {

    "description""Main Street, 12th"

  }

}

Explaining the parameters:

  • CALENDAR_ID, API_HOST and ACCESS_TOKEN - are the ones from the previous calls

  • event_id - it’s your own generated id, it can be the Schedule Appointment Id

And that’s it! Thank you for reading and if you need a similar implementation or need some explanation on what was written, let us know.

 

Os campos obrigatórios estão assinalados com um asterisco(*)

Ao submeter este formulário assume ter lido a nossa declaração de privacidade, dando o seu consentimento para que façamos o processamento de dados de acordo com a referida declaração (incluindo transferências internacionais). Se, a qualquer momento, mudar de ideias quanto à receção de informação sobre a PwC, poderá enviar-nos um email.

Contacte-nos

Luís Côrte-Real

Luís Côrte-Real

Customer Transformation Director, PwC Portugal

Fechar