6

I was able to successfully parse the Partner WSDL in apex and generated apex class.SO what i am trying is to create a sample account record in destination org(Note both orgs are salesforce orgs )

Here is the sample apex class that i am trying to create Account in another salesforce instance

partnerSoapSforceCom.Soap   pc=new partnerSoapSforceCom.Soap ();
partnerSoapSforceCom.LoginResult res=pc.login('[email protected]','salesforce123');
system.debug('***'+res.sessionId);

 //Create a new sObject of type Contact
       // and fill out its fields.
    sobjectPartnerSoapSforceCom.sObject_x acc= new   sobjectPartnerSoapSforceCom.sObject_x();
    acc.type_x='Account';


 // Add this sObject to an array 
    sobjectPartnerSoapSforceCom.SObject_x[] accs = new   sobjectPartnerSoapSforceCom.SObject_x[1];
    accs[0] = acc;

 sobjectPartnerSoapSforceCom.sObject_x[] sbjs=accs;


 partnerSoapSforceCom.SessionHeader_element header=new partnerSoapSforceCom.SessionHeader_element();
 header.sessionId=res.sessionId;
 pc.SessionHeader=header;
 pc.create(sbjs);//Failed 

The class that i am using for sobject is as follow

/Generated by wsdl2apex

public class sobjectPartnerSoapSforceCom {
   public class sObject_x {
    public String type_x;
    public String[] fieldsToNull;
    public String Id;
    private String[] type_x_type_info = new String[]{'type','urn:sobject.partner.soap.sforce.com',null,'1','1','false'};
    private String[] fieldsToNull_type_info = new String[]{'fieldsToNull','urn:sobject.partner.soap.sforce.com',null,'0','-1','true'};
    private String[] Id_type_info = new String[]{'Id','urn:sobject.partner.soap.sforce.com',null,'1','1','true'};
    private String[] apex_schema_type_info = new String[]{'urn:sobject.partner.soap.sforce.com','true','false'};
    private String[] field_order_type_info = new String[]{'type_x','fieldsToNull','Id'};
    }
}

The error i am getting is as follows

19:46:02:475 EXCEPTION_THROWN [1479]|System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService faultcode=UNKNOWN_EXCEPTION faultactor=

I am missing something.Not sure how will i generate the fields using the class above .any help greatly appreciated.

1 Answer 1

3

As the error states, you didn't reset the destination URL. This is accomplished by the following line (after logging in):

pc.endpoint_x = res.serverUrl;
4
  • i have a doubt now how will i include the fields and its value. Dec 20, 2013 at 17:27
  • I mean to create an account in my generated class how will i specify fields of account and its values ? Dec 20, 2013 at 17:33
  • 1
    @MohithKumar Please ask this as a new question so it can receive the appropriate attention.
    – sfdcfox
    Dec 20, 2013 at 17:36
  • alright:).I will do this right Dec 20, 2013 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .