Skip to main content
howard zien (Business Logic) 님이 #Apex에 질문했습니다
i am trying to loop thu an object 2 ways . the wrong way with a lop and the right way with a list.

neither one works.

the wrong way, with a loop looks like this.

// First get the new invoice statement

integer i = 0;

for (invoice_statement__c[] inv : [SELECT id FROM Invoice_Statement__c]);

     {

//WHERE Description__c='My new invoice'];

   system.debug(inv.id );

     }

i get this error message.

Line: 7, Column: 14

Variable does not exist: inv.id

i am too confused to write the syntax with a list. and could use some help.

 
답변 3개
  1. 2015년 10월 3일 오전 5:03
    Hi Howard,

    Please use the below code syntax as per your requirement :

    integer i = 0;

    for (invoice_statement__c inv : [SELECT id FROM Invoice_Statement__c WHERE Description__c = 'My new invoice']){

    system.debug(inv.id );

    }

    The query will return records in chunk and assign a single instance of it to the

    "inv" varibale.

    Now you can use this inv varibale to perform action on the record.

    Let me know if you need more help on this.

    Thanks,

    Abhishek
0/9000