Add Photos on a Newly-Created Record Using Field Service Mobile Flow and SFS Mobile (Developer-Orien
In this article, we will demonstrate how to use the SharinPix app to add photos on a newly-created object record using the Field Service Mobile Flow on the SFS mobile app.
The scenario will be as follows:
A field technician launches the Salesforce Field Service mobile app.
He encounters an issue relating to a Work Order record and wants to document on same by adding a subject and a description on a new Case record. The technician also wants to add photos to the same Case record.
To do so, the technician taps on a button labeled Open a Case within the Field Service mobile app to create a new Case record with the necessary information and photos. This button launches a Field Service Mobile Flow allowing the technician to enter information about the new Case record. The Flow also includes a deeplink to the SharinPix mobile app allowing the user to capture the photos that will be added to the newly-created Case record.
In the following sections, you will learn how to implement the above scenario using:
A new field on the Case object as well as a new custom object, PendingAlbum, to store the information required to move the images to the newly-created Case records.
A Field Service Mobile Flow to enter the Case details as well as to launch the SharinPix mobile app to take pictures.
A Webhook alongside the Apex classes to move the photos captured to the Case record when the latter is created.
1. Pre-configuration
Before setting up the Flow and Webhook, we need to add a custom field on the Case object. This field will be used later on to store a Case record identifier. We will explain the need for this identifier in a subsequent step. For now, go ahead and create the custom field on the Case object using the following details:
Label: SharinPix Temporary ID
Data Type: Text Area
Another object, PendingAlbum needs to be created with two fields: Image Ids which holds the image IDs, and Temporary Id , which retains a unique ID associated with the Case record. Proceed by creating the custom object and the fields as indicated below:
Object configuration:
Name: SharinPix Pending Album
Description (optional): This custom _ object is used by SharinPix to store the metadata of images uploaded from the field service mobile app._
First field configuration:
Data Type:Long Text Area
Label:Image Ids
Description (optional):This field is used to store the image's Ids.
Second field configuration:** **
Data Type: Text
Label: Temporary Id
Length: 150
Description (optional): This field is used to store the temporary ID to retrieve the destination record.
2. Setup the Field Service Mobile Flow
To create the flow, follow the steps below:
Go to Setup then type Flow in the Quick Find box. Under Process Automation, select Flows
Click on New Flow. You will be directed to the Flow Designer
Click on Show More and select Field Service Mobile Flow. Then click on Create
Retrieve the SharinPix Mobile Upload Token from the parent Work Order record
A mobile upload token is needed whenever the SharinPix mobile app is used to upload photos on any record. This token provides SharinPix with information such as the album on which the photos should be uploaded.
In our case, however, we do not have any token being generated for the new Case records. Therefore, to launch the SharinPix app and capture images, we will proceed as follows:
We will use the mobile upload token already present on the parent Work Order record instead to temporarily upload the photos to the Work Order record first.
Then, by using a Webhook that will call an Apex class to move the images captured from the Work Order record to the newly-created Case records.
In the following section, we will configure the Flow to retrieve the SharinPix mobile upload token from the Work Order record. To do so, follow the steps below:
Go on the Manager tab and click on New Resource.
Resource Type: Variable
API Name: Id
Data Type: Text
Default Value: {!$GlobalConstant.EmptyString}
Availability Outside the Flow: Available for input
Go to the Manager tab again and click on New Resource.
Resource Type: Variable
API Name: WorkOrderRecord
Data Type: Record
Object: Work Order
Click Done** **
Next, go to the **Elements tab then drag and drop the Get Records **element found under the Data section onto the blank canvas. For the Get Records:
Label: g****etWorkOrder
Object: Work Order
Conditions: Id (Field) equals (operator) **{!Id} **(newly-created resource named Id)
In the How Many Records to Store , check the Only the first record option
In the Where to Store Field Values , check the** Together in a record variable** option
Then in the **Select Variable to Store Work Order **section, use the WorkOrderRecord variable for the **Record **field
In the Select Work Order Fields to Store in Variable section, click on Add Field and select the token field, that is, SharinPix_Token__c for this demo
Click **Done **when finished
Then, connect the Get Records (Get Work Order) element to the Start element
Create the case record
The next step is to set up a **Screen **element to enter the Case record's details. To do so:
Go to the **Elements tab then drag and drop the Screen ** element onto the blank canvas. Label the Screen element as Create Case
Next, drag and drop two **Text **components on the screen canvas
Label the first Text component as **Subject **and the second one as Description
Click Done to save
Then, connect the Screen (Create Case) element to the Get Records (Get Work Order) element previously added
Now, let's add a Create Records element to the canvas to create the Case record.
First, we will create a variable to store the record using the steps below:
Click on New Resource
Resource Type: Variable
API Name: caseRecord
Data Type: Record
Object: Case
Click Done
Generate a temporary ID to identify the newly created Case record
Go to the Manager tab again and click on New Resource.
Resource Type: Text Template
API Name: textTemporaryID
In the Body section, select View as Plain Text in the dropdown
Resource Picker: {!$Flow.CurrentDateTime}
Click Done
Go to the Manager tab again and click on New Resource.
Resource Type: Formula
API Name: temporaryID
Data Type: Text
Formula: SUBSTITUTE({! textTemporaryID}, " ", "")
Click Done
Now, let us add the Create Records element to the canvas:** **
Go to the **Elements tab then drag and drop the Create Records **element onto the blank canvas. For the Create Records:
Label: New Case Record
In the How to Set the Record Fields section, select Use separate resources, and literal values
Object: Case
In the** Set Field Values for the Case **section, choose Description as the field and Description as the matching value then click on the Add button. Next, choose **Subject **as the second field the variable Subject as value. For the **sharinPixTemporaryID__c has the variable temporaryID **as Value. Both the Origin and Status fields need values to create a case, so assign Phone to the Origin field and the variable New to the Status field.
In the Store Case ID** in Variable **section, choose **{!caseRecord.Id} **as value
Click Done to save
Next, connect the** Create Record **(New Case Record) element to the Screen (Create Case) element added previously
Add the deeplink (URL) to the SharinPix app
The next step is to add a Screen element to enable the launching of the SharinPix app to capture photos. To do so, follow the steps below.
Firstly, let's create a new resource that will store the deeplink to the SharinPix app with the following details:
Resource Type: Variable
API Name: deeplink
Data Type: Text
Default Value:
< a href="sharinpix://upload?token={!WorkOrderRecord.SharinPix_Token__c}&caseTempId={!temporaryID}">Click to launch the SharinPix App
In the deeplink above, we are also passing the temporary ID as caseTempId={!temporaryID}.
For more details about the deeplink syntax, please refer to the following article:
SharinPix mobile App : Deeplink syntax
Next, add a Screen element to launch the SharinPix app using the deeplink. Follow the steps below:
Drag and drop a **Screen **element on the canvas with **Launch SharinPix App **as the label
Next, drag and drop a **Display Text **component on the screen and add the following details:
API Name: sharinpixAppLauncher
In the **Insert a resource... **section, select deeplink
Click Done to save
To complete, connect the Screen (Launch SharinPix App) element to the Create** Records** (Create Case) element previously added.
The Flow should look like this at this point.
Save the Flow as **Create Case **and activate it. Then add the Flow as an **Action **labelled as **Open a Case **on the **FSL Work Order Layout **to make it visible on the FSL mobile app.
Tip:
If you have difficulties adding the Flow on the SFS mobile app, click here for more details about how to implement this.
Creation of the Webhook and Apex classes to move images to the newly created record
Setup the SharinPix Webhook
SharinPix Webhooks can be created to capture events such as image uploads to SharinPix. Webhook can also be used to invoke Apex methods to trigger the next actions when events are captured.
Tip:
For more information about Webhook, please refer to the following article: SharinPix Webhooks
In this section, we will:
Create a static method in an Apex class that will use transmitted data and Webhook information obtained from the SharinPix mobile app to move the images uploaded from the Work Order record to the newly-created Case record.
Configure the SharinPix Webhook so that it detects the upload event and makes a call to the static method.
Create a method to move images captured
Note:
The SharinPix Pending Album object is used in this section. It has a field to store image IDs and another field to store the matching Case temporary ID. This is needed if the Case record is created after the image upload. When the Case is created, it fires an Apex Trigger to fetch all stored image IDs from the related Pending Album record and uploads the images to the corresponding Case record.
Use the Apex code below to implement the method that will move the images captured to the newly-created Case record:
Tip:
In the above code snippet, we made use of the SharinPix moveImages method to perform the move operation. For more information on the moveImages , refer to this documentation: Image methods
You can refer to the code snippet below to implement your test class.
Now that our method is ready, we can configure our SharinPix Webhook as explained in the section below.
Configure the SharinPix Webhook
To configure the Webhook, go to the SharinPix Admin Dashboard and follow the instructions below:
From the top menu bar, select Webhooks
Then click on the button **New Webhook **located at the top right corner
Next, enter the Webhook details as indicated below:
For the Action type , choose apex_method
For the Class name , enter the name of the Apex class created above, that is SharinPixMoveImages
For the Method name , enter the name of the method using the transmitted data and Webhook information to move the images, that is, uploadDone
Leave the field **Type **as Webhook::V2
To complete, check the event Upload done. This event is triggered once all images have been uploaded to SharinPix
Click on **Create V2 **when done
Setup the Trigger on Case and Queueable
The SharinPixCase Apex Trigger automatically processes image uploads for new Case records using the SharinPixCaseHandler class. The trigger on the Case object will fire after the creation of a Case record and will initiate the 'move image' operation from the related Pending Album record to the Case record.
The SharinPixCaseHandler class manages image 'move image' operations to Case records by retrieving temporary IDs associated with the Case records. It first collects these temporary IDs, retrieves corresponding _Pending Album _records, and maps them to their IDs. For each Case record, it checks for associated albums, extracts the image IDs, and enqueues a job to transfer these images and delete the temporary Pending Album records.
You can refer to the code snippet below to implement your test class.
The ImageMoveQueueable class is designed to manage the transfer of images to specific Case records in Salesforce asynchronously. It stores image IDs and a Case ID. When launched, it moves the images to the designated Case record. This process is done in the background, allowing other tasks to process without delay.
You can refer to the code snippet below to implement your test class.
We are now all set!
To test this new implementation, go ahead and open the Flow on the Field Service app to create a new Case record and capture images.
Demo: See the Photo Upload and Move in Actions
To test our new implementation:
Open the SFS mobile app
Go on a Work Order record
From the **Show Actions menu, select the option Open a Case ** to launch the Field Service Mobile Flow
Once inside the flow, enter the new Case details and click Next :
Next, click on the link **Click to launch the SharinPix App **to launch the SharinPix mobile app so as to capture photos:
Once back in the Flow, then click on Next again followed by Finish
Now that the Flow is completed, the images captured will be moved to the newly created Case record when the latter becomes available.
Tip:
SharinPix Images can also be added to SFS Service Reports. How more information about how this is done, please refer to the following article:
Display Images in Service Report (Salesforce Field Service / FSL)
Last updated

