I am trying to use Line breaks (\n) in return statement. But it doesn't work. \n gets printed in the return statement. I am not using any VF Page. I am trying this in my webservice class.

Below is the method structure.

global static string createNewCase()
    return 'FIELDS :' + '' + response.fields + '/\n' +
        'MESSAGE :' + '' + response.message +
        'STATUS CODE :' + '' + response.statuscode;

I tried by adding '/\n' this also did not work. Please help in how to do this. I tried to search for this. But all I get is the example of VF page and controller where escape=False is specified in controller.

I have tried the code mentioned in the I don't know why '\n' new line is not working link for reference and made changes. Still it is not working.

  • Hi Basti, Thanks for the reply. But this is not the same question that you mentioned. I am not using any VF page. I am trying to return string from a method.
    – sfdcdev
    Commented Nov 13, 2017 at 13:10
  • 2
    FYI you can remove your concatenations of the empty string ('') as they add nothing.
    – Adrian Larson
    Commented Nov 13, 2017 at 13:29
  • @AdrianLarson The concatenations were used for adding whitespace. I will remove them. Yes you are right they add nothing.
    – sfdcdev
    Commented Nov 13, 2017 at 13:40

1 Answer 1


You may use like following:

String str = 'Welcome home'; 
str += '\n';
str += 'salesforce stackExchange';
return str;

Welcome home 
salesforce stackExchange
  • Hi @Prince. I already tried what you have given. But that is not working.
    – sfdcdev
    Commented Nov 14, 2017 at 6:03

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