0

I have a field called description which tracks all the changes made to "Add to Description" field.

When the description field is blank and any new value is entered into Add to Description field, I can also see "null" value in the description field.

Below is my code snippet:

if (String.isEmpty(newCaseIssue.Add_To_Description__c)) {} else {

            newCaseIssue.Description__c = newCaseIssue.Description__c + '\n\n' + strUserName + ' Date/Time of Addition: ' + DateTime.now().format() + '\n' + newCaseIssue.Add_To_Description__c;
            newCaseIssue.Add_To_Description__c = '';
        }

Can anyone please suggest the changes to the above code so that I can exclude the null term from description on first update of the record.

1 Answer 1

0

You can add empty value in your if block-

if (String.isEmpty(newCaseIssue.Add_To_Description__c)) 
{
    newCaseIssue.Add_To_Description__c = '';
} 
else 
{
    String newCaseIssueDescription = newCaseIssue.Description__c == null ? '' : newCaseIssue.Description__c;
    newCaseIssue.Description__c = newCaseIssueDescription +  '\n\n' + strUserName + ' Date/Time of Addition: ' + DateTime.now().format() + '\n' + newCaseIssue.Add_To_Description__c;
    newCaseIssue.Add_To_Description__c = '';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.