You need to sign in to do that
Don't have an account?

Converting "Null" string in JSON to BLANK
Hello,
I have an apex callout class and a future callout method where I am passing JsonInput of Account fields.
During integration testing, it was requested that any field without any value , should be returned as ' ' <just blank> and not as "Null".
I don't think we can pass ' ' <just blank> in JSON.
But I still gave it a shot and checked blank value before creating json input...
Although the code saved, I am getting an "Internal Server Error, Status Code= 500" everytiime I lauch the callout.
Does any one have an idea how I can make the blank value as ' ' and not as "Null".
Any help is appreciated.
Thanks!
I have an apex callout class and a future callout method where I am passing JsonInput of Account fields.
During integration testing, it was requested that any field without any value , should be returned as ' ' <just blank> and not as "Null".
I don't think we can pass ' ' <just blank> in JSON.
But I still gave it a shot and checked blank value before creating json input...
@InvocableMethod public static void postAccountToSystem(List<Id> acctIds){ Account acc = [SELECT Name,Display_Name__c, Bio_URL__c,Image_URL__c FROM Account WHERE Id = :acctIds[0]]; if(acc.Display_Name__c == NULL){ acc.Display_Name__c = ''; } if(acc.Bio_URL__c == NULL){ acc.Bio_URL__c = ''; } if(acc.Image_URL__c == NULL){ acc.Image_URL__c = ''; } String jsonInput = '{\n' + ' "displayName" : "'+acc.Display_Name__c+'",\n'+ ' "bioUrl" : "'+acc.Bio_URL__c+'",\n'+ ' "imageUrl" : "'+acc.Image_URL__c+'",\n'+ System.enqueueJob(new QueueableCall(jsonInput, acc.Id)); }
Although the code saved, I am getting an "Internal Server Error, Status Code= 500" everytiime I lauch the callout.
Does any one have an idea how I can make the blank value as ' ' and not as "Null".
Any help is appreciated.
Thanks!
Current format being sent to external system ...
then pass the string in the JSON.
But even your code is doing the same thing I did with for loop.
Either way the error persists.. statuscode=500.
Brother you and I just think alike..
I wish I could have shown you my email which I sent an hour ago asking the developers on receving system to ignore fields when I send NULL or MISSING.
Any ways thanks for your help.
Cheers!!