Hi all, I’ve been suggested to post here for some help with this so hopefully someone can help out!
We’ve recently installed the Salesforce Addon to Gravity Forms and, while it works very well and is passing data over correctly, I’ve found frustratingly little information on the field type mappings from GF to Salesforce.
For example, while it’s fairly easy to map things like text or email addresses to corresponding field types in our Salesforce objects, it’s less clear how boolean fields or dates are being handled. When I’ve set up what I thought were boolean fields to send data to Salesforce boolean fields, the entire record has failed to transfer, and I don’t seem to be able to find any sort of error logs to show what’s actually happening behind the scene.
If anyone’s found/created anything documenting the API beyond the three rather basic pages on the existing KB I’d be very interested, thanks!
Mapping to single checkboxes within Salesforce requires a bit of custom code in order to translate the data from Gravity Forms into a boolean value so that the Salesforce API will accept the request. The following snippet is the best solution we’ve seen for handling this.
// convert checkboxes and consent to boolean for Salesforce
add_filter( 'gform_salesforce_field_value', function( $value, $form, $entry, $field_id ) {
$field = GFAPI::get_field( $form, $field_id );
if ( $field instanceof GF_Field_Consent && $value === 'Checked' ) {
gf_salesforce()->log_debug( current_filter() . ": Sending `true` for Consent field {$field_id}." );
return true;
}
if ( $field instanceof GF_Field_Checkbox && ! empty( $value ) && str_contains( rgar( $field, 'cssClass' ), 'send_to_salesforce_as_boolean' ) ) {
gf_salesforce()->log_debug( current_filter() . ": Sending `true` for Checkbox field {$field_id}." );
return true;
}
return $value;
}, 10, 4 );
This snippet will convert any Consent field into boolean when sent to Salesforce and will allow you to send selected checkbox options to Salesforce by adding a custom CSS class of send_to_salesforce_as_boolean within the checkbox field settings. Note: snippet requires PHP 8 or greater.
If you’re looking to map multi-selects or checkboxes into a similar picklist in Salesforce, then you’ll need to also transform the data from comma-separated into the semi-colon-separated format Salesforce is expecting. Something like the following should accomplish that:
Thanks Joshua, that’s really helpful - if I’m understanding right then, booleans on Gravity Forms are currently being transmitted as text, if that’s correct? Is that the case for all the GF fields, that they just send raw text strings?