3

I am have trouble with line breaks and string literals:

I cannot get the below to compile:

newD.Additional_Information__c = recTypeName +  '\r\n\r\n' 
                            + recTypeName == 'Data Request' ? rq.Reason_for_data_request__c :  rq.Reason_for_mailshot__c + ' \r\n'
                            + '\r\n\' + 'Pre-Extract Systems Analysis ' + rq.Systems_analysis__c;

what I want is to add a line break into the field but I am getting the error on this line:

+ '\r\n\' + 'Pre-Extract Systems Analysis ' + rq.Systems_analysis__c;

The error is Save error: line breaks not allowed in string literals

What is the correct or best way to include line breaks in strings within my fields?

2 Answers 2

6

The line

+ '\r\n\' + 'Pre-Extract Systems Analysis ' + rq.Systems_analysis__c;

contains a \' which is escaping the close ' and screwing everything up for you. It looks like it should just be:

+ '\r\n' + 'Pre-Extract Systems Analysis ' + rq.Systems_analysis__c;

or if you need that final slash

+ '\r\n\\' + 'Pre-Extract Systems Analysis ' + rq.Systems_analysis__c;
4

The error is on that line you're trying to add. \' is an escaped quote character, meaning your string isn't properly closed. simply removing the \ should fix the problem.

You must log in to answer this question.

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