Я новичок в Apex и SOQL.
Я хочу получить данные из учетной записи и контактов контактов с помощью SOQL, передать результаты в список.
Из списка я хочу «получить» данные из результатов «Учетные записи внешнего запроса» и из внутреннего запроса (из «Контактов»). Как мне это сделать?
This is what I tried, I do not know how to proceed further.
integer counter = 0;
string accountId;
string accountName;
List<Account> myAccts = [SELECT Id, Name, (Select Id, Name from Contacts) from Account];
for(Account i :myAccts) {
//System.debug(i);
Account currentAccount = myAccts.get(counter);
accountId = currentAccount.Id;
accountName = currentAccount.Name;
System.debug('This is the current account record---' + accountName);
counter = counter+1;
}
// SOQL to retrieve Accounts and related Contacts
List<Account> myAccts = [SELECT Id, Name, (Select Id, Name from Contacts) from Account];
// Loop through each Account
for (Account acct : myAccts) {
// Example of referencing Account field
system.debug(acct.Name);
// Loop through each related Contact
for (Contact con : acct.Contacts) {
// Example of referencing Contact field
system.debug(con.Name);
}
}
Большое спасибо Скарнеги! Я очень благодарен.