Table of Contents
Problem Symptom
URLFOR function returns a relative URL for an action, s-control, Visualforce (VF) page, or used to return a reference to a file contained in a static resource archive such as a .zip or .jar file.
I got the invalid target parameter error randomly and could not able to figured out what causing this error. The detailed error message return from URLFOR function is as below:
Invalid target parameter for function URLFOR
Invalid parameter for function URLFOR
Invalid parameter for function URLFOR Error is in expression ‘{!URLFOR($Action.DisplayCheck__c.New,$CurrentPage.Name)}’ in component in page visitaudit_vf
URLFOR: Invalid parameter for function
Follow the below solution steps to resolve invalid target parameter for function URLFOR issue.
Solution 1: Check the order of parameters
- first param is $Page
- second param is Id
- third param is [‘param’=’eters’]
- fourth param is Boolean
try this example:
<apex:commandButton
value="Add Killer Checks"
action="{!URLFOR($Action.DisplayCheck__c.New, null, ['CF00N20000009H4jV'=$CurrentPage.Parameters.vname,'CF00N20000009H4jV_lkid'=$CurrentPage.Parameters.id])}"
style="float:center"
/>
Solution 2: Hide the outputlink
If the parameter where you pass your id is null, hide the outputLink completely when the id of the attachment is null to avoid this error.
<apex:outputLink value="{!URLFOR($Action.Attachment.Download, item.AttachmentID)}" target="_blank" rendered="{!NOT(ISBLANK(item) && NOT(ISBLANK(item.AttachmentID))}">{!item.AttachmentName}</apex:outputLink>
Solution 3: Define static variable
Define a static variable on a class, set that variable to true in your trigger and check against it. As long as you’re within the same transaction scope, that static variable will maintain its value.