1
List<APEX_Invoice__c> updatedInvoice new List<APEX_Invoice__c> ();
for (APEX_Invoice__c obj:objInvoice){
    obj.APEX_Invoice__c.Status__c = 'Paid';   
    updatedInvoice.add(obj);
}
update updatedInvoice;

Why is it not working and showing me error like :

Unexpected token '<'.

Can we not enter where clause in SOQL when using it with LIST ?

Note: The field API name is correct. And also when I simply run the Select query it does fetch the data, but does not work with LIST.

0

2 Answers 2

5

As shown in your question, this code contains multiple syntax errors. Syntax errors occasionally cause the Apex compiler to misinterpret your code relative to what you expect, and this may cause it to show errors that don't quite make sense at first glance.

List<APEX_Invoice__c> updatedInvoice new List<APEX_Invoice__c> ();

This line is missing an assignment operator =, which is probably the source of one of the errors you've shown in a revision of this question.

for (APEX_Invoice__c obj:objInvoice){
    obj.APEX_Invoice__c.Status__c = 'Paid';   
    updatedInvoice.add(obj);
}

This is not how you reference a field on an object. You would simply do obj.Status__c = ....

1
  • Thanks David Reed It was the = missed Commented May 15, 2021 at 14:51
3

Your code has syntax errors...

This

List<APEX_Invoice__c> updatedInvoice new List<APEX_Invoice__c> (); should be

List<APEX_Invoice__c> updatedInvoice = new List<APEX_Invoice__c> ();

And this line...

obj.APEX_Invoice__c.Status__c = 'Paid'; should be...

obj.Status__c = 'Paid';

1
  • Thanks @jan julian It was the = missed Commented May 15, 2021 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .