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
ALAL 

Inserting records from SOAP API callout

Hello, I have a SOAP callout to an external webservice and I'd like to retrieve the records from the external service and insert them into Salesforce. If I query on a specific record from the external system, I can insert that record into Salesforce. However when I query on multiple records, they're not being inserted into SF. I tried creating a while loop and adding the records to a list and then insert the list, but that hasn't worked. Any help would be appreciated. Thank you.
 
public class ListOutboundFax {
    
      public static void getListOutBoundRecords(Integer customerId ){     
        Concord__c con = new Concord__c();
        List<Concord__c> lstConcord = new  List<Concord__c>();
        
        accountmanagementreportingwebservice.AccountManagementReportingWebserviceSoap s= new accountmanagementreportingwebservice.AccountManagementReportingWebserviceSoap();
        accountmanagementreportingwebservice.ListOutboundActivityRequest  req = new accountmanagementreportingwebservice.ListOutboundActivityRequest();
        accountmanagementreportingwebservice.ListOutboundActivityResponse res = new accountmanagementreportingwebservice.ListOutboundActivityResponse();
        accountmanagementreportingwebservice.Authentication a =new accountmanagementreportingwebservice.Authentication();
        accountmanagementreportingwebservice.ArrayOfString filter = new accountmanagementreportingwebservice.ArrayOfString();
        accountmanagementreportingwebservice.Filter filters = new accountmanagementreportingwebservice.Filter();
        
                   
        a.Username = '-------';
        a.Password = '-------'; 
        req.Authentication = a;
        req.CustomerId = customerId;
        req.EndDate = date.valueOf('2019-11-12T06:03:15-08:00');
        req.ExcludeSubLevelEntries = Boolean.valueOf('true');
        req.PageIndex = 0;
        req.PageSize = 100;
        req.SortOption = 0;
        req.StartDate = date.valueOf('2019-11-11T06:03:15-08:00');
        
        res = s.ListOutboundActivity(req);
        String jsonResponse = (JSON.serializePretty(res));
    
        System.debug(jsonResponse);
   Integer count = 0;     
   JSONParser parser = JSON.createParser(jsonResponse);
          while(parser.nextToken() != null && count < lstConcord.size()){
              if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
               parser.nextValue();
                if(parser.getCurrentName() == 'id') {
                   con.JOB_ID__c = parser.getText(); 
    //               System.debug(con.Name);
                }
                  
                 else if(parser.getCurrentName() == 'dur'){
                            con.Duration__c = Integer.valueOf(parser.getText());
    //                        System.debug(con.Duration__c);

                        }
                        
                        else if(parser.getCurrentName() == 'pgct'){
                            con.Delivered_Pages__c = Integer.valueOf(parser.getText());
    //                        System.debug(con.Delivered_Pages__c);
                        }
                        
                        else if(parser.getCurrentName() == 'dt'){
                            con.Stop_Date__c = Date.valueOf(parser.getText());
  //                          System.debug(con.Stop_Date__c);
                        }
                        
                        else if(parser.getCurrentName() == 'FaxNumber'){
                            con.Fax__c = parser.getText();
 //                           System.debug(con.Fax__c);
                        }  
                  
                   else if(parser.getCurrentName() == 'fcc'){
                            con.Sender_Country__c = parser.getText();
   //                         System.debug(con.Sender_Country__c);
                        } 
                  
                  else if(parser.getCurrentName() == 'cid'){
                            con.Concord_Account_ID__c = parser.getText();
    //                        System.debug(con.Concord_Account_ID__c);
                        } 
                  

                  lstConcord.add(con);
                  System.debug('Size of List' + lstConcord.size());
              }  
              
              System.debug('Size of List' + lstConcord.size());
              count++;
              
              
          }
  
                        if(lstConcord.size() > 0 ){
            try{
                
                insert lstConcord;
            }
            
            catch(Exception ex){
                System.debug(ex);
            }
        }
          
          
          
              }
          }

 
KrishnaAvvaKrishnaAvva
Hi AL,

Can you please elaborate on "not inserted". Is it throwing an error? Is the list empty or there is an exception?:
ALAL
Hi Krishna, when I try using execute anonymous, it doesn't throw an error. The debug statement actually shows records being added to a list, but when I go to do an insert on that list, the records aren't being created in the system.