You need to sign in to do that
Don't have an account?
Sebastien Plante
Trying to display the lasted entry of a related list... but getting "Content cannot be displayed: List has no rows for assignment to SObject"
I'm trying to display the last entry of a custom related list (BPG) from Account.
I'm using this
and the "sample" VF page (I will complete it when fixed! :P)
I've been trying many things found on the internet... but I can't seems to find the best way for doing it.
Using a list seems to be the "best idea", but I never manged to get anything on the VF page... I'm lost! :'(
I'm using this
public class BGP_ControllerExtension { public String currentRecordId {get;set;} public BGP_ControllerExtension(ApexPages.StandardController controller) { currentRecordId = ApexPages.CurrentPage().getparameters().get('id'); } public Business_Generator_Profile__c BGPList { get { if ( BGPList == null ) { Business_Generator_Profile__c[] BGPList = [ SELECT Name, Dealer__c, Account__r.Id FROM Business_Generator_Profile__c WHERE Account__r.Id = :currentRecordId ORDER BY CreatedDate DESC LIMIT 1 ]; } return BGPList; } private set; } }
and the "sample" VF page (I will complete it when fixed! :P)
<apex:page standardController="Account" extensions="BGP_ControllerExtension" showHeader="false"> <apex:pageBlock> <apex:PageBlockSection title="Business Generator Profile ({!BGPList.Name})"> <apex:outputField value="{!BGPList.Dealer__c}"/> </apex:PageBlockSection> </apex:pageBlock> </apex:page>and it's working fine, except for one thing... When there's nothing on the related list, It display "Content cannot be displayed: List has no rows for assignment to SObject". I wish to change that to a custom message, simply "No BGP entered or something like this".
I've been trying many things found on the internet... but I can't seems to find the best way for doing it.
Using a list seems to be the "best idea", but I never manged to get anything on the VF page... I'm lost! :'(
All Answers
Woohoo ! Working. Thanks a lot !
The "apex:pageMessages" need to have a field else it won't display (dosent call the controller?), but since I use the rendered, it's working fine :D