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
balakrishna mandula 6balakrishna mandula 6 

How to Change SOAP API to Bulk API

I have done integration using SOAP API, from on SF org to another Org. I have coded one class in first Org1 to insert opportunity record as follows.
  //Webservices SFDC to SFDC
global class WsdlOpportunityCls{
  webService static void InsertOptRecord(String name,String Description){
    Opportunity op = new Opportunity();
    op.name = Name;
    op.Description= Description;
    op.StageName = 'Qualification';
    op.CloseDate = Date.today();
   
    insert op; 
 
  }

}

I have generated wsdl file for this class and partner wsdl of this org.

And I have parsed these two wsdls in another org to integrate. I successfully inserted records into Org2 when I try to insert records from Org2 thru SOAP API.

Below class to invoke the webservice method of above class.

public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){
 
     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];
   
     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');
    
     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;
    
    // for( Opportunity oppt : oppRec){
      // obj.InsertOptRecord ( oppt.Name, oppt.Description);
    // }         
   
    for(opportunity opt :oppRec ) {
      obj.InsertOptRecord(opt.name, opt.description);
    }
   
         
 
  }
}

Trigger to invoke Source_Opportuinity_Class

trigger Oppt_to_Invoke_toIntegrate on Opportunity (after insert, after update) {
   List<id> listid = new List<Id>();
   for(Opportunity oppt : Trigger.new){
      listId.add(oppt.id);
   }
   Source_Opportuinity_Class.Source_Invoke_Opt_Method(listid);

}

When I try to create records in Org2 those records are being loaded into Org1 using SOAP API.

My requirement is to use Bulk API to load large amount of data.

Please help me how to do Bulk API?

Regards,
Balakrishna

Best Answer chosen by balakrishna mandula 6
Tony TannousTony Tannous
Hello,

Replace the object OppObject with the below :

global class OppObject
  {
    webservice string Name{get;set;}
    webservice  string Description{get;set;}
  }

then generate the wsdl again and do the import in the org.

and use this code :


public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){

     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];

     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');

     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;


list<Target_Oppty_WSDL_Bulk.OppObject> listToInsertOpp = new  list<Target_Oppty_WSDL_Bulk.OppObject>


for(Opportunity opp : oppRec )
{
Target_Oppty_WSDL_Bulk .OppObject oppObj= new Target_Oppty_WSDL_Bulk.OppObject();
oppObj.Name=opp.Name;
oppObj.Description=opp.Description;
listToInsertOpp .add(oppObj);
}
    obj.InsertOptRecord(listToInsertOpp );

  }
}

Regards


All Answers

Tony TannousTony Tannous
Hello,

you can do the below changes in the web service method 

global class WsdlOpportunityCls{
  webService static void InsertOptRecord( list<Opportunity> listOpportunity)
{
//String name,String Description)
list<Opportunity> listOppToInsert = new list<Opportunity>();
    for(Opportunity opp :listOpportunity)
{
    Opportunity op = new Opportunity();
    op.name = opp.Name;
    op.Description= opp.Description;
    op.StageName = 'Qualification';
    op.CloseDate = Date.today();
    listOppToInsert.add(op);
}  
  insert  listOppToInsert;

  }

}

and here you change the way of calling 

public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){

     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];
  
     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');
   
     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;
   

      obj.InsertOptRecord(oppRec);
  
        

  }
}

Good Luck

balakrishna mandula 6balakrishna mandula 6
Hi Tony,

The above WsdlOpportunityCls is being parsed successfully but when I am trying to click on Generate apex code button the follwing error is coming

Apex Generation Failed
Unable to find complexType for {http://soap.sforce.com/schemas/class/WsdlOpportunityCls}address


could you please solve this?

Regards,
Balu
Tony TannousTony Tannous
Hi Balu,

try the below instead :


 global class WsdlOpportunityCls{
  webService static void InsertOptRecord( list<OppObject> listOpportunity)
{
//String name,String Description)
list<Opportunity> listOppToInsert = new list<Opportunity>();
    for(OppObject oppObj :listOpportunity)
{
    Opportunity op = new Opportunity();
    op.name = oppObj.Name;
    op.Description= oppObj .Description;
    op.StageName = 'Qualification';
    op.CloseDate = Date.today();
    listOppToInsert.add(op);
}  
  insert  listOppToInsert;

  }

public class OppObject
{

public string Name{get;set;}
public string Description{get;set;}
}

}

and here you change the way of calling 

public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){

     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];
  
     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');
   
     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;
   

list<Target_Oppty_WSDL.WsdlOpportunityCls.OppObject> listToInsertOpp = new  list<Target_Oppty_WSDL.WsdlOpportunityCls.OppObject>
  

