function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Venkatesh DevamVenkatesh Devam 

Compile Error: Illegal string literal: Line breaks are not allowed in string literals

I am getting error in below statement.

String xmloutput = '<?xml version="1.0" encoding="UTF-8"?>
<ns2:gaTransactionType xmlns:ns2="http://abx.xa.gov">gaPaymentTransaction.xsd ">
    <merchantName>Arizona Test Merchant</merchantName>
    <merchantNumber>SNA_TEST</merchantNumber>
    <service>SNA_TEST_DONATION</service> 
                   <totalAmount>5000</totalAmount>';
srlawr uksrlawr uk
yes. you can't have line breaks in String literals.

You have two choices, change your definition to one line, or concatinate it.

(this might not work in the forum presentation, but I am removing all the line breaks.... so it's one long line)
 
String xmloutput = '<?xml version="1.0" encoding="UTF-8"?><ns2:gaTransactionType xmlns:ns2="http://abx.xa.gov">gaPaymentTransaction.xsd >merchantName>Arizona Test Merchant</merchantName><merchantNumber>SNA_TEST</merchantNumber><service>SNA_TEST_DONATION</service><totalAmount>5000</totalAmount>';

or, here, I add the string delimiting apostrophes and "+" signs to concat the multiline string:

 
String xmloutput = '<?xml version="1.0" encoding="UTF-8"?> ' +
' <ns2:gaTransactionType xmlns:ns2="http://abx.xa.gov">gaPaymentTransaction.xsd "> ' +
'    <merchantName>Arizona Test Merchant</merchantName> ' +
'    <merchantNumber>SNA_TEST</merchantNumber> ' +
'    <service>SNA_TEST_DONATION</service>  ' +
 '                  <totalAmount>5000</totalAmount>';


 
srlawr uksrlawr uk
(incidentally, the i first code snippet has not presented correctly, if you hover over it though and click the icon to "view source" you will see it as one long line!)