Neat Salesforce URLFOR Trick
December 28th, 2010
I was working on an app the other day and had written a custom screen allowing the user to add/edit multiple records on the same page. So in the process I wrote a Visualforce page that Overrides the standard New and Edit functions and redirects the user to this new screen. Here’s my code that I thought should have worked perfectly.
1 2 3 | <apex:page standardController=”MyCustomObject__c”
action=”{!URLFOR($Page.AddEditMultipleRecords,null,
[id=MyCustomObject__c.SomeRelatedObject__c])}”/> |
The code above worked great for the New function but I was receiving the following error for the Edit function:
SObject row was retrieved via SOQL without querying the requested field: MyCustomObject__c.SomeRelatedObject__c
This is actually a well-known “problem” when using a standard controller. The standard controller automatically constructs your SOQL query for you based on the fields that are referenced in your page. So simply including the field on the page, fixes the error.
1 2 3 4 5 | <apex:page standardController=”MyCustomObject__c”
action=”{!URLFOR($Page.AddEditMultipleRecords,null,
[id=MyCustomObject__c.SomeRelatedObject__c])}”>
{!MyCustomObject__c.SomeRelatedObject__c}
</apex:page> |
Categories: Salesforce, Visualforce













Interesting post !
Seems you included wrong field in the page i.e. {!Purchase_Order_Opportunity__c.Purchase_Order__c}
I believe it should be MyCustomObject__c.SomeRelatedObject__c
Thanks @Abhinav!! I didn’t cleanse my code as well I would have liked to.
Hi, this is definately most usefull, I’m trying to save the Visualforce page in my sandbox but get this error :
Save error: is required and must be the outermost tag in the markup at line 1 column 1
sorry
Save error: is required and must be the outermost tag in the markup at line 1 column 1
sorry again the error is on the page tag which is definately the outermost but eventually Eclipse returns the error.