Skip to main content
Hi and thanks in advance,

I have 2 goals here:

  • get a List Value and assign to a variable.
  • If record not found, do nothing, go to the next record. (This works)
Note: I can access the variable through acc.id

if query without a list, but I get an error when a record is not found and it won't go to the next record. For example,

Account acc = [SELECT id, OwnerId, Name, AccountNumber FROM Account where AccountNumber =:ReferenceId];

Load list through query: (does not throw exception if record not found)

List<Account> acc = [SELECT id, OwnerId, Name, AccountNumber FROM Account where AccountNumber =:ReferenceId];

Access id value code (Does not work)

newcase.AccountId = acc.id;

Error:

Variable does not exist: id

Regards,

Eric

 
2 answers
  1. Nov 17, 2020, 9:25 PM
    In case anyone needs this.

     

    newcase.AccountId = acc[0].id;

     
0/9000