function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShashankShashank 

Apex with inner class not compiling

Hi,

When I execute anonymous the following ..

 

 

class A {
 class B {
 }
}

 .. it does not compile but fails with message 

 

Compile error at line 2 column 0
unexpected token: 'class'

 

Compile error at line 2 column 0unexpected token: 'class'

 

The same design pattern works in a controller class.

 

Any explanations?

 

TIA

 

Best Answer chosen by Admin (Salesforce Developers) 
gm_sfdc_powerdegm_sfdc_powerde

execute anonymous block does not support declaring classes or methods on the fly.  It was meant to write few lines of code and test it out quickly without having to create a VF page. 

All Answers

gm_sfdc_powerdegm_sfdc_powerde

execute anonymous block does not support declaring classes or methods on the fly.  It was meant to write few lines of code and test it out quickly without having to create a VF page. 

This was selected as the best answer
ShashankShashank

Oh ok.

Thanks!

 

I would quite prefer to have a full fledged test bed to try out the design patterns before implementing in the real Apex classes. Anyways, thanks for clarifying.

harry63harry63

hI i had an asynchronous class contains two methods.so i used to @future calls for those. i am posting my trigger code and asynchronous class.could you please help me.

Thanks in Advance

trigger code

trigger open120 on Opportunity (before insert, aft er update) 
{

 if(trigger.isinsert){
list<String> OpportunityAccountIds = new list<Stri ng>(); 
for(opportunity opp:trigger.new)
{OpportunityAccountIds.add(opp.Accountid);}
opp120.opp120Method(OpportunityAccountIds);}

else{
list<String> OpportunityAccountIds = new list<String>(); 
list<String> OpportunityOldAccountIds = new list<String>(); 
for(opportunity opp:trigger.new)
{OpportunityAccountIds.add(opp.Accountid);}
for(opportunity opp:trigger.old)
{OpportunityOldAccountIds.add(opp.Accountid);}

opp120.opp120Method(OpportunityAccountIds);  //getting error too many future calls:11 at this line
opp120.opp120OldMethod(OpportunityOldAccountIds);}


}

 

 

asynchronous class

public class opp120{
@future(callout=true) 
public static void opp120Method(list<String> OpportunityAccountIds){ 
list<Opportunity>lstOpp =[select Id, StageName,Expiry_Date__c from Opportunity where AccountId IN :OpportunityAccountIds];  

for(Account ac:[select id,No_of_Open_Deals_in_Next_120_Days__c from Account where id in :OpportunityAccountIds])
{
integer i=0;
 for(Integer j = 0; j < lstOpp.size(); j++)  {
if((lstopp[j].StageName=='Prospecting'||lstopp[j].StageName=='Renewal'||lstopp[j].StageName=='Submission')&&(lstopp[j].Expiry_Date__c>=System.today()+120))
{
i++;
}
ac.No_of_Open_Deals_in_Next_120_Days__c=i;
}update ac;
}
}
@future(callout=true)
public static void opp120OldMethod(list<String> OpportunityOldAccountIds){ 
list<Opportunity>lstOpp = [select Id, StageName,Expiry_Date__c from Opportunity where AccountId IN :OpportunityOldAccountIds];  

for(Account ac:[select id,No_of_Open_Deals_in_Next_120_Days__c from Account where id in :OpportunityOldAccountIds])
{
integer i=0;
 for(Integer j = 0; j < lstOpp.size(); j++)  {
if((lstopp[j].StageName=='Prospecting'||lstopp[j].StageName=='Renewal'||lstopp[j].StageName=='Submission'||lstopp[j].StageName=='ClosedLost'||lstopp[j].StageName=='ClosedWon')&&(lstopp[j].Expiry_Date__c>=System.today()+120))
{
i++;
}
ac.No_of_Open_Deals_in_Next_120_Days__c=i;

}update ac;
}
}

}