Skip to main content

Facilio SDK for Salesforce


Facilio is a leading provider of facilities management software that helps businesses streamline their operations and improve efficiency. Facilio offers an SDK for Salesforce that enables developers to integrate their facilities management software with Salesforce, leveraging the power of the Salesforce platform to enhance the user experience and drive better business outcomes.


The Facilio SDK for Salesforce provides developers with a set of tools and resources that enable them to easily integrate their facilities management software with the Salesforce platform. The SDK includes the FacilioAPI Apex class, as well as a range of other tools and resources such as sample code, documentation, and support services.

Setting up the Facilio SDK#

This section provides a step-by-step guide for setting up the Facilio SDK in your Salesforce instance.

Prerequisites#

Before proceeding with the installation of the Facilio SDK, ensure that you have the following prerequisites:


  1. A Salesforce account with admin access
  2. A Facilio account with a valid API key
  3. Basic knowledge of Salesforce administration

Install & Configure#

Configure Facilio URL in Remote Site Settings before installing Facilio SDK Package

  1. Navigate to Setup > Security > Remote Site Settings.
  2. Click on "New Remote Site" and enter "Facilio" as Remote Site Name and Facilio URL in Remote Site URL.

Click "Save" to add Facilio URL in Remote Site Settings.


Configuration


Once the Remote Site Settings is setup, Install the Facilio SDK for Salesforce package shared by Facilio Team.


After installing the Facilio SDK for Salesforce package, follow the below steps to configure the Facilio URL and API key:
  1. Navigate to Setup > Package Manager > Installed Packages.
  2. Find the Facilio SDK package in the list of installed packages and click on "Configure".
  3. In the configuration page, enter your Facilio URL and API key.

Click "Save" to apply the changes.


tip

If you don't have a Facilio API key, you can generate one by following the instructions provided in this document: https://facilio.com/help/docs/user-guide/managing-user-account/managing-api-clients


Configuration


Conclusion#

Congratulations! You have successfully installed and configured the Facilio SDK for Salesforce in your instance. You can now use the SDK to integrate your Salesforce data with the Facilio platform and unlock its powerful features. If you have any questions or issues, please contact the Facilio support team for assistance.

FacilioAPI (Apex Class)#

The FacilioAPI Apex class provides a set of methods that developers can use to interact with the Facilio platform from within the Salesforce environment. The methods available in the FacilioAPI Apex class include createRecord and updateRecord, among others.

createRecord#

The createRecord method allows developers to create new records in the Facilio platform from within Salesforce. This method takes two parameters:


Syntax : Long facilioId = FacilioAPI.createRecord(String moduleName, Map record);


Params:

ParamDescription
moduleNameA string that specifies the module name of the record to be created.
recordA map of key-value pairs that specifies the details of the record to be created, such as the record name, record type, and any relevant data points.

Once the parameters have been specified, the createRecord method sends the data to the Facilio platform and creates a new record.

updateRecord#

The updateRecord method allows developers to update existing records in the Facilio platform from within Salesforce. This method takes three parameters:


Syntax: Boolean updateStatus = FacilioAPI.updateRecord(String moduleName, Long recordId, Map record);


Params:

ParamDescription
moduleNameA string that specifies the module name of the record to be created.
recordIdA long integer that specifies the ID of the record to be updated.
recordA map of key-value pairs that specifies the details of the record to be created, such as the record name, record type, and any relevant data points.

Once the parameters have been specified, the updateRecord method sends the updated data to the Facilio platform and updates the existing record.

getRecord#

The getRecord method allows developers to fetch existing records to the Salesforce from Facilio platform. This method takes two parameters:


Syntax: Map record = FacilioAPI.updateRecord(String moduleName, Long facilioId);


Params:

ParamDescription
moduleNameA string that specifies the module name of the record to be created.
recordIdA long integer that specifies the ID of the record to be updated.

Once the parameters have been specified, the getRecord method returns the fetched data from the Facilio platform.

addNote#

The addNote method allows developers to add note to the existing record in the Facilio platform from within Salesforce. This method takes three parameters:


Syntax: Long noteId = FacilioAPI.addNote(String moduleName, Long facilioId, String noteContent );


Params:

ParamDescription
moduleNameA string that specifies the module name of the record to be created.
recordIdA long integer that specifies the ID of the record to be updated.
noteContentA string that specifies the note to be added.

Once the parameters have been specified, the addNote method sends the data to the Facilio platform and creates a note in the specified record.

