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
Prasad TangilaPrasad Tangila 

select isnull(field,0) from table in salesforce

Hi,
I want to check the case if some fields have blank or null values, if either of null or blank values then I want to make value as 0 , the sql server query is like this :-  select isnull(field,0) from table ,
can anyone give me soql to the above?..
Thanks in advance
Atul GuptaAtul Gupta
Prasad,
 
// here i'm taking example of Account and its fields
for(Account acc : [select Name, CreatedDate from Account]){
    
    //for text/text area/long text area fiels,
    if(acc.Name == null || acc.Name == ''){
        //do something
    }
    
    //for other fields, you can just check for null
    if(acc.CreatedDate == null){
        //do something
    }

}

 
ManojjenaManojjena
Hi Prasad,
You can  do like belwo so that you wil get only the field null or null value .Here you can check by particular field
 
List<Account> acclIst=[SELECT Field__c FROM Account WHERE Field__c = null OR Field__c = ''];
for(Account ac : accList){
  ac. Field__c=0;
}
try{
  update acclIst;
}catch(DmlException de ){
  System.debug(de);
}
Let me know if it helps !!
Thanks
Manoj