You need to sign in to do that
Don't have an account?
Nandhini S 3
\n not working in apex
Hi All,
We have an apex class to send out email. There is a string which has the body of the email.
Example:
String str = 'Hi,' + '\n\n'+
'First line of the subject: '+variable1 +'\n'+
'Second line of the subject: '+variable2 +'\n';
This works fine when the value of variable1 is short (first and second line of the string comes in separate lines). If the value of variable1 is a long text then first and second line of the string comes in the same line.
We have an apex class to send out email. There is a string which has the body of the email.
Example:
String str = 'Hi,' + '\n\n'+
'First line of the subject: '+variable1 +'\n'+
'Second line of the subject: '+variable2 +'\n';
This works fine when the value of variable1 is short (first and second line of the string comes in separate lines). If the value of variable1 is a long text then first and second line of the string comes in the same line.
In Apex, the "\n" character is not recognized as a line break in a string. Instead, you can use the "<br/>" HTML tag to create a line break in the email body.
For example: By using the "<br/>" tag, each line will be displayed on a separate line in the email body, regardless of the length of the variable values.
If this helps , please mark this as Best Answer.
Thank you.
I tried using "<br/>" but the tag is just displayed in the email and there is no break in the lines.
Can you try with this :
Hope this helps !
Thank you.