foreach(Opportunity opp : oppRec )
{
Target_Oppty_WSDL.WsdlOpportunityCls.OppObject oppObj= new Target_Oppty_WSDL.WsdlOpportunityCls.OppObject();
oppObj.Name=opp.Name;
oppObj.Description=opp.Description;
listToInsertOpp .add(oppObj);

}
    obj.InsertOptRecord(listToInsertOpp );
  
        

  }
}


this solution should work .

Regards
balakrishna mandula 6balakrishna mandula 6
Hi Tony,

Thanks for your reply,

I am still getting the error in the calling class while I am savinng

Error: Compile Error: Invalid type: Target_Oppty_WSDL.WsdlOpportunityCls.OppObject at line 22 column 73
Tony TannousTony Tannous
can you post the content of the class Target_Oppty_WSDL??

balakrishna mandula 6balakrishna mandula 6
Hi Tony,

The below is getting error like

Error: Compile Error: Invalid type: Target_Oppty_WSDL.WsdlOpportunityCls.OppObject at line 22 column 73


public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){

     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];
 
     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');
  
     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;
  

list<Target_Oppty_WSDL.WsdlOpportunityCls.OppObject> listToInsertOpp = new  list<Target_Oppty_WSDL.WsdlOpportunityCls.OppObject>
 

for(Opportunity opp : oppRec )
{
Target_Oppty_WSDL.WsdlOpportunityCls.OppObject oppObj= new Target_Oppty_WSDL.WsdlOpportunityCls.OppObject();
oppObj.Name=opp.Name;
oppObj.Description=opp.Description;
listToInsertOpp .add(oppObj);
}
    obj.InsertOptRecord(listToInsertOpp );
 
       

  }
}
Tony TannousTony Tannous
you are getting this error because apparently the Target_Oppty_WSDL.WsdlOpportunityCls.OppObject doesn't exist.

can you share the code of the class Target_Oppty_WSDL and not the code of the class Source_Opportuinity_Class.

regards
balakrishna mandula 6balakrishna mandula 6
The class in target org is:

global class WsdlOpportunityClsBulk{
  webService static void InsertOptRecord( list<OppObject> listOpportunity)
  {

    list<Opportunity> listOppToInsert = new list<Opportunity>();
    for(OppObject oppObj :listOpportunity)
   {
    Opportunity op = new Opportunity();
    op.name = oppObj.Name;
    op.Description= oppObj .Description;
    op.StageName = 'Qualification';
    op.CloseDate = Date.today();
    listOppToInsert.add(op);
   }
   insert  listOppToInsert;

}

global class OppObject
{

  public string Name{get;set;}
  public string Description{get;set;}
}

}



Here I am sending the code of Target_Oppty_WSDL_Bulk :
The generated apex from .wsdl file of WsdlOpportunityClsBulk


