I am using SOAP API to post leads in salesforce i want leads to be of specific record type but im not getting any option to set the record type of lead.Please Find code below.

package Salesforce_Soap;

import com.sforce.soap.enterprise.Connector;

import com.sforce.soap.enterprise.EnterpriseConnection;

import com.sforce.ws.ConnectionException;

import com.sforce.ws.ConnectorConfig;
import com.sforce.ws.wsdl.Schema;

import com.sforce.ws.wsdl.Schema.*;

import com.sforce.soap.enterprise.sobject.Account;

import com.sforce.soap.enterprise.sobject.Lead;

import com.sforce.soap.enterprise.sobject.Lead.*;
import com.sforce.soap.enterprise.RecordTypeInfo;

import com.sforce.soap.enterprise.QueryResult; 

import com.sforce.soap.enterprise.SaveResult; 

import com.sforce.soap.enterprise.sobject.SObject;

import com.sforce.soap.metadata.RecordType;

public class JavaToSalesforceWebSbx {

     static final String USERNAME = "username";

     static final String PASSWORD = 


     static EnterpriseConnection connection;

     static JavaToSalesforceWebSbx obj;

public static void main(String[] args) {

        obj=new JavaToSalesforceWebSbx();

        ConnectorConfig config = new ConnectorConfig();



        try {

            connection = Connector.newConnection(config);

            System.out.println("Logged in, endpoint: " + 

        } catch (ConnectionException e1) {



        // Create lead 

        try { 
        } catch (Exception e) { 

        // Logout
        try {
            System.out.println("Logged out");
        } catch (ConnectionException ce) {

public void CreateLead() throws ConnectionException
            // Create a new Lead and assign various properties 
            Lead lead = new Lead();

            lead.setCompany("India Inc");          



          /*  QueryResult qr = connection.query("SELECT Id FROM AssignmentRule WHERE Name = 'standard'"); 
            if (qr.getSize() == 0) {
                connection.setAssignmentRuleHeader(null, true);
            } else {
                connection.setAssignmentRuleHeader("01Q28000000e0Ox", false);
            }   */     
            connection.setAssignmentRuleHeader(null, true);

            SaveResult[] sr = connection.create(new SObject[] {lead}); 
            for (int i=0;i<sr.length;i++) { 
                if (sr[i].isSuccess()) {
                    System.out.println("Successfully created lead with id of: " + 
                                       sr[i].getId() + ".");
                } else {
                    System.out.println("Error creating lead: " + 
           // connection.clearAssignmentRuleHeader();

I am notgetting how and where to set the recordtypeid.


Are you sure your Org has RecordType created before generating the Enterprise wsdl. If it is there the wsdl definitely have this RecordTypeId field as mentioned below. If it is not there create the RecordTypes and generate again. Now when you generate the Java Class you will see the setRecordTypeId method.

<complexType name="Lead">
        <extension base="ens:sObject">
                <element name="RecordTypeId" nillable="true" minOccurs="0" type="tns:ID"/>
  • Yes Record types are created for leads. I cross checked but is missing from WSDL so as missing in .jar as well. – Priya Aug 29 '18 at 11:22
  • It might happen that you have generated the wsdl before the RecordTypes are created created. Try to generate the wsdl now and see if you are still not able to see the RecordTypeId field. – Saroj Bera Aug 29 '18 at 11:40
  • It is resolved actually i was adding a jar file of different Salesforce org as reference. – Priya Aug 29 '18 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.