+ Start a Discussion
Siva Nanda 9Siva Nanda 9 

Standard controller on opportunity object is not working

Hi Team,
I have created a VF page using standarController as Opportunity but it is not fetching the opportunity records(same is happening with Contact object too), whereas the same code is working fine with all other standar and custom object.

code below
<apex:page standardController="Contact" recordSetVar="cons">
    <apex:form >
    <apex:pageBlock title="Data from SF" >
        <apex:pageBlockSection title="Sub data" columns="1" >
        <apex:pageBlockTable value="{!cons}" var="c">
           <!-- <apex:column headerValue="Id of account along with link">
                <apex:outputLink value="/{!c.Id}">{!c.Id}</apex:outputLink>
            </apex:column> --->
            <apex:column value="{!c.Name}"/>
           
          </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:commandButton value="Next" action="{!Next}"/>
         <apex:commandButton value="Previous" action="{!previous}"/>
  
        </apex:pageBlock>
    </apex:form>
</apex:page>
Linga_RaminLinga_Ramin
Hi Siva,
     I pasted your code in my Org,it's working fine in my Org 
   
Avinash GangadhareAvinash Gangadhare
Hi Siva Nanda 9 --
Can you confirm if user opening the page having at least read access to the Opportunity and Account.. and check OWD too if it is private for these objects then only owned records will be shown to the users.

Thanks !!
Siva Nanda 9Siva Nanda 9
Hi Avinash
OWD settings for these two objects is public read/write
Khan AnasKhan Anas (Salesforce Developers) 
Hi Siva,

Greetings to you!

Absolutely there is no issue with the code. When using Standard List Controller, the page does not specify a filter in the request, so the page is displayed with the last used filter. The reason for this behavior is that the page is displaying the opportunities/contacts based on the last filter you've used. To fix this, try accessing the Opportunity/Contact tab and then click on All Opportunities or All Contacts in the View.

Now come to the visual force page and refresh the page, the standard controller now will display the list of opportunities/contacts object records.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_access_data.htm

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_list_views.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Deepali KulshresthaDeepali Kulshrestha
Hi Siva,

I have gone through your code. The code is working correctly.

Only one thing you have is that in the link of preview tab add '&id=(ANY CONTACT ID)'.


Example:--

https://curious-wolf-o8quto-dev-ed--c.visualforce.com/apex/con?core.apexpages.request.devconsole=1&id=0032v00002qqeNp


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com