Gravity Forms Salesforce Add-on
[resolved] [PATCH][2.1.1] Don't send empty fields to Salesforce (2 posts)

  1. gmcinnes
    Posted 3 years ago #

    It is tempting fate to send empty fields to Salesforce using the SOAP API. It can lead to type errors and extra complexity. This patch filters out empty fields before sending the fields to SalesForce.

    It should apply cleanly to 2.1.1, as long as this previous patch is applied:


    --- salesforce-api.php	2012-11-27 16:41:10.000000000 -0500
    +++ salesforce-api.php.no_empty_merge_vars	2012-11-29 20:11:34.000000000 -0500
    @@ -1424,6 +1424,12 @@
             $merge_vars = array_map(function($merge_var) { return clean_utf8_xml_string($merge_var); }, $merge_vars);
    +	// Don't send merge_vars that are empty. It can cause problems with Salesforce strict typing.  For example,
    +        // if the form has a text field where a number should go, but that number isn't always required, when it's
    +        // not supplied, we don't want to send <var></var> to Salesforce. It might choke because it expects a Double
    +        // data type, not an empty string
    +	$merge_vars = array_filter($merge_vars, function($merge_var) { return strlen($merge_var) > 0; } );
             $account = new SObject();
             $account->fields = $merge_vars;


  2. Zack Katz
    Plugin Contributor

    Posted 3 years ago #

    Thanks! This will be added to the next version.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Gravity Forms Salesforce Add-on
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic