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
weiliang teoweiliang teo 

How do I create account with RecordType -> Corporate using Sforce enterprise wsdl API?

As per topic, how do I create an account with RecordType -> Corporate using Sforce enterprise wsdl?
I am using the latest Enterprise WSDL generated via Setup -> Develop -> API ​-> generate WSDL button.
Is "Volunteer/Individual Donor" a default recordtype in Salesforce?
I can write into Salesforce $sObject->RecordType->Name = "Volunteer/Individual Donor" successfully but for $sObject->RecordType->Name = "Corporate", it always fail to write into Salesforce. Is there any missing step that I have missed out?

Please advise, thanks.
Best Answer chosen by weiliang teo
ArmouryArmoury
Ok.. I will explain the steps to  use the online tool to execute the API request. Let me know the result.(Hope you are comfortable in dealing with XMLs)

Step 1 : Go to the URL http://soapclient.com/soapmsg.html in the browser.
Step 2 : In the 'Server Address' Enter the value https://test.salesforce.com/services/Soap/c/35.0/ and paste the below request in 'SOAP Message' field with the correct username and password and click 'Execute'
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>xxxxxxxxx</urn:username>
         <urn:password>xxxxxxx</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

Step 3 : Copy the 'Server URL' and 'Session Id' from the response.
Step 4 : Go back to the home page again and give the 'Server Address' as the value of 'Server URL' received in Step 3. And paste the below request in 'SOAP Message' field with the <urn:session id> value replaced from Step3 value. Cilck 'Execute'
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>xxxxxxxxxx</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>select Id, Name, Description, DeveloperName, IsActive from RecordType</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

Step 5 : Check in the response whether the 'Corporate' record type is available and the 'IsActive' value is 'True'.
Step 6 : If Step5 is success, then try to create an account record with the below request again. Replace the <Urn:session id> value  from Step3 and <urn:RecordTypeId> value from Step 5.
 
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>xxxxxxxxxxxxxx</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <!--Zero or more repetitions:-->
          <urn:sObjects xsi:type="Account">
		<urn:RecordTypeId>xxxxxxxxxx</urn:RecordTypeId>
		<urn:Name>Theo Walcott</urn:Name>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>


 

All Answers

pconpcon
There are no "default recordtypes" in Salesforce.  You will need to generate all of the Record Types you need.  Just to verify, you do see the Record Type of "Corporate" available when you create the new record via the UI?  Have you tried creating your object and setting the RecordTypeId field to the Id for the Record Type?  Are you getting any errors when you try to do the creation, or does it just not get assigned as expected?
weiliang teoweiliang teo
Hi pcon,
By using the soql query (select id, name from recordType) on Force.com Explorer, I do see the Record Type of "Corporate" available and also available via the UI. Strangely, I can create object directly from the UI of Salesforce but not from the Enterprise WSDL API. To make things complexe, I could actually create object for my "Volunteer/Individual Donor" record type in both Enterprise WSDL API and UI of Salesforce but it just does not work for "Corporate" record type.
 
ArmouryArmoury
The profile which is assigned to you and the api user is different? If Yes, can you check whether the recorrd type is assigned to the API User's profile?
weiliang teoweiliang teo
Hi Sathish Venkat,
​The profile I was assigned to and the API is the same. i.e, I cannot write into "Corporate" recordtype via API call only. I cannot find the reason for that.
ArmouryArmoury
Can you execute this api request and see whether 'Corporate' recordtype is returning in the response. 
Replace the SessionId value with a valid id.
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>xxxx</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>select Id, Name, Description, DeveloperName, IsActive from RecordType</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

 
weiliang teoweiliang teo
Hi Sathish Venkat,
Pardon me for asking, may I know where do I insert the API request into and where do I get my sessionID?
ArmouryArmoury
Hi - Sorry.. I assumed that you are using SoapUI tool for API Account insert scenarios and thats why sent that request. May I know how do you do testing for the API ? I will try to frame the request accordingly..
weiliang teoweiliang teo
Hi Sathish Venkat,
​I'm using the soapclient API which consists of the following
- my_salesforce_enterprise.wsdl
- ProxySettings.php
- SforceBaseClient.php
- SforceEmail.php
- SforceEnterpriseClient.php
- SforceFieldTypes.php
- SforceHeaderOptions.php
- SforceMetadataClient.php
- SforceMetaObject.php
- SforcePartnerClient.php
- SforceProcessRequest.php
When my paypal ipn has been verified, it will call the salesforce API for connection and write into salesforce.
ArmouryArmoury
Ok.. I will explain the steps to  use the online tool to execute the API request. Let me know the result.(Hope you are comfortable in dealing with XMLs)

