• SFDC Dev1 13
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi Developers

I'm getting below error.
FATAL_ERROR|System.JSONException: N/A at [line:1, column:7280] 
Class.OTBatchUpdate.execute: line 46, column 1

My requirement is 
I wrote a batch class, i'm having HTTP callout, i will be receiving json response, which i need to parse and update my salesforce objects data. Everything is working fine for one or two records, but when i set batch size to 100, i'm getting above error. 
I believe it 's something related to parsing, and  in the response it has some junk data??
Below is the code where it says issue at
List<ParseJson> responseList = (List<ParseJson>)JSON.deserialize(ssss, List<ParseJson>.class);

Below is the code that i have in execute method.
Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setEndpoint('ENDPOINT URL');
            request.setMethod('POST');
            request.setHeader('Content-Type', 'application/json;charset=UTF-8');
            request.setHeader('Accept', 'application/json');
            // Set the body as a JSON object
            request.setBody(s);
            request.setTimeout(60000);
            HttpResponse response = http.send(request);
            // Parse the JSON response
            System.debug(response.getBody());
            string jsonresponse = response.getBody();
            String ssss = jsonresponse.unescapeEcmaScript();
            system.debug(ssss);
            ssss = ssss.substring(1, ssss.length()-1);
            system.debug('response after trimming---->>>>'+ssss);

         //   List<Object> results = (List<Object>)JSON.deserializeUntyped(ssss);
         //   system.debug('results'+results);
        
            List<ParseJson> responseList = (List<ParseJson>)JSON.deserialize(ssss, List<ParseJson>.class);
            system.debug('response is '+responseList);

Any pointers for ths issue?

Thanks​
 
Hello Developers,

I need your pointers for updating data into three objects, Location,Account and Contact. My scenario is, we have to consume 3rd party service and parse the data into three above mentioned objects and this should de done in batches.Records in salesforce will be there, we need to just update the same records with response received from json. So i have written batch class,
1. I was able to consume service, get the response, parse json.
2. I was able to map fields on child object(Location)
3. I'm having difficulties in mapping Account and contact. Can you share some pointers on how to acheive this.
Below is my code for your reference.
global class BatchUpdate implements Database.Batchable<sObject>,Database.AllowsCallouts,Database.Stateful{

   global Database.QueryLocator start(Database.BatchableContext BC){
   String SOQL = 'Select Name from Location__c where name =\'T4375\'';     
      return Database.getQueryLocator(SOQL);
   }
     
   global void execute(Database.BatchableContext BC,List<Sobject> scope){
        String[] otNames = new String[] {};
        string s;
           system.debug('im from Execute');
           for(Sobject lc : scope){           
               for(Location__c loc: [Select Name from Location__c where name = 'T4375']){
                   otNames.add(loc.Name);
                }
                s = String.join(otNames, '|');                      
            } 
 
            system.debug(s);
            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setEndpoint(ENDPOINT URL);
            request.setMethod('POST');
            request.setHeader('Content-Type', 'application/json;charset=UTF-8');
            request.setHeader('Accept', 'application/json');
            // Set the body as a JSON object
            request.setBody(s);
            request.setTimeout(60000);
            HttpResponse response = http.send(request);
            // Parse the JSON response
            System.debug(response.getBody());
            string jsonresponse = response.getBody();
            String ssss = jsonresponse.unescapeEcmaScript();
            system.debug(ssss);
            ssss = ssss.substring(1, ssss.length()-1);
            system.debug('response after trimming---->>>>'+ssss);

            List<Object> results = (List<Object>)JSON.deserializeUntyped(ssss);
            system.debug('results'+results);
        
            List<ParseJson> responseList = (List<ParseJson>)JSON.deserialize(ssss, List<ParseJson>.class);
            system.debug('response is '+responseList);
            
  
            List<location__c> lct = new List<location__c>();
            List<location__c> finallst = Database.query('SELECT Id,Location__c,Account__r.MSD_Code__c FROM location__c WHERE Name = \'OT43757\'');
            
             for(ParseJson lcc:responseList){
                 location__c mylct= new location__c();
                 mylct.location__c=lcc.Address_3;
                 mylct.key__c     =lcc.Key;
                 mylct.Account__r.MSD_Code__c=lcc.Chain_Name_Code ;
                 mylct.id='a090k000001UoAN';
                 finallst.add(mylct);
             }
            map<id,location__c> lccmap = new map<id,location__c>();
            //put all the values from the list to map. 
            lccmap.putall(finallst);
            if(lccmap.size()>0){
            update lccmap.values();
            }
            update finallst;

   }

    

   global void finish(Database.BatchableContext BC){
     system.debug('im from finish');
   }
   

            public class ParseJson {
                public String Key;  // Child object field
                public String No;   // Child object field
                public String Name_Code;  // Parent(Account)
                public String Contact;        // Contact Info
                public String Address; // Parent(Account
                public String Address_A; // Parent(Account
                public String Address_B; // Parent(Account
                public String Post_Code; // Parent(Account
               }

    
            public static List<ParseJson> parse(String ssss) {
               return (List<ParseJson>) System.JSON.deserialize(ssss, List<ParseJson>.class);
            }
        
        
 }

 
Hi 

I have a REST Class exoposed from salesforce is used to create an Account and Contact from a web form elsewhere in the company. 

It was working fine until 2 days ago and now i have the error (in description). 

Can anyone please help me understabd why?

Thanks in Advance
Sri