I'm having problems with replace() operations of text that I have in Subject of my Email Template.

Subject is like: A - B - C

My code is:

    EmailTemplate eTemplate = newEmail.searchForEmailTemplate('MyTemplate');
                eTemplate.Subject.replace('A', 'Test1: ' + String.valueOf(Account.Sending__c) + ' ');
                eTemplate.Subject.replace('B', 'Test2: ' + String.valueOf(Account.Stat__c) + ' ');
                eTemplate.Subject.replace('C', 'Test3: ' + String.valueOf(Account.GetMethods__c) + ' ');

System.debug('eTemplate.Subject --> ' + eTemplate.Subject);

But it does not work. Debug prints: A - B - C, so, Subject did not change.


The replace method on String class doesn't modify the String on which is being Called. Instead it would return a new string with the modifications.

Please read more about it here.

enter image description here


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.