You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Final Members error
I have an class where I have a Class level Variable
private static final Map<Id,Customer__c> CUSTOMERTEMP;
In my method
global override void bulkAfterExtended(){
When I go to deploy I get a
"Final Memebers can only be assigned in thier declaration, init blocks,or constructor: CUSTOMERTEMP"
I have other private static final with no issue but they are not maps. What am doing wrong?
Thanks,
P
private static final Map<Id,Customer__c> CUSTOMERTEMP;
In my method
global override void bulkAfterExtended(){
if (!CustVal.isEmpty()) { CUSTOMERTEMP = new Map<Id,Customer_c>([SELECT Id, Name,Status__c FROM Customer__c); }
When I go to deploy I get a
"Final Memebers can only be assigned in thier declaration, init blocks,or constructor: CUSTOMERTEMP"
I have other private static final with no issue but they are not maps. What am doing wrong?
Thanks,
P
As we know final variables can only be assigned a value once, either when you declare a variable or inside a constructor per documentation
You cannot assign the final static variable value other than the declaration of variable or static block. If you try to assign it, then you will get an error as "Final static variables can only be assigned in their declaration or in a static block"
To solve this issue, you need to assign like the example below I found online,
Note: Static code blocks run before the constructor.
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you