0

I am getting the value from a text area and sending it to apex for saving.

For example this:- You're orange.

This value appears properly in console logs and apex debugs.

However when I SOQL, it changes to this- You're orange. Edit: the resulting escaping was invisible

I tried using the escapeSingleQuote string function, it didn't work.

Here is my code;

    var action = component.get("c.setEmployerMessage");
    //This is important, as it converts it to text type.
    var employerMsg = component.get("v.employerMessage");
    console.log('employerMsg-->'+component.get("v.employerMessage"));
    console.log('employerMsg Variable-->'+employerMsg);
    action.setParams({strMessage:employerMsg});
    action.setCallback(this, function(response) {
        var state = response.getState();

Apex

@AuraEnabled
public static void setEmployerMessage(String strMessage){
    try{
        System.debug('Message in set-->'+strMessage);
        System.debug('Single quote process-->'+ String.escapeSingleQuotes(strMessage));
        User currentUser = CarynCommonUtilityClass.getLoggedInUserDetails();
        List<Account> lstAccountToUpdate = [Select Id,Enrollment_Message__c,Name
                                            from Account
                                           where Id=:currentUser.Contact.AccountId];
        Account accToUpdate = lstAccountToUpdate[0];
        System.debug('accToUpdate in set-->'+accToUpdate.Name);
        accToUpdate.Enrollment_Message__c = strMessage;
        update accToUpdate;

Debug Logs:-

09:35:25.0 (393694)|CODE_UNIT_STARTED|[EXTERNAL]|Aura 09:35:25.0 (2369747)|CODE_UNIT_STARTED|[EXTERNAL]|01p2E000009apFH|PersonalizeMessageController.setEmployerMessage(String) 09:35:25.0 (2524639)|HEAP_ALLOCATE|[79]|Bytes:3 09:35:25.0 (2598850)|HEAP_ALLOCATE|[84]|Bytes:152 09:35:25.0 (2622730)|HEAP_ALLOCATE|[399]|Bytes:408 09:35:25.0 (2646436)|HEAP_ALLOCATE|[412]|Bytes:408 09:35:25.0 (2668874)|HEAP_ALLOCATE|[520]|Bytes:48 09:35:25.0 (2726819)|HEAP_ALLOCATE|[139]|Bytes:6 09:35:25.0 (2799394)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5 09:35:25.0 (2808782)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 09:35:25.0 (2824778)|METHOD_ENTRY|[15]|01p2E000009apFH|PersonalizeMessageController.PersonalizeMessageController() 09:35:25.0 (2834893)|STATEMENT_EXECUTE|[15] 09:35:25.0 (2843754)|STATEMENT_EXECUTE|[15] 09:35:25.0 (2892454)|HEAP_ALLOCATE|[52]|Bytes:5 09:35:25.0 (2919582)|HEAP_ALLOCATE|[58]|Bytes:5 09:35:25.0 (2928416)|HEAP_ALLOCATE|[66]|Bytes:7 09:35:25.0 (2949451)|SYSTEM_MODE_ENTER|false 09:35:25.0 (2965143)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5 09:35:25.0 (2973269)|SYSTEM_MODE_EXIT|false 09:35:25.0 (2981647)|METHOD_EXIT|[15]|PersonalizeMessageController 09:35:25.0 (2987799)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:14 09:35:25.0 (2994422)|SYSTEM_MODE_ENTER|false 09:35:25.0 (3000237)|VARIABLE_SCOPE_BEGIN|[44]|strMessage|String|false|false 09:35:25.0 (3052701)|VARIABLE_ASSIGNMENT|[44]|strMessage|"You're Orange." 09:35:25.0 (3080347)|HEAP_ALLOCATE|[45]|Bytes:5 09:35:25.0 (3086222)|STATEMENT_EXECUTE|[44] 09:35:25.0 (3088951)|STATEMENT_EXECUTE|[45] 09:35:25.0 (3091192)|STATEMENT_EXECUTE|[45] 09:35:25.0 (3093522)|STATEMENT_EXECUTE|[46] 09:35:25.0 (3097048)|HEAP_ALLOCATE|[46]|Bytes:17 09:35:25.0 (3113707)|HEAP_ALLOCATE|[46]|Bytes:31 09:35:25.0 (3141542)|SYSTEM_METHOD_ENTRY|[46]|System.debug(ANY) 09:35:25.0 (3166657)|USER_DEBUG|[46]|DEBUG|Message in set-->You're Orange. 09:35:25.0 (3176813)|SYSTEM_METHOD_EXIT|[46]|System.debug(ANY) 09:35:25.0 (3181888)|STATEMENT_EXECUTE|[48] 09:35:25.0 (3760297)|HEAP_ALLOCATE|[48]|Bytes:40 09:35:25.0 (3778364)|HEAP_ALLOCATE|[48]|Bytes:39 09:35:25.0 (3794678)|METHOD_ENTRY|[14]|01p2E000009apE9|CarynCommonUtilityClass.CarynCommonUtilityClass() 09:35:25.0 (3803511)|STATEMENT_EXECUTE|[14] 09:35:25.0 (3809320)|STATEMENT_EXECUTE|[14] 09:35:25.0 (3822503)|SYSTEM_MODE_ENTER|true 09:35:25.0 (3833715)|HEAP_ALLOCATE|[48]|Bytes:5 09:35:25.0 (3842954)|SYSTEM_MODE_EXIT|true 09:35:25.0 (3854989)|METHOD_EXIT|[14]|CarynCommonUtilityClass 09:35:25.0 (3875642)|METHOD_ENTRY|[48]|01p2E000009apE9|CarynCommonUtilityClass.getLoggedInUserDetails() 09:35:25.0 (3902494)|SYSTEM_MODE_ENTER|true 09:35:25.0 (3909274)|HEAP_ALLOCATE|[22]|Bytes:5 09:35:25.0 (3917358)|STATEMENT_EXECUTE|[21] 09:35:25.0 (3921116)|STATEMENT_EXECUTE|[22] 09:35:25.0 (3924060)|STATEMENT_EXECUTE|[22] 09:35:25.0 (3926710)|STATEMENT_EXECUTE|[23] 09:35:25.0 (3931578)|HEAP_ALLOCATE|[23]|Bytes:146 09:35:25.0 (3962696)|HEAP_ALLOCATE|[23]|Bytes:4 09:35:25.0 (3979332)|HEAP_ALLOCATE|[23]|Bytes:7 09:35:25.0 (14978600)|HEAP_ALLOCATE|[25]|Bytes:97 09:35:25.0 (15037895)|SYSTEM_METHOD_ENTRY|[1]|UserInfo.UserInfo() 09:35:25.0 (15054016)|STATEMENT_EXECUTE|[1] 09:35:25.0 (15067840)|SYSTEM_METHOD_EXIT|[1]|UserInfo 09:35:25.0 (15091177)|METHOD_ENTRY|[25]||System.UserInfo.getUserId() 09:35:25.0 (38509070)|METHOD_EXIT|[25]||System.UserInfo.getUserId() 09:35:25.0 (42655750)|SOQL_EXECUTE_BEGIN|[23]|Aggregations:0|SELECT Id, ContactId, Contact.AccountId, Contact.Account.Enrollment_Status__c, Contact.Account.Enrollment_Message__c FROM User WHERE Id = :tmpVar1 09:35:25.0 (42681708)|LIMIT_USAGE|[23]|SOQL|1|100 09:35:25.0 (42706859)|LIMIT_USAGE|[23]|AGGS|0|300 09:35:25.0 (55319612)|SOQL_EXECUTE_END|[23]|Rows:1 09:35:25.0 (55341427)|LIMIT_USAGE|[23]|SOQL_ROWS|1|50000 09:35:25.0 (55371714)|HEAP_ALLOCATE|[23]|Bytes:8 09:35:25.0 (55392336)|HEAP_ALLOCATE|[23]|Bytes:259 09:35:25.0 (55545869)|HEAP_ALLOCATE|[23]|Bytes:8 09:35:25.0 (55571611)|VARIABLE_SCOPE_BEGIN|[23]|usr|List|true|false 09:35:25.0 (55624415)|VARIABLE_ASSIGNMENT|[23]|usr|[{"Id":"0058A000002NQhiQAG","ContactId":"0038A00000Gag87QAB","Contact":{"AccountId":"0018A00000MJsXBQA1","Id":"0038A00000Gag87QAB","Account":{"Enrollment_Status__c":"Quote Accepted","Enrollment_Message__c":"You're Personal (7 more) ...","Id":"0018A00000MJsXBQA1"}}}]|0x60343f2b 09:35:25.0 (55636099)|STATEMENT_EXECUTE|[27] 09:35:25.0 (55707998)|HEAP_ALLOCATE|[27]|Bytes:16 09:35:25.0 (55721714)|SYSTEM_MODE_EXIT|true 09:35:25.0 (56297785)|METHOD_EXIT|[48]|01p2E000009apE9|CarynCommonUtilityClass.getLoggedInUserDetails() 09:35:25.0 (56313917)|VARIABLE_SCOPE_BEGIN|[48]|currentUser|User|true|false 09:35:25.0 (56353249)|VARIABLE_ASSIGNMENT|[48]|currentUser|{"Id":"0058A000002NQhiQAG","ContactId":"0038A00000Gag87QAB","Contact":{"AccountId":"0018A00000MJsXBQA1","Id":"0038A00000Gag87QAB","Account":{"Enrollment_Status__c":"Quote Accepted","Enrollment_Message__c":"You're Personal (7 more) ...","Id":"0018A00000MJsXBQA1"}}}|0x1a5ab411 09:35:25.0 (56361978)|STATEMENT_EXECUTE|[49] 09:35:25.0 (56368994)|HEAP_ALLOCATE|[49]|Bytes:71 09:35:25.0 (56392373)|HEAP_ALLOCATE|[49]|Bytes:4 09:35:25.0 (56800768)|SOQL_EXECUTE_BEGIN|[49]|Aggregations:0|SELECT Id, Enrollment_Message__c, Name FROM Account WHERE Id = :tmpVar1 09:35:25.0 (56817566)|LIMIT_USAGE|[49]|SOQL|2|100 09:35:25.0 (56833459)|LIMIT_USAGE|[49]|AGGS|0|300 09:35:25.0 (111101692)|SOQL_EXECUTE_END|[49]|Rows:1 09:35:25.0 (111123355)|LIMIT_USAGE|[49]|SOQL_ROWS|2|50000 09:35:25.0 (111153398)|HEAP_ALLOCATE|[49]|Bytes:8 09:35:25.0 (111168881)|HEAP_ALLOCATE|[49]|Bytes:94 09:35:25.0 (111290924)|HEAP_ALLOCATE|[49]|Bytes:8 09:35:25.0 (111317663)|VARIABLE_SCOPE_BEGIN|[49]|lstAccountToUpdate|List|true|false 09:35:25.0 (111365674)|VARIABLE_ASSIGNMENT|[49]|lstAccountToUpdate|[{"Id":"0018A00000MJsXBQA1","Enrollment_Message__c":"You're Personal (7 more) ...","Name":"Print"}]|0x24d88fc6 09:35:25.0 (111374108)|STATEMENT_EXECUTE|[52] 09:35:25.0 (111448035)|HEAP_ALLOCATE|[52]|Bytes:16 09:35:25.0 (111458403)|VARIABLE_SCOPE_BEGIN|[52]|accToUpdate|Account|true|false 09:35:25.0 (111477081)|VARIABLE_ASSIGNMENT|[52]|accToUpdate|{"Id":"0018A00000MJsXBQA1","Enrollment_Message__c":"You're Personal (7 more) ...","Name":"Print"}|0x196cae7a 09:35:25.0 (111483496)|STATEMENT_EXECUTE|[53] 09:35:25.0 (111489175)|HEAP_ALLOCATE|[53]|Bytes:21 09:35:25.0 (111535072)|HEAP_ALLOCATE|[53]|Bytes:26 09:35:25.0 (111558688)|SYSTEM_METHOD_ENTRY|[53]|System.debug(ANY) 09:35:25.0 (111586664)|USER_DEBUG|[53]|DEBUG|accToUpdate in set-->Print 09:35:25.0 (111595293)|SYSTEM_METHOD_EXIT|[53]|System.debug(ANY) 09:35:25.0 (111600405)|STATEMENT_EXECUTE|[54] 09:35:25.0 (111674156)|VARIABLE_ASSIGNMENT|[54]|this.Enrollment_Message__c|"You're Orange."|0x196cae7a 09:35:25.0 (111681123)|STATEMENT_EXECUTE|[55] 09:35:25.0 (111713357)|HEAP_ALLOCATE|[55]|Bytes:8 09:35:25.0 (111723763)|DML_BEGIN|[55]|Op:Update|Type:Account|Rows:1 09:35:25.0 (111739598)|LIMIT_USAGE|[55]|DML|1|150 09:35:25.0 (111753149)|LIMIT_USAGE|[55]|DML_ROWS|1|10000 09:35:25.0 (111770256)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 09:35:25.0 (140901821)|CODE_UNIT_STARTED|[EXTERNAL]|01q2E000000ck6o|AccountTrigger on Account trigger event BeforeUpdate|__sfdc_trigger/AccountTrigger 09:35:25.0 (140962558)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 09:35:25.0 (141004958)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 09:35:25.0 (141094871)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4 09:35:25.0 (141106692)|VARIABLE_SCOPE_BEGIN|[1]|this|AccountTrigger|true|false 09:35:25.0 (141139168)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x23e0a748 09:35:25.0 (141163167)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4 09:35:25.0 (141168785)|VARIABLE_SCOPE_BEGIN|[1]|this|AccountTrigger|true|false 09:35:25.0 (141180388)|VARIABLE_ASSIGNMENT|[1]|this|{}|0x23e0a748 09:35:25.0 (141188512)|STATEMENT_EXECUTE|[1] 09:35:25.0 (141209143)|STATEMENT_EXECUTE|[3] 09:35:25.0 (141218008)|STATEMENT_EXECUTE|[4] 09:35:25.0 (141224094)|STATEMENT_EXECUTE|[9] 09:35:25.0 (141226590)|STATEMENT_EXECUTE|[10] 09:35:25.0 (141868884)|HEAP_ALLOCATE|[10]|Bytes:22 09:35:25.0 (141885317)|HEAP_ALLOCATE|[10]|Bytes:64 09:35:25.0 (141917706)|METHOD_ENTRY|[5]|01p2E000009apDz|AccountTriggerHelper.AccountTriggerHelper() 09:35:25.0 (141925731)|STATEMENT_EXECUTE|[5] 09:35:25.0 (141930948)|STATEMENT_EXECUTE|[5] 09:35:25.0 (141937074)|METHOD_EXIT|[5]|AccountTriggerHelper 09:35:25.0 (141960833)|METHOD_ENTRY|[10]|01p2E000009apDz|AccountTriggerHelper.updateAccountStateCode(List, Map) 09:35:25.0 (141982698)|VARIABLE_SCOPE_BEGIN|[87]|newAccList|List|true|false 09:35:25.0 (186547761)|VARIABLE_ASSIGNMENT|[87]|newAccList|[{"LastModifiedDate":"2019-12-16T17:35:04.000Z","Bank_Account_Holder__c":"Print","Employer_Microsite_Link__c":"http://dev.employer. (77 more) ...","Broker_Group__c":"00G8A000001kbwuUAA","Taxpayer_Id__c":"123456789","Enrollment_Message__c":"You're Orange.","Industry__c":"Automotive Repair, S (19 more) ...","Name":"Print","Company_Owner__c":"Community Admin","Is_Authorization_Provided__c":false,"City__c":"Chicago","CreatedById":"0058A000002JfsYQAS","tender_type__c":"Account","Bank_Name__c":"HDFC","Enrollment_cutOff_date__c":"2019-12-31T00:00:00.000Z","Bank_Routing_Number__c":24242424,"State__c":"Illinois","MemberApi_Success__c":false,"Bank_Account_Type__c":"Checking","IsDeleted":false,"Quote_Accepted__c":false,"Enrollment_Status__c":"Quote Accepted","Sic":"7533","Sharing_Plans__c":false,"Plan_Effective_Date__c":"2020-01-15T00:00:00.000Z","Street_Suite__c":"Redwood","Division__c":"Services","CreatedDate":"2019-12-04T05:29:00.000Z","First_Name__c":"CEO","Id":"0018A00000MJsXBQA1","Department__c":"HR","IsPartner":false,"Last_Name__c":"Print","picklis__c":"Auto Exhaust System (12 more) ...","Cheque_Uploaded__c":true,"Job_Title__c":"CEO","Send_Quote_From__c":"AFMC","OwnerId":"0052E00000JRYwbQAH","RecordTypeId":"0122E000000dDa2QAE","Transaction_Description__c":"Company Name Print C (28 more) ...","State_Code__c":"IL","ZIP__c":"60617","Phone_Number__c":"8087752115","Plan_End_Date__c":"2021-01-14T00:00:00.000Z","Company_Number__c":"C-00068","Send_Merchant_receipt__c":1,"Work_Email__c":"[email protected]","Bank_Account_Number__c":"24242","IsCustomerPortal":true,"Census_Group__c":"00G8A000001kbwvUAA","Client_Id__c":"3206","Employee_Microsite_Link__c":"http://dev.member.ah (75 more) ...","SystemModstamp":"2019-12-16T17:35:04.000Z","Custom_Data__c":"Caryn Health 3206","Organization__c":"AHPA","Same_as_Above__c":false,"send_customer_receipt__c":1,"LastModifiedById":"0058A000002NQhiQAG"}]|0x5d4d2968 09:35:25.0 (186601835)|VARIABLE_SCOPE_BEGIN|[87]|oldAccMap|Map|true|false 09:35:25.0 (188652640)|VARIABLE_ASSIGNMENT|[87]|oldAccMap|{"0018A00000MJsXBQA1":{"Las

4
  • would you share the logging?
    – SeanGorman
    Commented Dec 16, 2019 at 15:04
  • What is the type of field Enrollment_Message__c?
    – David Reed
    Commented Dec 16, 2019 at 16:23
  • This is the field type:- Rich Text Area(32768)
    – mvk1991
    Commented Dec 16, 2019 at 17:32
  • 1
    @SeanGorman Added Debug Logs,basically while variable assignment it is fine, but next when trigger runs, and Trigger.newis referred, it add the characters. (you can search logs with the word Orange)
    – mvk1991
    Commented Dec 16, 2019 at 17:40

1 Answer 1

2

Rich Text Area fields are stored in HTML, where characters such as apostrophes are escaped. That is what you're seeing here. It's behaving as designed and cannot be changed.

From Editing Rich Text Area Fields in Records :

Rich text field values are returned in HTML format. Some characters are escaped when the custom field value is retrieved through the API.

  • Ampersand character & is returned as &amp;.
  • Greater than character > is returned as &gt;
  • Less than character < is returned as &lt;
  • Quote character " is returned as &quot;
  • Single quote character ' is returned as &#39;
1
  • Thanks David. I have changed the field type to normal long text area, as it was not absolutely needed there.
    – mvk1991
    Commented Dec 16, 2019 at 18:15

You must log in to answer this question.

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