4

I got introduced to Salesforce just recently and needed to work with their API on a web lead form. I'm a PHP developer, so I'm using PHP toolkit (SOAP API) - some code samples here.

I'm stuck with trying to find a way to bypass the duplicate alert during lead creation. The alert prevents me from creating the record. Turning off the alert is not a feasible option as we still want users inside Salesforce to be "alerted" when they attempt to create a record that the CRM thinks already exists.

I've heard about the DuplicateRuleHeader, but I don't see any documentation on how to use this option using the PHP toolkit. How do we bypass a duplicate alert using this toolkit?

4
  • 2
    Far as I can tell, the PHP Toolkit does not support DuplicateRuleHeader, so you might need to update the source.
    – sfdcfox
    Commented Mar 30, 2017 at 3:20
  • @sfdcfox Thanks for responding. I looked through the library and extending it might be possible. Anyhow, I was digging through the source when my Salesforce administrator informed me that he had setup a new duplicate rule whereby if this certain boolean field (new custom field added to the Lead object) is set to true, then it will bypass the other duplicate rules. So, this option was the quickest one and saved my day!
    – ayandyan
    Commented Mar 30, 2017 at 5:34
  • @IanJohnCaluscusan Hey Ian, have you find a way to accomplish this?
    – odedta
    Commented Jul 4, 2017 at 10:38
  • @odeta The easy way to accomplish it was to add a checkbox field on the Lead named IgnoreDuplicateRule, for example. Then, update your Duplicate Rule condition such that it will only run if IgnoreDuplicateRule == FALSE. When pushing the lead to Salesforce from the PHP API, ensure that this field is TRUE. The other way is to update the PHP Toolkit library yourself by setting the DuplicateRuleHeader. I've went with the easy way for now, though.
    – ayandyan
    Commented Jul 10, 2017 at 3:24

1 Answer 1

1

So I just figured this out.

not pretty

Modification #1: SforceBaseClient.php around line 313 where it is adding all the SOAP headers based on the type of call (create/delete/update/query) I add a new DuplicateRuleHeader for the create call:

// start dtbaker mod
if ($call == "create"){
    // trying to get https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_header_duplicateruleheader.htm working.
    $header = new SoapHeader($this->namespace, 'DuplicateRuleHeader', array (
        'allowSave' => true,
    ));
    if ($header != NULL) {
        array_push($header_array, $header);
    }
}
// end dtbaker mod

Modification #2: manually edit my enterprise.wsdl.xml file

I just searched for every occurrence of MruHeader and added a new identical one for DuplicateRuleHeader

for example:

<element name="DuplicateRuleHeader">
    <complexType>
        <sequence>
            <element name="allowSave" type="xsd:boolean"/>
        </sequence>
    </complexType>
</element>

and

<part element="tns:MruHeader" name="MruHeader"/>
<part element="tns:DuplicateRuleHeader" name="DuplicateRuleHeader"/>

etc.. there were about 3 or 4 places to add this in. And other areas if you wanted to also use this header for updates etc..

Modification #3

make sure WSDL cache is not set, otherwise you'll probably end up with Element {} item invalid at this location errors. ini_set("soap.wsdl_cache_enabled", "0");

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .