0

I have a large text value as below in a custom field of a custom object.

FINDDATA: [XY_8852376.......
{name:"State__SKN", "data": "State__SKN", defaultContent: '', className:"frozencolumnscolor", title:"<filter/>State"}, {name:"Zip__SKN", "data": "Zip__SKN", defaultContent: '', className:"frozencolumnscolor", title:"<filter/>Zip"}, {name:"Specialty__SKN", "data":"Specialty__SKN", className: "text-center", defaultContent: '', title:"<filter/>Specialty"}, {name:"HQ_Call_Plan_Flag__SKN", "data": "HQ_Call_Plan_Flag__SKN", className: "text-center minwidth80", render: checkBoxRender ,defaultContent: '', title:"<filter/>HQ Call Plan Flag"}, {name:"HQ_Recommended_Frequency__SKN", "data": "HQ_Recommended_Frequency__SKN", className: "text-center", defaultContent: '', title:"<filter/>Recommended Calls"}, {name:"My_Frequency__SKN", "data": "My_Frequency__SKN", className: "text-center", render: myFrequencyRender, defaultContent: 0, title:"<filter/>Planned Calls"}, {name:"Reason_for_Add_Drop__SKN", "data": "Reason_for_Add_Drop__SKN",visible:false,className: "text-center minwidth100", defaultContent: '', render:reasonaddDropRender,title:"<filter/>Reason for Add/Drop"}, {name:"My_Action__SKN", "data": "My_Action__SKN", render: myActionRender, className: "text-center minwidth100", defaultContent: '', title:"<filter/>My Action"}, {name:"Business_Planner_Flag__SKN", "data": "Business_Planner_Flag__SKN", className: "text-center minwidth80", render: bpPlanRender, defaultContent: '', title:"<filter/>Business Planner Flag"}, {name:"Text_Field_01__SKN", "data": "Text_Field_01__SKN", className: "text-center", render: tpPlanRender, defaultContent: '', title:"<filter/>Targeted Product"}, {name:"PDRP_Flag__SKN", "data": "PDRP_Flag__SKN", render: checkBoxRender , visible:false,className: "text-center minwidth80", defaultContent: '', title:"<filter/>PDRP Flag"}, {name:"Text_Field_09__SKN", "data": "Text_Field_09__SKN", className: "text-center", defaultContent: '', visible:false, title:"<filter/>IC Universe"}, {name:"Text_Field_08__SKN", "data": "Text_Field_08__SKN", className: "minwidth120",defaultContent: '', visible:false, title:"<filter/>Approved for Detailing"}, {name:"Text_Field_10__SKN", "data": "Text_Field_10__SKN", visible:false, className: "minwidth180",defaultContent: '', title:"<filter/>Recommended Product P1s"}, {name:"Last_Quarter_Calls_By_Rep__SKN", "data":"Last_Quarter_Calls_By_Rep__SKN", visible:false, render: numberRenderer, defaultContent: '', className: "text-center minwidth100", title:"<filter/>Calls Made (Last 3 Mo)"}, {name:"Text_Field_02__SKN", "data": "Text_Field_02__SKN", className: "minwidth100", type:'decile', visible:false, defaultContent: '', title:"<filter/>ANG Product Decile"}, {name:"Text_Field_03__SKN", "data": "Text_Field_03__SKN", className: "minwidth100", type:'decile', visible:false, defaultContent: '', title:"<filter/>TTRT Market Decile"}, {name:"Text_Field_04__SKN", "data": "Text_Field_04__SKN", className: "minwidth120", visible:false, defaultContent: '', title:"<filter/>ANG Motivational Profile"}, {name:"Text_Field_05__SKN", "data": "Text_Field_05__SKN", className: "minwidth100", type:'decile', visible:false, defaultContent: '', title:"<filter/>SYN Product Decile"}, {name:"Text_Field_06__SKN", "data": "Text_Field_06__SKN", className: "minwidth120", type:'decile', visible:false, defaultContent: '', title:"<filter/>Thyroid Market Decile"}, {name:"Text_Field_07__SKN", "data": "Text_Field_07__SKN", className: "minwidth120", visible:false, defaultContent: '', title:"<filter/>SYN Motivational Profile"}, {name:"Decimal_Field_02__SKN",data:"Decimal_Field_02__SKN", visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>TTRT Rx Volume"}, {name:"Decimal_Field_03__SKN",data:"Decimal_Field_03__SKN", render: numberRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>ANG Rx Volume"}, {name:"Decimal_Field_05__SKN",data:"Decimal_Field_05__SKN", render: percentRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>ANG Market Share"}, {name:"Decimal_Field_06__SKN",data:"Decimal_Field_06__SKN", render: percentRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>ANG Share Growth"}, {name:"Decimal_Field_07__SKN",data:"Decimal_Field_07__SKN", render: numberRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>Thyroid Rx Volume"}, {name:"Decimal_Field_08__SKN",data:"Decimal_Field_08__SKN", render: numberRenderer, visible:false, className: "minwidth80", defaultContent: '', title:"<filter/>SYN Rx Volume"}, {name:"Decimal_Field_09__SKN",data:"Decimal_Field_09__SKN", render: percentRenderer, visible:false, className: "minwidth140", defaultContent: '', title:"<filter/>SYN % TRx Growth (Last 3 Mo)"}, {name:"Decimal_Field_10__SKN",data:"Decimal_Field_10__SKN", render: percentRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>SYN Market Share"}, {name:"Decimal_Field_11__SKN",data:"Decimal_Field_11__SKN", render: percentRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>SYN Share Growth"}, {name:"Decimal_Field_12__SKN",data:"Decimal_Field_12__SKN", render: percentRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>ANG Favorability"}, {name:"Decimal_Field_13__SKN",data:"Decimal_Field_13__SKN", render: numberRenderer, visible:false, className: "minwidth180", defaultContent: '', title:"<filter/>Other TTRT Volume in Favorable Plans"}, {name:"Decimal_Field_14__SKN",data:"Decimal_Field_14__SKN", render: numberRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>Favorability Gap"}, {name:"Decimal_Field_15__SKN",data:"Decimal_Field_15__SKN", render: numberRenderer, visible:false, className: "minwidth100", defaultContent: '', title:"<filter/>Caremark TTRT TRx"}, {name:"Decimal_Field_16__SKN",data:"Decimal_Field_16__SKN", render: numberRenderer, visible:false, className: "NoExport minwidth100", defaultContent: '',display: "hide", title:"<filter/>Silverscript TTRT TRx"}, {name:"Decimal_Field_17__SKN",data:"Decimal_Field_17__SKN", render: percentRenderer, visible:false, className: "NoExport text-center minwidth100", defaultContent: '', display: "hide", title:"<filter/>AndroGel Call %"}, { name: "Bus_Plan_Record_Id__c", "data": "Bus_Plan_Record_Id__c",visible:false, defaultContent: '', title:"<filter/>Source"}, {name:"ttrtdecilecalc", className: "NoExport", "data": function (row){ row.ttrtdecilecalc = row.Text_Field_08__SKN == 'SYN'? 'Synthroid Only' : row.Text_Field_03__SKN; return row.ttrtdecilecalc; }, visible:false, defaultContent: ''}, {name:"androdecilecalc", className: "NoExport", "data": function (row){ row.androdecilecalc= row.Text_Field_08__SKN == 'SYN'? 'Synthroid Only' : row.Text_Field_02__SKN; return row.androdecilecalc; }, visible:false, defaultContent: ''}, {name:"andromotprofcalc", className: "NoExport", "data": function (row){ row.andromotprofcalc= row.Text_Field_08__SKN == 'SYN'? 'Synthroid Only' : row.Text_Field_04__SKN; return row.andromotprofcalc; }, visible:false , defaultContent: ''}, {name:"thyrdeccalc", className: "NoExport", "data": function (row){ row.thyrdeccalc= row.Text_Field_08__SKN == 'ANG'? 'AndroGel Only' : row.Text_Field_06__SKN; return row.thyrdeccalc; }, visible:false , defaultContent: ''}, {name:"syndeccalc", className: "NoExport", "data": function (row){ row.syndeccalc= row.Text_Field_08__SKN == 'ANG'? 'AndroGel Only' : row.Text_Field_05__SKN; return row.syndeccalc; }, visible:false , defaultContent: ''}, {name:"synmotprofcalc", className: "NoExport", "data": function (row){ row.synmotprofcalc= row.Text_Field_08__SKN == 'ANG'? 'AndroGel Only' : row.Text_Field_07__SKN; return row.synmotprofcalc; }, visible:false , defaultContent: ''}, {name:"Text_Field_25__SKN", className: "NoExport", "data":"Text_Field_25__SKN", visible:false, display: "hide", defaultContent: ''}]...........xniojniocsimk....

Now I need to extract all those values having '_SKN' as an item of a list. But whenever I try to put them in a string it throws compile error for double identifiers. Error:

 Compile Error: Unrecognized symbol '"', which is not a valid Apex identifier. 

Can someone please help me with a way out here? I have to find the text ='FINDDATA' and immediate closing third bracket after that to substring the relevant portion. I was trying as below. String X='....[Above text]'; String JSONString = JSON.serialize(X);

  • If that's valid JSON, it looks like you want to deserialize it rather than serializing. – David Reed Apr 22 '18 at 13:03
2

Your JSON is not valid JSON. Even if your code compiled, deserializing would result in other errors. Please refer to this website. Long story short, though, is that JSON is a subset of JavaScript, and has stringent rules for how it operates. Notably, '' is not a valid "empty string." Instead, it must be "", or optionally, null, without any quotes, depending on your intent:

{ "validEmptyString": "", "validNullValue": null }

Note that field names must always be quoted with ".

However, let's say you did want to put a literal ' in your code. To do this, you "escape" them:

String aintAintAWord = '"Ain\'t" ain\'t a word.'

If you need a backslash, you can escape those, too:

String escapedEscape = '\\';

Note that, because of that, if you want a literal backslash to appear in your JSON, you end up doubling that yet again:

String observeMyBackSlash = '{ "source": "The Amazing \\\\" }';

Which results in "The Amazing \" (just a single backslash). Note that this is a side effect of JSON escaping literal \ as \\, plus Apex Code doing the same. Each escape has to be escaped again to finally result in a single, valid backslash.

This rule only applies to Apex Code source code. If you're reading your JSON from the database, a Custom Label, an HTTP callout, or another source, that source should not double-escape the backslash.

So, for example, if you have a Static Resource with some JSON, it might look like this:

{ "Name": "Dwayne \"The Rock\" Johnson" }

JSON requires an escape, but since this isn't in Apex Code, we do not double up on the backslashes in this case.

| improve this answer | |

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.