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
Natasha AliNatasha Ali 

No Syntax error in Apex class but dev console is showing Unexpected token '{'. error??

Hi,
I have the following controller which seems fine in terms of syntax but I'm still getting an error? I only added a StageName to the SOQL (the original controller deployed fine without it):
 
public class OpportunityVFController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityVFController {
        opp = [SELECT Id, Name, CreatedDate, Pathway__c, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
        NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, 
                Key_Responsibilities__c, Skills_Required__c, Account.Name, Employer_Name__c,  Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
        WHERE (StageName = '1 - Qualifying'or StageName = '2 - Booked for CK' or StageName = '3 - Live'
                or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice') AND (Post_Ad__c = TRUE)];
          }
}

The original deployed one:
public class OpportunityVFController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityVFController {
        opp = [SELECT Id, Name, CreatedDate, Pathway__c, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
        NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, 
                Key_Responsibilities__c, Skills_Required__c, Account.Name, Employer_Name__c,  Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
        WHERE (StageName = '2 - Booked for CK' or StageName = '3 - Live'
                or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice') AND (Post_Ad__c = TRUE)];
          }
    
}
Any help is much appreciated!
Many Thanks,
Natasha :)
 
Best Answer chosen by Natasha Ali
Deepali KulshresthaDeepali Kulshrestha
Hi Natasha,

The issue is that your object creation syntax is wrong.constructors are method calls and also require parentheses.
Try the following code it may be helpful for you:
public class OpportunityVFController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityVFController (){
        opp = [SELECT Id, Name, CreatedDate, Pathway__c, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
        NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, 
                Key_Responsibilities__c, Skills_Required__c, Account.Name, Employer_Name__c,  Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
        WHERE (StageName = '1 - Qualifying'or StageName = '2 - Booked for CK' or StageName = '3 - Live'
                or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice') AND (Post_Ad__c = TRUE)];
          }
}
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
 

All Answers

Natasha AliNatasha Ali
Here is the error:
User-added image
Deepali KulshresthaDeepali Kulshrestha
Hi Natasha,

The issue is that your object creation syntax is wrong.constructors are method calls and also require parentheses.
Try the following code it may be helpful for you:
public class OpportunityVFController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityVFController (){
        opp = [SELECT Id, Name, CreatedDate, Pathway__c, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
        NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, 
                Key_Responsibilities__c, Skills_Required__c, Account.Name, Employer_Name__c,  Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
        WHERE (StageName = '1 - Qualifying'or StageName = '2 - Booked for CK' or StageName = '3 - Live'
                or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice') AND (Post_Ad__c = TRUE)];
          }
}
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
 
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Natasha,
You have to add () in a constructor.Try  the below code:
public class OpportunityVFController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityVFController() {
        opp = [SELECT Id, Name, CreatedDate, Pathway__c, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
        NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, 
                Key_Responsibilities__c, Skills_Required__c, Account.Name, Employer_Name__c,  Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
        WHERE (StageName = '2 - Booked for CK' or StageName = '3 - Live'
                or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice') AND (Post_Ad__c = TRUE)];
          }
    
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi