Salesforce Record Offline Filters

This guide will explain how to use the offline record filters for Salesforce fields.

The offline record filter is useful when you want to choose available records for offline use based on valid API fields in Salesforce.

Below are examples that illustrate the syntax of a record filter for offline use.

Use-Case 1: Offline record filter based on the merge field

image
( function( result ) {
    // Retrieve the value from formyoula form fields and store it in a descriptive variable
    var form_field_value = formyoula.form_fields[ "2ccf-975e-4ca9" ].get( 'value' );
    // Compare the result name with the form field value and return the comparison result
    return ( result.Name == form_field_value );
} )

Or we can use the short version.

( function( result ) {
    // Compare the result name with the form field value and return the comparison result
    return ( result.Name == '{{2ccf-975e-4ca9}}' );
} )

Use-Case 2: Offline record filter based on a certain account name. It will filter all the records with the account name "test."

( function( result ) {
    // Compare the result name with the test name and return the comparison result
    return ( result.Name == 'test' );
} )

Use-Case 3: Offline record filter based on the account name, type, and other valid API fields

( function( result ) {
    // Define a variable for account ID and assign a value
    var account_id = 1234567890;
    // Define a variable for account number and assign a value
    var account_number = '1234567890';
    // Define a variable to indicate if it is active and set to true
    var is_active = true;
    // Define a variable for type and assign 'Prospect'
    var account_type = "Prospect";
    // Compare result properties with defined variables and return the boolean result
    return ( result.AccountId == account_id && result.AccountNumber == account_number && result.Active__c == is_active && result.Type == account_type );
} )

Use-Case 4: Offline record filter based on Email value equals to the email of the user logged into the Formyoula.

( function( result ) {
    // Compare record email with current user email's email
    return ( result.Email == window.formyoula.form_fields.Formyoula_User_Email );
} );

Similarly, we can create function for other fields. For example, to filter Email = username of the logged in user, we can use the following function

( function( result ) {
    // Compare record email with current user's username
    return ( result.Email == '{{Formyoula_User_Username}}' );
} );

Here is the Json of an example form with various lookups with filters added based on the use case.

OFFLINE RECORD FILTER[GUIDE].json

Note:

For the offline record filter to work correctly in offline mode,

Display Additional field option in the salesforce lookup, "Salesforce select, grid or table should have selected the API field based on which we are filtering the records. For example, if we are filtering the records based on Email = "[email protected]," then Email should be the field selected in the display additional field option, as shown in the image below.

image

For any questions, please contact us - [email protected] or the Formyoula in-app chat 🙂