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
Vigneshwaran LoganathanVigneshwaran Loganathan 

FATAL_ERROR System.JSONException: Malformed JSON: Expected '{' at the beginning of object

@future(callout=true)
       public static void ListCallAllowanceBalanceRequest()
      {  
		accx=[Select id,Name,Billing_Date__c,AccountNumber__c,Client_ID__c,Start_Date__c,End_Date__c,Bill_Hold__c,Bill_Talk__c,Bill_Transfer__c,Bill_Ring__c,Call_Rounding__c from Account WHERE To_Be_Run_Today__c = 'True'];
        for(Account accy:accx)
        {
        wrap.StartDate=accy.Start_Date__c; 
        wrap.EndDate=accy.End_Date__c; 
        wrap.ClientId=accy.Client_ID__c;
        wrap.BillHold = Boolean.ValueOf(accy.Bill_Hold__c);
        system.debug('****billhold****'+wrap.BillHold);
        wrap.BillTalk = Boolean.ValueOf(accy.Bill_Talk__c);
        wrap.BillTransfer= Boolean.ValueOf(accy.Bill_Transfer__c);
        wrap.BillRing = Boolean.ValueOf(accy.Bill_Ring__c);
        wrap.RoundCalls = accy.Call_Rounding__c;
        wrap.CustomerName= autx.Customer_Name__c;
        wrap.UserName = autx.User_Name__c;
        wrap.Password = autx.Password__c;
        String jsonBody = json.serialize(wrap);
        system.debug(jsonBody);
        HttpResponse res;
        HttpRequest req = new HttpRequest();
        req.setEndPoint('https://telassistant.hostedsuite.com/api/json/reply/ListCallAllowanceBalanceRequest'); 
        req.setMethod('POST');
        req.setHeader('Content-Type','application/json');
        req.setBody(jsonBody);
        Http http_req = new Http();
        res = http_req.send(req);
        System.Debug(res.toString());
         try 
        {
            res = http_req.send(req);
            System.debug('>>>>>res'+res.getBody());
            string httpresp = res.getBody();
         deserialize1 qw= new deserialize1();
         qw=(deserialize1)JSON.deserialize(httpresp,deserialize1.class);
         system.debug('***userid***' + qw.NumCalls);
         listacc1.Num_calls__c =qw.NumCalls;
         kk.add(listacc1);
         system.debug('NumCalls'+listacc1.Num_calls__c);
        }
        catch(System.CalloutException e) 
        {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }
           update kk;
      }
     }

public class deserialize1
       {
             public boolean Authenticated {get; set;}
             public string UserType {get; set;}
             public string body  {get; set;}  
             public string Name {get; set;}  
             public string CompanyName {get; set;}
             public string userId {get; set;}  
             public string ClientId {get; set;}  
             public string PhotoUrl {get; set;} 
             public Integer NumCalls{get; set;} 
       }


Hi,
I have written a call out function like above. It shows the following Error in debug log

Any help? What does it mean?

Thanks frnz.
KaranrajKaranraj
Vigneshwaran - Where you declared the variable 'wrap' in your class? Try initating the variable inside the for loop. Because the wrap variable values are not reset when the for loop goes for the second time, so its try to serialize the json string with old value also.
 
Vigneshwaran LoganathanVigneshwaran Loganathan
Hi karan,

Thanks for the Reply :)

Actually here is the the code. I have modified with ur suggestion but still same,
 
@future(callout=true)
       public static void ListCallAllowanceBalanceRequest()
      {  
        account listacc1=new account(); 
        list<Account> accx=new list<account>(); 
         list<Account> kk=new list<account>(); 
       // hosted wrap = new hosted();  
        Authentication__c autx=new Authentication__C();
        integer count=[select count() from Account WHERE To_Be_Run_Today__c = 'True'];
        integer a2=[select count() from Authentication__C where Enable__c='TRUE'];
               if(count > 0)
        {
        if(a2==1)
          {
          autx=[select Customer_Name__c,Password__c,User_Name__c from Authentication__C where Enable__c='TRUE'];
        accx=[Select id,Name,Billing_Date__c,AccountNumber__c,Client_ID__c,Start_Date__c,End_Date__c,Bill_Hold__c,Bill_Talk__c,Bill_Transfer__c,Bill_Ring__c,Call_Rounding__c from Account WHERE To_Be_Run_Today__c = 'True'];
        for(Account accy:accx)
        {
        hosted wrap = new hosted();
        wrap.StartDate=accy.Start_Date__c; 
        wrap.EndDate=accy.End_Date__c;  // other things as previous
What is the mistake I am doing here?

Thank you so much :)