You need to sign in to do that
Don't have an account?
Return custom object record ID to visualforce page
I am very new to development in general and to Salesforce development. I have a custom object Announcements__c. I want to display the most recent announcement record on a visualforce page. I have gone through the visualforce basics module (https://trailhead.salesforce.com/content/learn/modules/visualforce_fundamentals) but still cannot figure out how to pass the record ID of the most recent announcement record (custom object). Here is my apex class - which I modeled after the trailblazer example which used the Contact standard object, so not really sure this translates well to my custom object:
And here is the visualforce markup:
I get no errors, but also don't get my custom object field to display. Any help would be much appreciated!
The first thing you will notice with your code is that you are using standard controller instead of your custom controller that is why you are not seeing any error.
If you are into writing something custom of your own, then change standardController to Controller and mention you custom class name.
One of the important point to note that inputField/outputField can only be used with sObject, i.e. if you are passing a list<record> and accessing those in apex:outputfield you will receive an error even if your list has only one record.
Considering that change your code like below options:
If you want to play with list only then use below code:
check pageBlockTable: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageBlockTable.htm
You can remove pageBlockSection.
Hope it helped.
Regards,
Puneet.