Step 1 : Go to the URL http://soapclient.com/soapmsg.html in the browser.
Step 2 : In the 'Server Address' Enter the value https://test.salesforce.com/services/Soap/c/35.0/ and paste the below request in 'SOAP Message' field with the correct username and password and click 'Execute'
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>xxxxxxxxx</urn:username>
         <urn:password>xxxxxxx</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

Step 3 : Copy the 'Server URL' and 'Session Id' from the response.
Step 4 : Go back to the home page again and give the 'Server Address' as the value of 'Server URL' received in Step 3. And paste the below request in 'SOAP Message' field with the <urn:session id> value replaced from Step3 value. Cilck 'Execute'
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>xxxxxxxxxx</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>select Id, Name, Description, DeveloperName, IsActive from RecordType</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

Step 5 : Check in the response whether the 'Corporate' record type is available and the 'IsActive' value is 'True'.
Step 6 : If Step5 is success, then try to create an account record with the below request again. Replace the <Urn:session id> value  from Step3 and <urn:RecordTypeId> value from Step 5.
 
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>xxxxxxxxxxxxxx</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:create>
         <!--Zero or more repetitions:-->
          <urn:sObjects xsi:type="Account">
		<urn:RecordTypeId>xxxxxxxxxx</urn:RecordTypeId>
		<urn:Name>Theo Walcott</urn:Name>
         </urn:sObjects>
      </urn:create>
   </soapenv:Body>
</soapenv:Envelope>


 
This was selected as the best answer
weiliang teoweiliang teo
Here is the reflected updates.
For Step 5:
<records xsi:type="sf:RecordType">
  <sf:Id>xxx</sf:Id>
  <sf:Description>To capture corporate lead information</sf:Description>
  <sf:DeveloperName>Corporate</sf:DeveloperName>
  <sf:IsActive>true</sf:IsActive>
  <sf:Name>Corporate</sf:Name>
</records>

<records xsi:type="sf:RecordType">
  <sf:Id>yyy</sf:Id>
  <sf:Description>Corporate donors</sf:Description>
  <sf:DeveloperName>Corporate</sf:DeveloperName>
  <sf:IsActive>true</sf:IsActive>
  <sf:Name>Corporate</sf:Name>
</records>
For Step 6:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com">
  <soapenv:Header>
    <LimitInfoHeader>
      <limitInfo>
        <current>134</current>
        <limit>5000000</limit>
        <type>API REQUESTS</type>
      </limitInfo>
    </LimitInfoHeader>
  </soapenv:Header>
  <soapenv:Body>
    <createResponse>
      <result>
        <id>xxxxx</id>
        <success>true</success>
      </result>
    </createResponse>
  </soapenv:Body>
</soapenv:Envelope>
Is step 5 having conflict?
 
ArmouryArmoury
Yes.. Most likely the Step 5 is causing the problem here.. So we are able to create an Account with 'Corporate' recordtype via api.. So there are no issues in the Salesforce.
Now it looks like the PHP client when querying for the record type id - it is picking up the first 'Corporate'  id and associating it to the 'Account' whereas this id belongs to a different object.
You might have to update your logic in the PHP client to consider the SobjectType field also while picking up the recordtype id. Else you have to rename the recordtype of the other object. You can get the other object info with this query in Step 4.
select Id, Name, Description, DeveloperName, IsActive, SobjectType from RecordType
weiliang teoweiliang teo
Hi Sathish Venkat,
​Thanks for the superb guidance in debugging my issue, and yes. I have change to using RecordTypeID instead of RecordTypeName and it works. I will inform the relevant user about the conflict name. You have been a great help to me! Thanks so much!
weiliang teoweiliang teo
Just to add on to the previous query, is there any way I can check on the id of a custom field? I cannot write into Salesforce via API for a custom field and I suspect there is conflict field names again. Please advise, thanks.
Yashpal GogadayYashpal Gogaday
I was wondering if there was any way of sending Record Type name/Developer name from the Web to Salesforce. Here is an example of what i am trying to do. I know the reason this is failing. Using RecordTypeId will require me to change the id everytime i move environments. Looking for some guidance here.

<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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <urn:SessionHeader>
      <urn:sessionId>00D0q0000001hvg!ARsAQFt2.0dtzRppi1y3hLM7AAm4dj5F1BS1D_5NWmwsYFf4b6bQfVbzVqPdcsVNJWOaMevYNByHSqFuksUNbYrx3L7kYsLb</urn:sessionId>
    </urn:SessionHeader>
  </soapenv:Header>
  <soapenv:Body>
    <urn:create>
    <urn:sObjects xsi:type="urn1:Lead" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <FirstName>SOAP Lead</FirstName>
        <LastName>Test 2</LastName>
        <Channel__c>Web</Channel__c>
        <RecordType>Direct_Sales_Regent</RecordType>          
    </urn:sObjects>
    </urn:create>
  </soapenv:Body>
</soapenv:Envelope>