0

I've spent most of the day going through the SOAP API Developer Guide. I'm successfully making calls to my sandbox via SoapUI client. I've tried a number of SOAP calls, including findDuplicates(), findDuplicatesByIds(), search(), MatchingRule and MatchingRuleItem. I'm just not getting how to satisfy my use case, stated below. I'd really appreciate some direction.

In SFDC, we have a Duplicate Rule with Matching Rule on Account... If Company Name and Shipping Address are both Fuzzy Matches, then we prevent insert.

We currently have an issue where duplicate Accounts are being created in Netsuite.

With SOAP from Netsuite, we hope to be able to call Salesforce with Company Name and Shipping Address... Salesforce would then return a list of fuzzy match records, including ExternalId field.

0

You can perform a SOQL query on the account object using the SOAP API.

To get the records using the External Id field, use the query like below.

SELECT Name FROM Account WHERE ExternalId = 'value'

If you need the fuzzy search you can do it using the below query.

SELECT Name FROM Account WHERE ExternalId LIKE '%value%'

In a similar way, you search for other fields and even combine those conditions.

SELECT Name FROM Account WHERE ExternalId LIKE '%value%' AND CompanyName__c LIKE 
'%value%' AND ShippingCity LIKE '%value%' AND ShippingStreet LIKE '%value%' ...

Soap API Developer Guide
Sample Java and C# code for Query.

1
  • We want to be able to add/change the "matching rules" via Setup anytime in the future, so recreating the matching rules via SOQL doesn't satisfy the need, unfortunately. Aug 11 '20 at 20:36
0

Figured it out, finally! The following returns all records that fit the MatchingRule.

To authenticate, use login() https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm

Also, this trailhead will help you get started with SOAPUI (similar to Postman), which is where I did all the following requests from. https://trailhead.salesforce.com/en/content/learn/modules/api_basics/api_basics_soap

Next, call findDuplicates()

The Request:

https://login.salesforce.com/services/Soap/c/49.0

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:DuplicateRuleHeader>
         <urn:allowSave>false</urn:allowSave>
         <urn:includeRecordDetails>true</urn:includeRecordDetails>
         <urn:runAsCurrentUser>false</urn:runAsCurrentUser>
      </urn:DuplicateRuleHeader>
      <urn:SessionHeader>
         <urn:sessionId>00D2f0000008axL!ARQAQOE5sk9npGl8MiZOReExX80cXMeM4pKDjeXkPa.hWKwoPgYvpxxP2Nhz_YYaEkDOReqmeX415SSTgXLyi6KoydhEJgdi</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:findDuplicates>
         <!--Zero or more repetitions:-->
         <urn:sObjects xsi:type="urn1:Account" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <Name>RyanTest2</Name>
           <Company_Name__c>RyanTest2</Company_Name__c>
           <Description>Some description</Description>
           <ShippingStreet>91 Sycamore Cir</ShippingStreet>
           <ShippingCity>San Francisco</ShippingCity>
           <In_Active__c>No</In_Active__c>
         </urn:sObjects>
      </urn:findDuplicates>
   </soapenv:Body>
</soapenv:Envelope>

The Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:sf="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <LimitInfoHeader>
         <limitInfo>
            <current>80738</current>
            <limit>5000000</limit>
            <type>API REQUESTS</type>
         </limitInfo>
      </LimitInfoHeader>
   </soapenv:Header>
   <soapenv:Body>
      <findDuplicatesResponse>
         <result>
            <duplicateResults>
               <allowSave>false</allowSave>
               <duplicateRule>Accounts_Duplicates</duplicateRule>
               <duplicateRuleEntityType>Account</duplicateRuleEntityType>
               <errorMessage>Use one of these records?</errorMessage>
               <matchResults>
                  <entityType>Account</entityType>
                  <matchEngine>FuzzyMatchEngine</matchEngine>
                  <matchRecords>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>In_Active__c</name>
                     </fieldDiffs>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>Company_Name__c</name>
                     </fieldDiffs>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>ShippingStreet</name>
                     </fieldDiffs>
                     <matchConfidence>100.0</matchConfidence>
                     <record xsi:type="sf:Account">
                        <sf:Id>0012f00000WgADrAAN</sf:Id>
                        <sf:Name>RyanTest2</sf:Name>
                        <sf:Owner xsi:type="sf:User">
                           <sf:Id>0052f0000017uByAAI</sf:Id>
                           <sf:Name>Ryan McNeely</sf:Name>
                        </sf:Owner>
                     </record>
                  </matchRecords>
                  <matchRecords>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>In_Active__c</name>
                     </fieldDiffs>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>Company_Name__c</name>
                     </fieldDiffs>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>ShippingStreet</name>
                     </fieldDiffs>
                     <matchConfidence>100.0</matchConfidence>
                     <record xsi:type="sf:Account">
                        <sf:Id>0012f00000WgAHeAAN</sf:Id>
                        <sf:Name>RyanTest2</sf:Name>
                        <sf:Owner xsi:type="sf:User">
                           <sf:Id>0052f0000017uByAAI</sf:Id>
                           <sf:Name>Ryan McNeely</sf:Name>
                        </sf:Owner>
                     </record>
                  </matchRecords>
                  <matchRecords>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>In_Active__c</name>
                     </fieldDiffs>
                     <fieldDiffs>
                        <difference>DIFFERENT</difference>
                        <name>Company_Name__c</name>
                     </fieldDiffs>
                     <fieldDiffs>
                        <difference>SAME</difference>
                        <name>ShippingStreet</name>
                     </fieldDiffs>
                     <matchConfidence>99.0</matchConfidence>
                     <record xsi:type="sf:Account">
                        <sf:Id>0012f00000WgAHfAAN</sf:Id>
                        <sf:Name>RyanTest3</sf:Name>
                        <sf:Owner xsi:type="sf:User">
                           <sf:Id>0052f0000017uByAAI</sf:Id>
                           <sf:Name>Ryan McNeely</sf:Name>
                        </sf:Owner>
                     </record>
                  </matchRecords>
                  <rule>Accounts_Duplicates</rule>
                  <size>3</size>
                  <success>true</success>
               </matchResults>
            </duplicateResults>
            <success>true</success>
         </result>
      </findDuplicatesResponse>
   </soapenv:Body>
</soapenv:Envelope>

Also, now you have the Salesforce ID for any duplicate records. You can use query() to get any further info about the records. https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_search.htm?search_text=searc

Request https://login.salesforce.com/services/Soap/c/49.0

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>00D2f0000008axL!ARQAQOE5sk9npGl8MiZOReExX80cXMeM4pKDjeXkPa.hWKwoPgYvpxxP2Nhz_YYaEkDOReqmeX415SSTgXLyi6KoydhEJgdi</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>select NS_Account_Ext_Id__c 
         from account 
         where id in ('<sf:Id>','<sf:Id>','<sf:Id>')
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <LimitInfoHeader>
         <limitInfo>
            <current>78321</current>
            <limit>5000000</limit>
            <type>API REQUESTS</type>
         </limitInfo>
      </LimitInfoHeader>
   </soapenv:Header>
   <soapenv:Body>
      <queryResponse>
         <result>
            <done>true</done>
            <queryLocator xsi:nil="true"/>
            <records xsi:type="sf:Account">
               <sf:Id xsi:nil="true"/>
               <sf:NS_Account_Ext_Id__c>NS123</sf:NS_Account_Ext_Id__c>
            </records>
            <records xsi:type="sf:Account">
               <sf:Id xsi:nil="true"/>
               <sf:NS_Account_Ext_Id__c>NS124</sf:NS_Account_Ext_Id__c>
            </records>
            <records xsi:type="sf:Account">
               <sf:Id xsi:nil="true"/>
               <sf:NS_Account_Ext_Id__c>NS125</sf:NS_Account_Ext_Id__c>
            </records>
            <size>3</size>
         </result>
      </queryResponse>
   </soapenv:Body>
</soapenv:Envelope>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.