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
Miranda L 2Miranda L 2 

error for "recordId": "Class.System.JSON.deserialize

{
    "statusCode": 400,
    "status": "Error",
    "recordReferences": [],
    "errors": [
        {
            "recordId": "Class.System.JSON.deserialize: line 15, column 1\nClass.GlobalWS.processTable: line 33, column 1",
            "errorMessage": "Illegal value for primitive"
        }
    ]
}
please help me
 
EllEll

You'd need to check the "Class.GlobalWS.processTable" class and see what value it is expecting vs what value is being passed by the server/application.
 

This JSON.deserialize error means you're getting an incorrect value for the expected type in the class definition.

For example say you had a class like so:

public class Example {
  public String name;
  public Integer age;
}


But the JSON you were passing was something like:

{
  "name": "Ell",
  "age": "52"
}

You would get the same JSON.deserialise error because it would be expecting an Integer for "age" but instead got a String.
Miranda L 2Miranda L 2
Hi Thank you for your reply , I am having following class which was working fine

at line 33 for class GlobalWS
@HttpPost
        global static WSResponse processTable(){

            WSRequest req = new WSRequest();
            
       req = (WSRequest)JSON.deserialize(RestContext.request.requestBody.toString(), WSRequest.class); 


 if(req.entityName == INVOICE_ENTITY) {
                WSInvoiceRequest invoiceReq = (WSInvoiceRequest) JSON.deserialize(RestContext.request.requestBody.toString(),WSInvoiceRequest.class);
                for(InvoiceWrapperWS Wrapper : InvoiceReq.records){
                    Wrapper.updated_at = invoiceReq.updated_at; 
                }
                InvoiceProcessorWS processor = new InvoiceProcessorWS (InvoiceReq.records);
                WSResponse response = processor.processInvoice();
                if(response.statusCode==200 && !response.recordReferences.isEmpty()) UtilsWS.createDocument(response.status+'_'+response.recordReferences[0].values()+'_'+System.now()+':'+Math.random(),'Req:\n\n'+RestContext.request.requestBody.toString()+'\n\n Response:\n\n'+response, [SELECT ID FROM Folder WHERE Name ='Invoices WS'].id);
                return response;
            }  
      return processGenericSObject(req);
        }

global without sharing class InvoiceWrapperWS {
global InvoiceWrapperWS(){}
public string company_id       = '';
public decimal total = 0;
public string revenue_type       = '';

//I have added additional following field 

 public string[] product_items;
}
I tried with this also getting same error
public list<string>  product_items;
I have done 
and assigning 
private Invoice__c generateInvoice(InvoiceWrapperWS invoiceWrapped) {
        UtilsWS.getUsersMap(new Set<String> {invoiceWrapped.salesperson_reference});        
            Invoice__c I               = new Invoice__c(
            Account__c                 = UtilsWS.getAccountId(invoiceWrapped.company_id),
            Amount__c                  = invoiceWrapped.total,
            RevenueType__c             = invoiceWrapped.revenue_type,
           
           //I tried to Deserialize /serialize But I think its not woking and getting error but if I remove newly added field then I am not getting any error. its working with 
      
            Test_Product_Item__c       = System.JSON.serialize(invoiceWrapped.product_items)
        );
        System.debug('return I*** '+I);
        return I;
    }
Without this field  "product_items":["Dh"] in JSON getting folliwing result 
"statusCode": 200,
    "status": "Success",
    "recordReferences": [
        {
            "Invoice Reference": "d0859bf0-dae3-4b74-b379-1eaf62feb3c9"
        }
    ],
    "errors": []
}


JSON file 
 
{"entityName":"Invoice","records":[{
"company_id":"YKY7EP1K1",
"total":"6050.0",
"revenue_type":"Subscription",
"product_items":["Dh"]
}]
}

could you please suggest
EllEll
I'd suggest a different approach to take, which is deserialize the whole thing first.
If that's the exact JSON you get passed to you then you should only really need something basic like this for your wrapper class:
public class InvoiceClass {
  public String entityName;
  public List<InvoiceItemClass> records;
}

public class InvoiceItemClass {
  public String company_id;
  public Decimal total;
  public String revenue_type;
  public List<String> product_items
}

Then you should deserialize the whole JSON string result as that class:
InvoiceClass result = JSON.deserialize(requestString, InvoiceClass.class);
System.debug(result);

Then you can loop through InvoiceClass.records to create your actual invoice sObjects to insert!