Apostrophe turns into "'" in Salesforce Name field

  • 1
  • Question
  • Updated 5 years ago
  • Answered

I have a simple Opportunity Name field on my page, and when the user enters an apostrophe it looks like the picture above. Is there a way to fix that? I am using a custom field renderer that looks like this:
<code>
var field = arguments[0],    value = skuid.utils.decodeHTML(arguments[1]),
   $ = skuid.$;
if(value != null){
    field.mode = 'read';
}
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
</code>
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Moshe, could you post / send us the full XML for your page? What is the content of the "Template" property of your Page Title component? 

Could it be that a "New Opportunity" Skuid page you have created is actually causing the issue, since based on your Custom Field Renderer it would be impossible from this page to ever change the Opportunity Name? Is this page used as a Opportunity Detail page?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
I'm using {{{Name}}} in the page title, it is a new opportunity page.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Change {{{Name}}} to {{Name}}. Triple-mustached fields are spitting out the raw data for a field, whereas double-mustache syntax is spitting out the HTML-encoded data. 
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
I just tried that and it didn't work.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
I noticed from your Page XML that there are other Custom Field Renderers that affect the value of the Opportunity Name field, in addition to the one you posted above. If you remove all of these Custom Field Renderers, does the problem persist?
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Hey Zach thanks for looking into that, I just realized that there is a point during the save process where I am adding info onto the name, like so:

var currentName = opportunityModel.getFieldValue(row,'Name');   
if(currentName != null){
       opportunityModel.updateRow(row,'Name',currentName + ' - ' + commodity); 
    }
Do you know why that would change the behavior of the Name field.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
If I comment out that line the apostrophe appears normally! However is there a way I can get around that because I would still like to update the Opportunity Name...
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Yes, change it to this:

var currentName = opportunityModel.getFieldValue(row,'Name',true);   
if(currentName != null){
opportunityModel.updateRow(row,'Name',currentName + ' - ' + commodity); 
}

The important thing is that 3rd parameter to .getFieldValue(), where we request the UN-ESCAPED value of the field. If you don't pass in the third parameter true, then you get the ESCAPED value of the field. We do this as a protection against XSS injection, since often people will just use getFieldValue() and dump the value directly to the screen, which could constitute an XSS vulnerability.  

Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Thanks that works!