+ Start a Discussion
Shivani ThaparShivani Thapar 

Anyone know whats wrong with my apex class...

Im trying to create a apex class for all my unpaid invoices... 

anyone know why im getting this error? thanksUser-added image
Shivani ThaparShivani Thapar
here is the code if you cant see it

public class FindunpaidInvoices {
    private final List<Invoice_Consulting__c> invoices;

    public FindunpaidInvoices() {
        invoices = [select Account__c, Invoice_Date__c, Balance_Due__c, from Invoice_Consulting__c = 'Unpaid'];
    }

    public List<Invoice_Consulting__c> getUnpaidInvoices() {
        return invoices;
    }
}
Josh KiddJosh Kidd
I think you have a comma that shouldn't be there following Balance_Due__c.
Shivani ThaparShivani Thapar
ok thanks - new error... "Error: Compile Error: expecting right square bracket, found '=' at line 5 column 98"

heres code: 

 public class FindunpaidInvoices {
    private final List<Invoice_Consulting__c> invoices;

    public FindunpaidInvoices() {
        invoices = [select Account__c, Invoice_Date__c, Balance_Due__c from Invoice_Consulting__c = 'Unpaid'];
    }

    public List<Invoice_Consulting__c> getUnpaidInvoices() {
        return invoices;
    }
}

User-added image
Jerome LusinchiJerome Lusinchi
Hi,

 invoices = [select Account__c, Invoice_Date__c, Balance_Due__c from Invoice_Consulting__c where Name = 'Unpaid'];

you forgot the where criteria and the name of the field for wich the value is 'Unpaid'

Jerome
Shivani ThaparShivani Thapar
Jerome your the master... thank you. worked. 
Josh KiddJosh Kidd
Ok.  You need a WHERE in there as well:  Something Like:


invoices = [select Account__c, Invoice_Date__c, Balance_Due__c from Invoice_Consulting__c WHERE Some_Field__c = 'Unpaid'];

Some_Field__c will be replaced with whichever field on your object you are checking.