0

I have below code that gives out error with Form custom object's Id value as not defined. Can someone please help?

JAVASCRIPT

window.open('/apex/FormTemplatePrinterRequest?'+'id='+{!Form_Requests_abv__c.Id}+'&TemplateId='+{!Form_Requests_abv__c.Form_Template_Name_abvId__c},'_blank');}
2
  • 1
    Can you please change the question title ?
    – Jarvis
    Feb 23, 2016 at 13:11
  • 1
    A clear title is a good norm
    – Jarvis
    Feb 23, 2016 at 13:41

2 Answers 2

5

Apex variables are not part of Javascript runtime, they are rendered from server side.

  • You need to enclose the Apex variables with single quote in client side.

Try this:

window.open('/apex/FormTemplatePrinterRequest?'+'id='+'{!Form_Requests_abv__c.Id}'+'&TemplateId='+'{!Form_Requests_abv__c.Form_Template_Name_abvId__c}','_blank');}

Even though above code will work its better to JSENCODE the Apex variables to avoid XSS vulnerablity:

window.open('/apex/FormTemplatePrinterRequest?id={!JSENCODE(Form_Requests_abv__c.Id)}&TemplateId={!JSENCODE(Form_Requests_abv__c.Form_Template_Name_abvId__c)}','_blank');}

If you apply for security review, all these vulnerabilities will raise serious red flags, so its better to follow it.

2

Try the below code :

window.open('/apex/FormTemplatePrinterRequest?id={!Form_Requests_abv__c.Id}&TemplateId={!Form_Requests_abv__c.Form_Template_Name_abvId__c}','_blank')

You must log in to answer this question.

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