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('testorg@developer.com','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.

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;
  • i have a doubt now how will i include the fields and its value. – Mohith Shrivastava Dec 20 '13 at 17:27
  • I mean to create an account in my generated class how will i specify fields of account and its values ? – Mohith Shrivastava Dec 20 '13 at 17:33
  • 1
    @MohithKumar Please ask this as a new question so it can receive the appropriate attention. – sfdcfox Dec 20 '13 at 17:36
  • alright:).I will do this right – Mohith Shrivastava Dec 20 '13 at 17:46

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.