You need to sign in to do that
Don't have an account?
uu
Access current record ID
Hii Guys,
Please help me! I am new to apex code.
I want to access the current Record ID.
and assign that ID to another variable in apex class.
When i use the above code it shows error msg
Variable Does not exist currentRecod.
Please Help me to solve error.
Where my code is going wrong?
Thanks you
Please help me! I am new to apex code.
I want to access the current Record ID.
and assign that ID to another variable in apex class.
public class SampleCode{
Public Offers_Appraisals__c currentRecord{get; set;}
public SampleCode(ApexPages.StandardController controller) {
currentRecord = [SELECT ID FROM Offers_Appraisals__c
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public static void HRSalarySheet()
{
List<Offers_Appraisals__c> OfferList=new List<Offers_Appraisals__c>();
OfferList=[SELECT ID,Name,
From_Date__c,To_date__c
FROM Offers_Appraisals__c
WHERE ID=:currentRecord.ID];
}
Public Offers_Appraisals__c currentRecord{get; set;}
public SampleCode(ApexPages.StandardController controller) {
currentRecord = [SELECT ID FROM Offers_Appraisals__c
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public static void HRSalarySheet()
{
List<Offers_Appraisals__c> OfferList=new List<Offers_Appraisals__c>();
OfferList=[SELECT ID,Name,
From_Date__c,To_date__c
FROM Offers_Appraisals__c
WHERE ID=:currentRecord.ID];
}
When i use the above code it shows error msg
Variable Does not exist currentRecod.
Please Help me to solve error.
Where my code is going wrong?
Thanks you
There seems to be nothing wrong with the usage of your instance variable (currentRecord)
To verify, I tried the following sample code snippet in my local org and it worked just fine However, I believe the variable is inaccessible because your method, being static, can't see the instance variables. Removing the "static" keyword should allow the variable to be visible. Came across this:
https://salesforce.stackexchange.com/questions/194119/variable-does-not-exist-even-though-declared-at-top-of-apex-file
Anudeep
All Answers
There seems to be nothing wrong with the usage of your instance variable (currentRecord)
To verify, I tried the following sample code snippet in my local org and it worked just fine However, I believe the variable is inaccessible because your method, being static, can't see the instance variables. Removing the "static" keyword should allow the variable to be visible. Came across this:
https://salesforce.stackexchange.com/questions/194119/variable-does-not-exist-even-though-declared-at-top-of-apex-file
Anudeep
Thanks for reply.
It resolve my error.
So basically i want to ask you to get the current page record id there is no need write constructor and ApexPages.currentPage().getParameters().get('id')].
By using above code you have written, does it acccess the current record ID?
Thank you.
Yes, it does
I am able to see the results for System.debug('conList is'+ conList); in the code I executed in the execute anonymous window
Thanks,
Anudeep
Thank you .It worked.