0

I am working on some code right now to merge Accounts in Salesforce, but when I need to merge accounts I need to have certain fields preserved in case the victim account has something that needs to be merged into the master. i.e. Account A is the master but Account B, the victim, has notes that need to be merged into the master.

I found this link that does give me a starting point.

This was the SOAP API call that I pieced together from that code:

<?xml version="1.0" encoding="utf-8" ?> 
<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" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
    <soapenv:Header> 
        <urn:SessionHeader>
            <urn:sessionId>{session_id}</urn:sessionId>
        </urn:SessionHeader> 
    </soapenv:Header>
    <soapenv:Body> 
        <ns1:merge xmlns:ns1='urn:partner.soap.sforce.com'>
            <ns1:merge>
                <ns1:masterRecord> 
                    <ens:type xmlns:ens='urn:sobject.partner.soap.sforce.com'>Account</ens:type> 
                    <ens:Id xmlns:ens='urn:sobject.partner.soap.sforce.com'>{master_id}</ens:Id>
            <ns1:merge>
                <ns1:masterRecord>    
                    <ens:type xmlns:ens='urn:sobject.partner.soap.sforce.com'>Account</ens:type>    
                    <ens:Id xmlns:ens='urn:sobject.partner.soap.sforce.com'>{master_id}</ens:Id>
                    <ens:{item} xmlns:ens='urn:sobject.partner.soap.sforce.com'>{value}</ens:{item}>
                </ns1:masterRecord>
                <ns1:recordToMergeIds>{victim_id}</ns1:recordToMergeIds> 
            </ns1:merge>
        </ns1:merge>
    </soapenv:Body>
</soapenv:Envelope> 

What I am wondering is if first that this XML is formed correctly. I feel like there is a missing ending tag that should go with the first ns1:merge tag.

The other part is for the {item} and {value} tags. Would I put Note for a Note and the Note ID into the value tag? The article has the actual values, but I don't think that would be the case for what I'm working with.

1 Answer 1

0

Ended up figuring it out on my own after much trial and error:

<?xml version="1.0" encoding="UTF-8"?>
<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:SessionHeader>
            <urn:sessionId>{session_id}</urn:sessionId>
        </urn:SessionHeader> 
    </soapenv:Header>
   <soapenv:Body>
    <ns1:merge xmlns:ns1='urn:partner.soap.sforce.com'>
        <ns1:merge>
            <ns1:masterRecord>
                <ens:type xmlns:ens='urn:sobject.partner.soap.sforce.com'>{type}</ens:type>
                <ens:Id xmlns:ens='urn:sobject.partner.soap.sforce.com'>{master_id}</ens:Id>
            </ns1:masterRecord>
            <ns1:recordToMergeIds>{victim_id}</ns1:recordToMergeIds>             
        </ns1:merge>                                   
    </ns1:merge>  
   </soapenv:Body>
</soapenv:Envelope>

Either I copied the code out of the Python script in the article wrong or there was a missing tag somewhere in the code, but I was able to create a successfull API call with this using Postman.

Hope this helps someone out there since there is very little documentation on how to do a SOAP merge API call in Salesforce.

You must log in to answer this question.

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