You need to sign in to do that
Don't have an account?
Learnerrr
Below code is correct to avoid hardcode Ids?? Here I need to create constructor ??
public class abc{ private final Id AccountId; public abc(ApexPages.StandardController stdController) { Account acc = (Account)stdController.getRecord(); accountId = acc.Id; } @AuraEnabled public static Account getAccount(){ Account acc = [select Name,Phone,Id from Account where Id= :accountId]; System.debug(acc.Id); return acc; } }
Seems correct,what error you are getting?
Yes, the code is correct to avoid hardcoded id's. But there is no need to create another constructor.
Because you have already a constructor in your code:
public abc(ApexPages.StandardController stdController) {
Account acc = (Account)stdController.getRecord();
accountId = acc.Id;
}
If you want to initialize any code you can initialize in this constructor.
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
Error is :Variable does not exist : accountId
If you are getting error Variable does not exist : accountId make your variable to static to use in static method.
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
Change your code from private final Id AccountId to
private static Id AccountId;
Please mark as Best Answer to help others too.
Thank you
When you invoke the Aura Contrilleri dnt think so you are doing to initialize the StandardController constructor
Below is the correct code