You need to sign in to do that
Don't have an account?
AL
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); } } } }
Can you please elaborate on "not inserted". Is it throwing an error? Is the list empty or there is an exception?: