Sales team saves dependent objects in one call

I use WSDL for sales partners using soap api to upload data to salesforce and store it on the SF object. I have two dependent objects that have one search field for the child object

When I store the parent object, I want to save the dependent data of the child objects.

How can I achieve this using a SOAP api.

Thanks in advance.

+4
source share
2 answers

You can do this in SOAP using the external identifier field of the parent type of the object, this will allow you to send the parent and child objects in one call and bind them automatically through the external values ​​of the identifier field.

here's a sample in Java that creates an account and the contact associated with it at a time. the contact is associated with the account through the extId__c field.

public static void main(String[] args) throws Exception { // login to salesforce. PartnerConnection pc = Connector.newConnection(args[0], args[1]); // The new Account record we're going to create. SObject acc = new SObject(); acc.setType("Account"); acc.setField("Name", "My New Account"); acc.setField("extId__c", UUID.randomUUID().toString()); // The new Contact record we're going to create. SObject con = new SObject(); con.setType("Contact"); con.setField("FirstName", "Simon"); con.setField("LastName", "Fell"); // This Account object we build with the relationship to the account above based // on the extId__c field, and then we set it on the contact record // this is the standard FK lookup using ExternalIds feature. SObject parentAcc = new SObject(); parentAcc.setType("Account"); parentAcc.setField("extId__c", acc.getField("extId__c")); con.setField("Account", parentAcc); // Now we can insert both records at once SaveResult [] sr = pc.create(new SObject [] { acc, con} ); printSaveResult("Account result", sr[0]); printSaveResult("Contact result", sr[1]); } private static void printSaveResult(String label, SaveResult sr) { if (sr.isSuccess()) System.out.println(label + " success recordId is " + sr.getId()); else System.out.println(label + " failed, reason is " + sr.getErrors()[0].getMessage()); } 

When I run this, it prints

 Account result success recordId is 0013000001DFMRxAAP Contact result success recordId is 0033000001aEgskAAC 

And when I enter the web application, I can see my new account entry and the contact record with children in the corresponding list. enter image description here

+2
source

You cannot achieve this using the SOAP API, because with this API you will first have to create the main object so that you can get the identifiers for setting the child objects. If you want to create all the objects in one transaction, you need to set the Apex method as a SOAP web service and call it instead.

+1
source

Source: https://habr.com/ru/post/1485434/


All Articles