SharinPix Mobile App: Retrieve User Information When Uploading Photos (Developer-Oriented)

circle-info

The SharinPix mobile app uses tokens to authenticate itself and upload photos that can be viewed on Salesforce.

Since the app is built for offline use, the tokens are usually generated beforehand and stored in Salesforce fields on records. Multiple users can also upload photos to a single Salesforce record. As such, the tokens cannot be tied to any specific user to avoid relating the user to all photos uploaded by anyone to the record. Thus, the tokens are "anonymous".

This article demonstrates how to:

  1. Pass the current user's identifier in the URL.

  2. Retrieve them when the photos are uploaded.

  3. Save the user identifier in a custom field on the SharinPix Image record.

circle-exclamation
circle-check

To retrieve the user information in anonymous tokens, you will need to:

Create the Flow

This section demonstrates how to create a Flow that will capture the username of the user opening the SharinPix mobile app to upload photos.

circle-info

Create a Screen 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.

  • Select Screen Flow, then click on Create.

  • Go to the Manager tab and click on New Resource.

    • Resource Type: Variable

    • API Name: Enter recordId

    • Data Type: Text

    • Default Value: {!$GlobalConstant.EmptyString}

    • Availability Outside the Flow: Available for input

    • Click Done

  • To retrieve the current user ID, proceed as follows:

    1. Go to the Manager tab and click on New Resource.

    2. Resource Type: Formula

    3. API Name: UserId

    4. Data Type: Text

    5. In the formula editor, enter the following formula to retrieve the current user ID: {!User.Id}

    6. Click Done

  • Go to the Manager tab again and click on New Resource.

    • Resource Type: Variable

    • API Name: Enter any API name. For this demo, we will use WorkOrderRecord

    • Data Type: Record

    • Object: Work Order

    • Click Done

  • Go to the Elements tab then drag and drop the Get Records element under the Data section onto the blank canvas. For the Get Records element:

    • Label: lookupWorkOrder

    • Object: Work Order

    • Conditions: Id (Field) equals (operator) {!recordId}

    • In the How Many Records to Store, check the Only the first record option

    • In the How to Store Record Data, check the Choose fields and assign variables (advanced) 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

    • Go to the Manager tab and click on New Resource:

      • Resource Type: Variable

      • API Name: Launch_SharinPix_App

      • Data Type: Text

      • Default Value: <a href="sharinpix://upload?token={!WorkOrderRecord.SharinPix_Token__c}&user_id=UserId">Take Pictures</a>

      • Click Done

Create 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.

  • Go to the Manager tab and click on New Resource.

    • Resource Type: Variable

    • API Name: Enter Id

    • Data Type: Text

    • Default Value: {!$GlobalConstant.EmptyString}

    • Availability Outside the Flow: Available for input

    • Click Done

  • To retrieve the current user ID, proceed as follows:

    1. Go to the Manager tab and click on New Resource.

    2. Resource Type: Variable

    3. API Name: Enter UserId

    4. Data Type: Text

    5. Availability Outside the Flow: Available for input

    6. Click Done

  • Go to the Manager tab again and click on New Resource.

    • Resource Type: Variable

    • API Name: Enter any API name. For this demo, we will use WorkOrderRecord

    • Data Type: Record

    • Object: Work Order

    • Click Done

  • Go to the Elements tab then drag and drop the Get Records element under the Data section onto the blank canvas. For the Get Records element:

    • Label: lookupWorkOrder

    • Object: Work Order

    • Conditions: Id (Field) equals (operator) {!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

  • Go to the Manager tab and click on New Resource:

    • Resource Type: Variable

    • API Name: Launch_SharinPix_App

    • Data Type: Text

    • Default Value: <a href="sharinpix://upload?token={!WorkOrderRecord.SharinPix_Token__c}&user_id=UserId">Take Pictures</a>

    • Click Done

circle-check

Create the Apex Class

circle-exclamation

Next, create an Apex class to will retrieve the user information passed to the user_id parameter and save the value in the custom field on the related SharinPix Image record.

Here's the sample code for the Apex class:

The Apex test class is as follows:

Create the SharinPix Webhook

For this implementation to work, you will need either a SharinPix Webhook of type** Upload Done** or New Image.

To verify your Webhook settings, go to the SharinPix Administration Dashboard, then click on Webhooks.

The Webhook settings should be as follows:

  • Action type: apex_method

  • Class name: sharinpix.ImageSyncMigration

  • Method name: synchronize

  • The Webhook should be either of type Upload Done or New Image

If no Webhook has been created for your organization, create one as indicated above.

circle-check

DEMO: How to test your implementation?

To test your implementation:

  1. Open the newly-created Flow on the Salesforce or Field Service mobile app.

  2. Tap on the SharinPix deeplink (i.e., the link to the SharinPix mobile app) added to the Flow.

  3. Capture and upload photos.

  4. Open the related SharinPix Image record created for any newly-uploaded photo.

  5. Verify that the Uploaded By field is populated with the username of the user who uploaded the photos:

Last updated

Was this helpful?