gform_salesforce_object_data

Description

Filters the object sent to Salesforce when processing the feed.

Usage

The following would apply to all forms:

add_filter( 'gform_salesforce_object_data', 'your_function_name', 10, 4 );

To target a specific form, append the FORMID to the hook name.

add_filter( 'gform_salesforce_object_data_123', 'your_function_name', 10, 4 );

Parameters

Examples

Set LeadSource before sending to Salesforce for all forms.

// Set LeadSource before sending to Salesforce for all forms
add_filter( 'gform_salesforce_object_data', function( $body, $form, $entry, $feed ) {

    // Log the initial state of the $body before modifications
    gf_salesforce()->log_debug( 'gform_salesforce_object_data: Original Salesforce object data: ' . print_r( $body, true ) );

    // Log form and entry IDs.

    gf_salesforce()->log_debug( 'gform_salesforce_object_data: Processing form ID ' . $form['id'] . ' and entry ID ' . $entry['id'] );
	
    $body['LeadSource'] = 'Website';

    // Log the modified $body before returning it
    gf_salesforce()->log_debug( 'gform_salesforce_object_data: Final Salesforce object data: ' . print_r( $body, true ) );

    // Always return the body
    return $body;

}, 10, 4 );

Add specific reference fields to a specific feed before sending to Salesforce.

add_filter( 'gform_salesforce_object_data', 'salesforce_campaignmember_relationship', 10, 4 );
function salesforce_campaignmember_relationship( $body, $form, $entry, $feed ) {
    //Ensure that this only applies to a specific form.
    if ( $form['id'] != '318' ) {
        return $body;
    }

    //Ensure that this only applies to a specific feed.
    if ( $feed['id'] != '1370' ) {
        return $body;
    }

    //Identify which Salesforce Object Fields the entry field values are mapped into.
    $body['CampaignId'] = rgar( $entry, '28' );
    $body['ContactId'] = rgar( $entry, '32' );

    return $body;
}

This can be very useful when combined with Gravity Flow that provides:
– Response mapping for executing Salesforce feeds as a step
– Ability to control timing/order of steps in it’s workflow.

Example:
You want to have a single form create a Salesforce campaign, contact and then associate that contact as a campaign member, but the relationship field types on the Campaign Member object (campaignId and ContactID) are not available for selecting in the feed settings screen and you need to ensure the data for them exist in the entry before the feed to create the Campaign Member is attempted. Gravity Flow would ensure your feed to create campaign and contact are executed first, and then this snippet would allow you to map their respective IDs into the relationship fields.

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in Gravity Forms Salesforce Add-On version 1.0.

Source Code

This filter is located in class-gf-salesforce.php.