0

Please find below code

String str = 'Hi {!Contact.FirstName} your phone number is {!Contact.Phone}';

I want to replace the string as follow

String str = 'Hi {!contact.firstName} your phone number is {!contact.phone}';

String is not fix so I can't put hard coded value in the replace and replaceAll functions

Please help .

  • Can you explain more the global probrem? I am understanding that you are sending and email from apex – Torsen Feb 24 '17 at 12:25
  • No need to worry about case, Apex is not case sensitive. So it won't cause any error. – Rohit Mourya Feb 24 '17 at 12:32
  • I am reading body of email from static resource and have to replace {!ContactFirstName } with actual value – Ranjit P Feb 24 '17 at 12:34
  • @RohitMourya str = str.replace('{!contact.name}' , 'Ranjit') this is not working. – Ranjit P Feb 24 '17 at 12:36
  • 1
    str.replace('{!contact.Firstname}' , 'Ranjit') you need to use firstName not name – Tushar Sharma Feb 24 '17 at 13:03
0

First convert your string to lower cap with the below code

str = str.toLowerCase();

then replace the string

str.replace('{!contact.Firstname}' , 'Ranjit')

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.