You need to sign in to do that
Don't have an account?
Assh
getRecord()
Hi All,
I am trying the following Apex code. I am getting value "null" for the account name and Account id. Could anyone please let me know why I am getting "null" for the account name? Your help is greatly appreciated.
public class myControllerExtension { private final Account acct; // The extension constructor initializes the private member // variable acct by using the getRecord method from the standard // controller. public myControllerExtension(ApexPages.StandardController stdController) { this.acct = (Account)stdController.getRecord(); System.debug('account name' + this.acct.name); System.debug('account id' + this.acct.id); } public String getGreeting() { System.debug('account name' + acct.name); return 'Hello ' + acct.name + ' (' + acct.id + ')'; } }
Following is the debug log:
22.0 APEX_CODE,DEBUG 16:18:28.025 (25950000)|EXECUTION_STARTED 16:18:28.026 (26016000)|CODE_UNIT_STARTED|[EXTERNAL]|06650000000H4Ct|VF: /apex/sample1 16:18:28.049 (49222000)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000000LZQc|myControllerExtension <init> 16:18:28.049 (49345000)|METHOD_ENTRY|[1]|01p50000000LZQc|myControllerExtension.myControllerExtension() 16:18:28.049 (49386000)|METHOD_EXIT|[1]|myControllerExtension 16:18:28.049 (49740000)|USER_DEBUG|[13]|DEBUG|account namenull 16:18:28.049 (49859000)|USER_DEBUG|[14]|DEBUG|account idnull 16:18:28.049 (49914000)|CODE_UNIT_FINISHED|myControllerExtension <init> 16:18:28.091 (91934000)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000000LZQc|myControllerExtension get(greeting) 16:18:28.092 (92430000)|CODE_UNIT_STARTED|[EXTERNAL]|01p50000000LZQc|myControllerExtension invoke(getgreeting) 16:18:28.092 (92596000)|USER_DEBUG|[17]|DEBUG|account namenull 16:18:28.092 (92697000)|CODE_UNIT_FINISHED|myControllerExtension invoke(getgreeting) 16:18:28.092 (92723000)|CODE_UNIT_FINISHED|myControllerExtension get(greeting) 16:18:28.107 (107559000)|CODE_UNIT_FINISHED|VF: /apex/sample1 16:18:28.107 (107600000)|EXECUTION_FINISHED
Following is the VF code
<apex:page standardController="Account" extensions="myControllerExtension"> {!greeting} <p/> <apex:form > <apex:inputField value="{!account.name}"/> <p/> <apex:commandButton value="Save" action="{!save}"/> </apex:form> </apex:page>
stdController.getRecord() this will return a record with id when you will add id parameter in query parameter in the URL
like if your page name is MyPage the URL should be like
servername/apex/MyPage?id=001000000ssuIJH
here "001000000ssuIJH" is any id of any existing account record in your org
let me know if any issues in it.
All Answers
stdController.getRecord() this will return a record with id when you will add id parameter in query parameter in the URL
like if your page name is MyPage the URL should be like
servername/apex/MyPage?id=001000000ssuIJH
here "001000000ssuIJH" is any id of any existing account record in your org
let me know if any issues in it.
Hello,
Thank you very much for the solution. It worked when I gave proper id in the URL.
Your welcome