function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DbjensenDbjensen 

Can you include multiple objects in a payload?

Hello - I have a webservice class that creates Accounts and Contacts. I am testing using Postman. When I include both Accounts and Contacts in a payload, I get the error message 'Only one operation within the same request is allowed.' 

Does this mean I can only include one object in a payload? 
 
<tes:inputAccount>
          <tes:accountArray>                                     <tes:Name>Charles</tes:Name>                              <tes:BillingStreet>121 Test RD</tes:BillingStreet>   ​                                   <tes:BillingCity>PHOENIX</tes:BillingCity>​                                  <tes:BillingState>AZ</tes:BillingState>​                                <tes:BillingPostalCode>65906</tes:BillingPostalCode> 
          </tes:accountArray>
      </tes:inputAccount>


<tes:inputContact>
          <tes:contactArray>
                                           <tes:FirstName>Ray</tes:FirstName>                               <tes:LastName>Charles</tes:LastName>                                       <tes:MailingStreet>121 Test RD</tes:MailingStreet>                                        <tes:MailingCity>PHOENIX</tes:MailingCity>                                 <tes:MailingState>AZ</tes:MailingState>                                 <tes:MailingPostalCode>60906</tes:MailingPostalCode> 
         </tes:contactArray>
      </tes:inputContact>

 
SwethaSwetha (Salesforce Developers) 
HI Dbjensen,
You might want to try the approach suggested in 
https://salesforce.stackexchange.com/questions/224347/can-i-create-records-across-multiple-objects-related-to-each-other-using-salesfo according to which,

The "composite" resource allows you to both:
Execute multiple subrequests as part of a single top-level request
Reference data from previous requests in a subsequent subrequests

The url you'd use to make a composite request is https://<your instance here>.salesforce.com/services/data/<api version>/composite/

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
AnudeepAnudeep (Salesforce Developers) 
Yes it possible

Here is an example from the documentation
 
<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>[sessionId retrieved from the login() call]</urn:sessionId>
    </urn:SessionHeader>
  </soapenv:Header>
  <soapenv:Body>
    <urn:create>
      <urn:sObjects xsi:type="urn1:Account">
        <Name>Sample Account Two</Name>
        <!-- Siebel_Id__c is the External Id field present on Account object -->
        <Siebel_Id__c>1-HR68E</Siebel_Id__c>
      </urn:sObjects>
      <urn:sObjects xsi:type="urn1:Contact">
        <FirstName>Anupam</FirstName>
        <LastName>Rastogi</LastName>
        <urn1:Account>
          <Siebel_Id__c>1-HR68E</Siebel_Id__c>
        </urn1:Account>
      </urn:sObjects>
    </urn:create>
  </soapenv:Body>
</soapenv:Envelope>

Also, a similar question is discussed here

Let me know if it helps
DbjensenDbjensen
Thanks for this helpful info. One more question. If my DML insert for the contact and account are in separate methods, within the same class, can I include both methods in the body? (So I'm sending 1 payload with 2 methods?)