+ Start a Discussion
kumar.apr10kumar.apr10 

getting Unexpected token '<' error

Hi,
I am getting unexpected toke '<' error in Row 1 column 5 position in open execute anonymous windows when I am trying to execute the below code

list<apex_invoice__c> listinv = new list<apex_invoice__c>;
listinv = [select name, id, apex_customer__r.name  from apex_invoice__c];
for(apex_invoice__c objinv: listinv)
{
    system.debug('name is: ' + objinv.apex_customer__r.name);
}

I am not sure what exactly  the issue is. Can you please help me to correct the code?

Thanks,
Praveen
Best Answer chosen by kumar.apr10
Raj VakatiRaj Vakati
list<apex_invoice__c> listinv = new list<apex_invoice__c>();
listinv = [select name, id, apex_customer__r.name  from apex_invoice__c];
for(apex_invoice__c objinv: listinv)
{
    system.debug('name is: ' + objinv.apex_customer__r.name);
}

You need to do it like constructor  () 

All Answers

Raj VakatiRaj Vakati
Try this ..first line is worng
 
list<apex_invoice__c> listinv = new list<apex_invoice__c>();
listinv = [select name, id, apex_customer__r.name  from apex_invoice__c];
for(apex_invoice__c objinv: listinv)
{
    system.debug('name is: ' + objinv.apex_customer__r.name);
}

 
Raj VakatiRaj Vakati
list<apex_invoice__c> listinv = new list<apex_invoice__c>();
listinv = [select name, id, apex_customer__r.name  from apex_invoice__c];
for(apex_invoice__c objinv: listinv)
{
    system.debug('name is: ' + objinv.apex_customer__r.name);
}

You need to do it like constructor  () 
This was selected as the best answer
kumar.apr10kumar.apr10
Thank you. It's working now
Raj VakatiRaj Vakati
close this thread!