uploadAttachment#

The uploadAttachment method allows developers to upload attachments to the existing record in the Facilio platform from within Salesforce. This method takes five parameters:


Syntax: FacilioAPI.uploadAttachment(String moduleName, String recordId, Blob file, String fileName, String fileContentType);


Params:

ParamDescription
moduleNameA string that specifies the module name of the record to be created.
recordIdA long integer that specifies the ID of the record to be updated.
fileA blob that specifies the content of the attachment retrived from salesforce.
fileNameA string that specified the name of the attachment to be added.
fileContentTypeA string that specifies the contentType of the blob file to be added.

Once the parameters have been specified, the addAttachment method sends the data to the Facilio platform and add a new attachment to the specified record.

Examples#

Create record using Apex Triggers#

To create a Facilio record using Apex triggers, developers can use the FacilioAPI Apex class provided by the Facilio SDK. Create a new apex class and new apex trigger Within the trigger code, developers can call the newly created apex class and call apex createRecord method of the FacilioAPI Apex class inside the newly created apex class by passing in the necessary parameters such as the module name and record details.


For example, a developer might create an Apex trigger that automatically creates a new work order in the Facilio platform whenever a new case is created in Salesforce. The trigger code could include a call to the Apex class Using the apex class createRecord method of the FacilioAPI Apex class can be called, passing in the module name "workorder" and the relevant details of the work order such as the work order type, description, and location.


Apex Trigger:

trigger CaseTrigger on case (after insert, after update) {    for (case objCase : Trigger.new) {        String subject = objCase.subject;        String description = objCase.description;        facilioService.create(subject , description);    }}

Apex Class:

public class facilioService {    @Future(callout=true)    public static Void create(String subject, String description){        String siteId = '238325'; // Replace your Facilio's site id here
        Map<String, String> recordMap = new Map<String, String>();        recordMap.put('subject', subject);        recordMap.put('siteId', siteId);        recordMap.put('description', description);
        Long facilioID = facilio_sdk.FacilioAPI.createRecord('workorder', recordMap);
        Case.Facilio_ID__c = facilioID; // If you want to store the Facilio ID in SF, create a custom field in SF and update the value here    }}

Update record using Apex Triggers#

To update a Facilio record using Apex Triggers, developers can use the FacilioAPI Apex class provided by the Facilio SDK. Within the trigger code, developers can call the updateRecord method of the FacilioAPI Apex class, passing in the necessary parameters such as the module name, the record ID, and the updated record details.


For example, a developer might create an Apex trigger that updates the subject and description of a work order in the Facilio platform whenever the status of a related case is updated in Salesforce. The trigger code could include a call to the Apex class. Using the apex class, updateRecord method of the FacilioAPI Apex class can be called, passing in the module name "workorder," the ID of the work order to be updated, and the updated status of the work order.


Apex Trigger:

trigger CaseTrigger on Case (after insert, after update) {    for (Case objCase : Trigger.new) {        String subject = objCase.subject;        String description = objCase.description;        facilioService.update(subject, description);        // Here the subject and description is updated for the already created workorder in Facilio.    }}

Apex Class:

public class facilioService {    @Future(callout=true)    public static Void update(String subject , String description){        Long facilioID = Case.Facilio_ID__c;        if (facilioID != null) { // update only if the record is already synced to Facilio
            String siteId = '238325'; // Replace your Facilio's site id here
            Map<String, String> recordMap = new Map<String, String>();            recordMap.put('subject', subject);            recordMap.put('siteId', siteId);            recordMap.put('description', description);
            facilio_sdk.FacilioAPI.updateRecord('workorder', facilioID, recordMap);        }    }}

Get record using Apex Triggers#

To fetch a Facilio record using Apex Triggers, developers can use the FacilioAPI Apex class provided by the Facilio SDK. Within the trigger code, developers can call a apex class from that apex class getRecord method of the FacilioAPI Apex class can be called, passing in the necessary parameters such as the module name and the record ID


For example, a developer might create a Apex Class that fetches a record of a site in the Facilio platform. The Apex class code could include a call to the getRecord method of the FacilioAPI Apex class, passing in the module name "site" and the ID of the site to be fetched.


Apex Class:

// Sample apex class codepublic class facilioService {    @Future(callout=true)    public static Void get(){        Map<String, object> record = facilio_sdk.FacilioAPI.getRecord('site',12345);        //Site Data is returned in the Map 'record'.    }}