How to insert and delete GroupMember records using Salesforce SOAP API?

How to insert and delete GroupMember records using Salesforce SOAP API?

We can insert and delete GroupMember records using Salesforce SOAP API.

Check the following steps to insert and delete GroupMember records using Salesforce SOAP API.

1. Send Login request to get the Session Id.
Endpoint URL: https://login.salesforce.com/services/Soap/u/54.0

Request Body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
   <soapenv:Header>
      <urn:CallOptions>
         <urn:client>?</urn:client>
         <urn:defaultNamespace>?</urn:defaultNamespace>
      </urn:CallOptions>
      <urn:LoginScopeHeader>
         <urn:organizationId>{YOUR_ORG_ID}</urn:organizationId>
      </urn:LoginScopeHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>{YOUR_USERNAME}</urn:username>
         <urn:password>{YOUR_PASSWORD}</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

2. Send create request to create GroupMember records.
Endpoint: https://{YOUR_DOMAIN}.my.salesforce.com/services/Soap/u/54.0/

Request Body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com" xmlns:urn1="urn:sobject.partner.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>            
          <urn:sessionId>
            {SESSION_ID_FROM_STEP1}
          </urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>      
      <urn:create>
         <urn:sObjects>
            <urn1:type>GroupMember</urn1:type>
            <GroupId>00G8c000006JAVOEA4</GroupId>
            <UserOrGroupId>0058c000007oEERAA2</UserOrGroupId>
         </urn:sObjects>
         <urn:sObjects>
            <urn1:type>GroupMember</urn1:type>
            <GroupId>00G8c000006JAVTEA4</GroupId>
            <UserOrGroupId>0058c000007oEERAA2</UserOrGroupId>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>

3. Send delete request to delete the records.
Endpoint: https://{YOUR_DOMAIN}.my.salesforce.com/services/Soap/u/54.0/

Request Body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">


   <soapenv:Header>
      <urn:SessionHeader>        
          <urn:sessionId>
            {SESSION_ID_FROM_STEP1}
          </urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:delete>
         <urn:ids>0118c000006ELshAAG</urn:ids>
         <urn:ids>0118c000006ELsiAAG</urn:ids>
      </urn:delete>
   </soapenv:Body>
</soapenv:Envelope>

Leave a Reply