You need to sign in to do that
Don't have an account?
TBouscal
Salesforce Example from VisualForce Workbook doesn't work
Trying to familiarize myself with extensions so I can eventually create a VF page to display the active territory members for each territory an account belongs in. I'm starting from scratch, straight out of the work book and not having ANY luck.
VF page called TerritoryMembership
I am accessing the page using a URL with ../apex/Territorymembership?id=accountid
What am I missing?
VF page called TerritoryMembership
<apex:page StandardController="Account" Extensions="TerritoryList"> {!Title} </apex:page>Apex extension
public class TerritoryList { private final Account acct; public TerritoryList(ApexPages.StandardController controller) { this.acct = (Account)controller.getRecord(); } public String getTitle() { return 'Account: ' + acct.name + ' (' + acct.id + ')'; } }These are directly from the VF workbook and I get an error message, System.SObjectException: SObject row was retrieved via SOQL without querying the reqested field: Account.Name Class.TerritoryList.getTitle: line8, column 1 (underlined above)
I am accessing the page using a URL with ../apex/Territorymembership?id=accountid
What am I missing?
return 'Account: ' + acct.name + ' (' + acct.id + ')';
You have the acct.id from your URL but you don't have the acct.name.
For accessing acct.name, you need to fire a SOQL:
Account accTest = [select id, name from Account where id = acct.id];
Now you may use:
return 'Account: ' + accTest.name + ' (' + acct.id + ')';
That being said, you're not using your "accTest" variable, but still the "acct" variable, hence why you are still seeing the exception.
Try the following instead: