function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC coderSFDC coder 

how to pass parameters using URLFOR()

How to pass parakmeters using URLFOR()hi all,

i have a scenario where in i need to prepopulate a field eventId of type text with event object's id passed using URLFOR().
However i get an error saying

Syntax error. Found '[' 

below is my code1 new_url = "{!URLFOR( $Action.Order__c.New, null, [00N11000000srcf=Event.Id])}";

2 window.location.replace(new_url);where  00N11000000srcf is fetched after i right click on text field-->inspect element and copy the id  of the field to be prepopulated

any help is appreciated
Best Answer chosen by SFDC coder
SFDC coderSFDC coder
hi all,

i have solved this using,single quotes around the id(last field ' 00N11000000srcf ')

new_url = "{!URLFOR( $Action.Order__c.New, null, [CF00N20000009GubC=Event.What,CF00N20000009GubC_lkid=Event.What.Id,'00N11000000srcf'=Event.Id])}";

window.location.replace(new_url);

All Answers

Gil GourévitchGil Gourévitch
Hi,
Your syntax is correct, but, do you try to use URLFOR in the controller ?
This method is a Visualforce function, so you can only use it in the VF page.

Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !
 
SFDC coderSFDC coder
hi gill,
now i am getting an error as Error: Syntax error. Missing field name
below is my code
new_url = "{!URLFOR( $Action.Order__c.New, null, [CF00N20000009GubC=Event.What,CF00N20000009GubC_lkid=Event.What.Id,"00N11000000srcf"=Event.Id])}"; 
window.location.replace(new_url);

where CF00N20000009GubC is the HTML id of a lookup field.I am trying to populate it with the event objects RelatedTo(What) field
 
Sumitkumar_ShingaviSumitkumar_Shingavi
Can you try below code
new_url = "{!URLFOR( $Action.Order__c.New, null, [CF00N20000009GubC=Event.What,CF00N20000009GubC_lkid=Event.What.Id,00N11000000srcf=Event.Id])}"; 
window.location.replace(new_url);
PS: if this answers your question then hit Like and mark it as solution!
SFDC coderSFDC coder
hi all,

i have solved this using,single quotes around the id(last field ' 00N11000000srcf ')

new_url = "{!URLFOR( $Action.Order__c.New, null, [CF00N20000009GubC=Event.What,CF00N20000009GubC_lkid=Event.What.Id,'00N11000000srcf'=Event.Id])}";

window.location.replace(new_url);
This was selected as the best answer