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
Wahid BuhariWahid Buhari 

Rich text area filed - null check

Hi.
I am updating a rich text area field from an Apex class. I would like to have the field to be appended with some value every time the class is called . 
I am using rich_txt_field__c+= rich_text_field__c + some content. since the first time there will not be any value  I am getting null + some value. though I used if(rich_text_field__c !=null), that seems not working. I dont want to get null value on the first time update.
Any views on this?
Best Answer chosen by Wahid Buhari
Wahid BuhariWahid Buhari
@Gaurav I dont know why this approach is not working in my case.
I have used replaceAll method to get rid of the issue,
like 
rich_text__c  += rich_text__c  + value;
rich_text__c  = rich_text__c.replaceAll('null','');

All Answers

GauravGargGauravGarg
Hi Wahid,

Please try this
if (rich_text__c.length() == 0 )
  rich_text__c  = value;
else
  rich_text__c  += rich_text__c  + value;
Let me know if you still face issue. 

Thanks,
Gaurav
Skype: gaurav62990
Wahid BuhariWahid Buhari
@Gaurav I dont know why this approach is not working in my case.
I have used replaceAll method to get rid of the issue,
like 
rich_text__c  += rich_text__c  + value;
rich_text__c  = rich_text__c.replaceAll('null','');
This was selected as the best answer
GauravGargGauravGarg
Yes, this will also resolve your issue. 

Thanks,
Gaurav
Wahid BuhariWahid Buhari
Yes it did.
Thanks.