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
ShotShot 

Why recordSetVar doesnt show data without id in the url

I don't know how i missed this before, but recently i realized, that my accountList vf page doesnt work without id.
And it is ok if we use standardController only. But if we use recordSetVar, which should give us some random elements form database, why it needs id also?

Lets say we created this VF page:
<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
  <apex:pageBlock >
    <apex:pageBlockTable value="{!accounts}" var="a">
      <apex:column value="{!a.name}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>
Then we click Preview and dont see anything.
User-added image

Now if we check the link we will find something like ...​visual.force.com/apex/AccountListTest?core.apexpages.request.devconsole=1
Let's add any id, even fake one: ...​visual.force.com/apex/AccountListTest?core.apexpages.request.devconsole=1&id=11111000003hffW
Boom! It works now:
User-added image


 
Best Answer chosen by Shot
Himanshu ParasharHimanshu Parashar
Hi Bogdan,

This is not related to recordsetvar. it is related to Standard controller which require id parameter in url as per the documentation. after getting the id sfdc initialize page.

For the getter method to succeed, the record specified by the id query string parameter in the URL must be of the same type as the standard controller. For example, a page that uses the Account standard controller can only return an account record. If a contact record ID is specified by the id query string parameter, no data is returned by the {!account} expression.

You can read it here as well.

http://www.salesforce.com/docs/developer/pages/Content/pages_controller_std_access_data.htm

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

All Answers

Himanshu ParasharHimanshu Parashar
Hi Bogdan,

This is not related to recordsetvar. it is related to Standard controller which require id parameter in url as per the documentation. after getting the id sfdc initialize page.

For the getter method to succeed, the record specified by the id query string parameter in the URL must be of the same type as the standard controller. For example, a page that uses the Account standard controller can only return an account record. If a contact record ID is specified by the id query string parameter, no data is returned by the {!account} expression.

You can read it here as well.

http://www.salesforce.com/docs/developer/pages/Content/pages_controller_std_access_data.htm

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
This was selected as the best answer
ShotShot
But i gave it fake id and i also tried with id's of case or contact, works with all of them. Looks like it doesnt matter what type is id and it is weird for me.
Chris AChris A
I had something similar to the problem that Shot described as I was building some exercises today. I thought I'd add a note in here since this came up high on the search results.

The page as presented doesn't need an ID parameter passed to the page to work, however one reason the page may not have displayed data is because a filter was not specified in the code and the filter applied will be the last filter used on the Account object.  (I say object, but now I'm curios where the actual "last filter" value is stored, since it could be associated with the standard controller. Sorry, I digress...).  In any case, if you go to the standard account page and set the filter so that accounts are displayed, this code works great.  By the way, this is noted in the Developer's Guide on the page "Accessing Data with List Controllers", but it's not something that jumps out at you.

Chris Andrews