0

I have a custom field called Account_from__c which is a text field. Now, I have a Long text field called Warning_Message__c which contains warning messages. The warning message will be like "Account from value cannot be null". This warning message field will contains multiple messages.

Now, if Account_from__c is not null, this particular warning message should be removed.

below is the code snipper:

String s = 'The Account From cannot be blank.';
if(acc.Account_from__c != Null){
                if(acc.Warning_Message__c.contains(s)){
                    acc.Warning_Message__c.replace(s,'');
                }
            }

This logic isnt working as expected. Even when I update the record with Account from value, the message is still in place.

Can anyone please suggest any update to the above code so that i can get this done.

Thanks!

1 Answer 1

0

You forgot to actually update the warning message. Replace does not change the current string but generates a new one.

String s = 'The Account From cannot be blank.';
if(acc.Account_from__c != Null){
    if(acc.Warning_Message__c.contains(s)){
        acc.Warning_Message__c = acc.Warning_Message__c.replace(s,'');
    }
}
1
  • ah...there you go..my bad. Thanks for the update @Phil :)
    – SFDCUser
    Commented Sep 8, 2020 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .