0

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 = 

"pass";

     static EnterpriseConnection connection;

     static JavaToSalesforceWebSbx obj;



public static void main(String[] args) {

        obj=new JavaToSalesforceWebSbx();

        ConnectorConfig config = new ConnectorConfig();

        config.setUsername(USERNAME);

        config.setPassword(PASSWORD);

        try {

            connection = Connector.newConnection(config);

            System.out.println("Logged in, endpoint: " + 
config.getAuthEndpoint());

        } catch (ConnectionException e1) {

            e1.printStackTrace();

        } 

        // Create lead 

        try { 
            obj.CreateLead(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 

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

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

            lead.setFirstName("Notify"); 
            lead.setLastName("TestEmail_Gmail2"); 
            lead.setCompany("India Inc");          

            lead.setCountry("India");

            //lead.setLeadSource("Web");

          /*  QueryResult qr = connection.query("SELECT Id FROM AssignmentRule WHERE Name = 'standard'"); 
            if (qr.getSize() == 0) {
                connection.setAssignmentRuleHeader(null, true);
            } else {
                System.out.println(qr.getRecords()[0].getId());
                connection.setAssignmentRuleHeader("01Q28000000e0Ox", false);
            }   */     
            connection.setAssignmentRuleHeader(null, true);
            connection.setEmailHeader(false,false,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: " + 
                                       sr[i].getErrors()[0].getMessage());
                }
            }   
           // connection.clearAssignmentRuleHeader();
        }    
}

I am notgetting how and where to set the recordtypeid.

0

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">
    <complexContent>
        <extension base="ens:sObject">
            <sequence>
                ........
                ........
                ........
                <element name="RecordTypeId" nillable="true" minOccurs="0" type="tns:ID"/>
                ........
                ........
                ........
            </sequence>
        </extension>
    </complexContent>
</complexType>
  • 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.