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
Cloud AtlasCloud Atlas 

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...
@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! 
 
Cloud AtlasCloud Atlas
Correct format .... expected in JSON string .... 
USER_DEBUG  "displayName" : "",

Current format being sent to external system ...
USER_DEBUG  "displayName" : "Null",

 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Try this
String displayName;
If(acc.Display_Name__c != null)
displayName = acc.Display_Name__c;
else
displayName = '';

then pass the string in the JSON.
Cloud AtlasCloud Atlas
Thanks enForcer for the response.
But even your code is doing the same thing I did with for loop.
Either way the error persists.. statuscode=500.
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Can you handle it on the receiving end and pass Null in the JSON?
Cloud AtlasCloud Atlas
Haha..
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!!