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');}
  • 1
    Can you please change the question title ? – Jarvis Feb 23 '16 at 13:11
  • 1
    A clear title is a good norm – Jarvis Feb 23 '16 at 13:41
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.

| improve this answer | |
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')
| 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.