public class Target_Oppty_WSDL_Bulk {
    public class LogInfo {
        public String category;
        public String level;
        private String[] category_type_info = new String[]{'category','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] level_type_info = new String[]{'level','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'category','level'};
    }
    public class OppObject {
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{};
    }
    public class AllowFieldTruncationHeader_element {
        public Boolean allowFieldTruncation;
        private String[] allowFieldTruncation_type_info = new String[]{'allowFieldTruncation','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'allowFieldTruncation'};
    }
    public class DebuggingHeader_element {
        public Target_Oppty_WSDL_Bulk.LogInfo[] categories;
        public String debugLevel;
        private String[] categories_type_info = new String[]{'categories','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'0','-1','false'};
        private String[] debugLevel_type_info = new String[]{'debugLevel','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'categories','debugLevel'};
    }
    public class CallOptions_element {
        public String client;
        private String[] client_type_info = new String[]{'client','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'client'};
    }
    public class InsertOptRecord_element {
        public Target_Oppty_WSDL_Bulk.OppObject[] listOpportunity;
        private String[] listOpportunity_type_info = new String[]{'listOpportunity','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'0','-1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'listOpportunity'};
    }
    public class SessionHeader_element {
        public String sessionId;
        private String[] sessionId_type_info = new String[]{'sessionId','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'sessionId'};
    }
    public class DebuggingInfo_element {
        public String debugLog;
        private String[] debugLog_type_info = new String[]{'debugLog','http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{'debugLog'};
    }
    public class InsertOptRecordResponse_element {
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk','true','false'};
        private String[] field_order_type_info = new String[]{};
    }
    public class WsdlOpportunityClsBulk {
        public String endpoint_x = 'https://ap1.salesforce.com/services/Soap/class/WsdlOpportunityClsBulk';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        public Target_Oppty_WSDL_Bulk.AllowFieldTruncationHeader_element AllowFieldTruncationHeader;
        public Target_Oppty_WSDL_Bulk.SessionHeader_element SessionHeader;
        public Target_Oppty_WSDL_Bulk.DebuggingInfo_element DebuggingInfo;
        public Target_Oppty_WSDL_Bulk.DebuggingHeader_element DebuggingHeader;
        public Target_Oppty_WSDL_Bulk.CallOptions_element CallOptions;
        private String AllowFieldTruncationHeader_hns = 'AllowFieldTruncationHeader=http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk';
        private String SessionHeader_hns = 'SessionHeader=http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk';
        private String DebuggingInfo_hns = 'DebuggingInfo=http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk';
        private String DebuggingHeader_hns = 'DebuggingHeader=http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk';
        private String CallOptions_hns = 'CallOptions=http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk';
        private String[] ns_map_type_info = new String[]{'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk', 'Target_Oppty_WSDL_Bulk'};
        public void InsertOptRecord(Target_Oppty_WSDL_Bulk.OppObject[] listOpportunity) {
            Target_Oppty_WSDL_Bulk.InsertOptRecord_element request_x = new Target_Oppty_WSDL_Bulk.InsertOptRecord_element();
            request_x.listOpportunity = listOpportunity;
            Target_Oppty_WSDL_Bulk.InsertOptRecordResponse_element response_x;
            Map<String, Target_Oppty_WSDL_Bulk.InsertOptRecordResponse_element> response_map_x = new Map<String, Target_Oppty_WSDL_Bulk.InsertOptRecordResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',
              'InsertOptRecord',
              'http://soap.sforce.com/schemas/class/WsdlOpportunityClsBulk',
              'InsertOptRecordResponse',
              'Target_Oppty_WSDL_Bulk.InsertOptRecordResponse_element'}
            );
            response_x = response_map_x.get('response_x');
        }
    }
}

The calling class is:

In this class I am getting error Error: Compile Error: Invalid type: Target_Oppty_WSDL.WsdlOpportunityCls.OppObject at line 22 column 73

public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){

     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];

     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');

     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;


list<Target_Oppty_WSDL.WsdlOpportunityCls.OppObject> listToInsertOpp = new  list<Target_Oppty_WSDL.WsdlOpportunityCls.OppObject>


for(Opportunity opp : oppRec )
{
Target_Oppty_WSDL.WsdlOpportunityCls.OppObject oppObj= new Target_Oppty_WSDL.WsdlOpportunityCls.OppObject();
oppObj.Name=opp.Name;
oppObj.Description=opp.Description;
listToInsertOpp .add(oppObj);
}
    obj.InsertOptRecord(listToInsertOpp );

     

  }
}

Could you please do needful.
Tony TannousTony Tannous
Hello,

Replace the object OppObject with the below :

global class OppObject
  {
    webservice string Name{get;set;}
    webservice  string Description{get;set;}
  }

then generate the wsdl again and do the import in the org.

and use this code :


public class Source_Opportuinity_Class{
  @future(callout = true)
  public static void Source_Invoke_Opt_Method(List<Id> listId){

     List<Opportunity> oppRec = new List<Opportunity>();
     oppRec = [Select Name, Description, Account.Name from Opportunity where Id IN : listId];

     Source_Partner_Cls3.Soap obj1 = new Source_Partner_Cls3.Soap();
     Source_Partner_Cls3.LoginResult lres = obj1.login( 'balakrishna.mandula@birlasoft.com', 'Jason123@vXoMT8HKsuG25xVuQDK4msfc');

     Target_Oppty_WSDL.WsdlOpportunityCls obj = new Target_Oppty_WSDL.WsdlOpportunityCls();
     obj.sessionHeader = new Target_Oppty_WSDL.sessionHeader_element();
     obj.sessionHeader.sessionId = lres.sessionId;


list<Target_Oppty_WSDL_Bulk.OppObject> listToInsertOpp = new  list<Target_Oppty_WSDL_Bulk.OppObject>


for(Opportunity opp : oppRec )
{
Target_Oppty_WSDL_Bulk .OppObject oppObj= new Target_Oppty_WSDL_Bulk.OppObject();
oppObj.Name=opp.Name;
oppObj.Description=opp.Description;
listToInsertOpp .add(oppObj);
}
    obj.InsertOptRecord(listToInsertOpp );

  }
}

Regards


This was selected as the best answer
balakrishna mandula 6balakrishna mandula 6
 Thanks a ton Tony!!!  It's working fine.   :)