kvrsfdc / sfdc-wsc

Automatically exported from code.google.com/p/sfdc-wsc
0 stars 0 forks source link

Using Oracle Data with WSC-22.jar #48

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello, I'm wanting to push some Oracle data to a SalesForce custom object and 
I'm not sure how to do the SaveResults[] with a single call.  Hereafter is a 
code snippet from my class. Any example on how to accomplish this would be 
appreciated.

// Here I get the data from Oracle
   stmt = connMkt.createStatement();
   rs = stmt.executeQuery("SELECT * FROM MKT_RIGTL_STAGE");

 // Here I instantiate the existing  SalesForce custom object
   SObject rtl = new SObject();                        
   rtl.setType("Rig_Timeline__c");   

 // Here I populate the SObject with data from Oracle
 // I want to add 100 records to SObject rtl and do a Single SaveResult after the while loop how can I accomplish this?

   while(rs.next()) {
    rtl.setField("Award_Rate__c", rs.getString("Award_Rate"));
    rtl.setField("End_Date__c", rs.getString("End_Date"));
    rtl.setField("HDR_Common_Name__c", rs.getString("Hdr_Common_Name"));
    rtl.setField("Options__c", rs.getString("Options"));    
    rtl.setField("Rig_Code__c", rs.getString("Rig_Code"));    
    rtl.setField("Rig_Name__c", rs.getString("Rig_Name"));    
    rtl.setField("SEG_Common_Name__c", rs.getString("Seg_Common_Name"));    
    rtl.setField("Start_Date__c", rs.getString("Start_Date"));    
   }

    SaveResult[] results = conn.create(new SObject[] { rtl });  

Original issue reported on code.google.com by Bart.Dew...@gmail.com on 12 Jan 2012 at 5:41

GoogleCodeExporter commented 9 years ago
// Here I populate the SObject with data from Oracle
// I want to add 100 records to SObject rtl and do a Single SaveResult
// after the while loop how can I accomplish this?
List<SObject> records = new ArrayList<SObject>(100);
while (rs.next()) {
    // Here I instantiate the existing SalesForce custom object
    SObject rtl = new SObject();
    rtl.setType("Rig_Timeline__c");

    rtl.setField("Award_Rate__c", rs.getString("Award_Rate"));
    rtl.setField("End_Date__c", rs.getString("End_Date"));
    rtl.setField("HDR_Common_Name__c", rs.getString("Hdr_Common_Name"));
    rtl.setField("Options__c", rs.getString("Options"));
    rtl.setField("Rig_Code__c", rs.getString("Rig_Code"));
    rtl.setField("Rig_Name__c", rs.getString("Rig_Name"));
    rtl.setField("SEG_Common_Name__c", rs.getString("Seg_Common_Name"));
    rtl.setField("Start_Date__c", rs.getString("Start_Date"));

    // Here I add the record to the list...
    records.add(rtl);
}
// Here I create the objects in Salesforce
SaveResult[] results = conn.create(records.toArray(new 
SObject[records.size()]));
// Here I check the results...
for (int i = 0; i < results.length; i++) {
    SaveResult saveResult = results[i];
    // you insert proper code here
}

Cheers

Jesper Udby

Original comment by jesperudby on 2 Feb 2013 at 11:36