I am creating a class which will eventually update records on a schedule using batch APEX. I am having trouble writing an inner class and have tried every possible combination of syntax that i can think of.
Code:
public with sharing class AddendumsExpired {
public List<Id> opportunityIds{get;set;}
public List<Id> addendumIds{get;set;}
public List<Id> OppIds(){
for(Opportunity thisOpp :[SELECT Id,StageName,Name,Addendum_Amount__c,Addendum_Amount_No_Discounts__c,Agreement_Balance__c FROM Opportunity WHERE (NOT StageName LIKE '%Proposed%') AND (NOT StageName LIKE '%Accepted%')]){
opportunityIds.add(thisOpp.Id);
}
return opportunityIds;
}
public List<Id> AddIds(){
for(Addendum__c thisAdd :[SELECT Id FROM Addendum__c WHERE Opportunity__c IN :opportunityIds AND Expiration__c < TODAY]){
addendumIds.add(thisAdd.Id);
}
return addendumIds;
}
public class debugging {
system.debug('opportunityIds :: '+opportunityIds);
system.debug('addendumIds :: '+addendumIds);
system.debug('OppIds() :: '+OppIds());
system.debug('AddIds() :: '+AddIds());
}
}
I am still in the testing stage, and the debugging class is throwing an error. I will need to have multiple inner classes for the final production deployment.
I have used the syntax above (public class classname {) before without any issues. However, when I execute anonymous this block of code I receive the error:
Compile error at line 24 column 8
unexpected token: 'class'
If anyone can shed some light on this situation I would really appreciate it! I’m puzzled and wondering why that syntax can work in a dozen other classes but not this one.
The code in your class:
is incorrectly placed in the declarations section and not where any actual code should be (excluding statics, getters and setters).
Place the system.debug code within a method inside of your inner-class (perhaps the constructor) and it will compile and run just fine. Of course then you need to instantiate your debugging class first so it has an instance to execute the code it contains.
Like this:
Then you can create an instance to execute these debug statements, passing in your opportunityIds list into the constructor of your inner-class:
EDIT:
Change your getters and setters to the following. These contain proper initialization code for your lists (using retVal to declare a new List in each):