Как получить поле со ссылкой на другой объект по имени.
Например,
Contact[] contacts = [Select Name, Account.Name From Contact Limit 1];
String accountName1 = (String)contacts[0].get('Account.Name'); // Ошибка
String accountName2 = contacts[0].Account.Name; // Все ок
Кто-нибудь пробовал что-то подобное сделать?
Как получить поле со ссылкой на другой объект по имени. Например, Contact[] contacts = [Select Name, Account.Name From Contact Limit 1]; String accountName1 = (String)contacts[0].get('Account.Name'); // Ошибка String accountName2 = contacts[0].Account.Name; // Все ок Кто-нибудь пробовал что-то подобное сделать?
32.0 APEX_CODE,ERROR;APEX_PROFILING,ERROR
Execute Anonymous: Contact[] contacts = [Select Name, AccountId, Account.Name From Contact Limit 1];
Execute Anonymous:
Execute Anonymous: String accountName1 = contacts[0].Account.Name;
Execute Anonymous: Id accountId = contacts[0].AccountId;
Execute Anonymous:
Execute Anonymous:
Execute Anonymous: system.debug(LoggingLevel.Error, accountName1);
Execute Anonymous: system.debug(LoggingLevel.Error, accountId);
16:27:51.057 (57166045)|EXECUTION_STARTED
16:27:51.057 (57177189)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
16:27:51.115 (115216244)|USER_DEBUG|[7]|ERROR|ליאת ניסיון
16:27:51.115 (115290264)|USER_DEBUG|[8]|ERROR|001g000000JYPFJAA5
16:27:51.115 (115359578)|CODE_UNIT_FINISHED|execute_anonymous_apex
16:27:51.117 (117834339)|EXECUTION_FINISHED
Не совсем понял в чем проблема ?
[quote="Gres"]Contact[] contacts = [Select Name, Account.Name From Contact Limit 1]; String accountName1 = (String)contacts[0].get('Account.Name'); // Ошибка [/quote] 32.0 APEX_CODE,ERROR;APEX_PROFILING,ERROR Execute Anonymous: Contact[] contacts = [Select Name, AccountId, Account.Name From Contact Limit 1]; Execute Anonymous: Execute Anonymous: String accountName1 = contacts[0].Account.Name; Execute Anonymous: Id accountId = contacts[0].AccountId; Execute Anonymous: Execute Anonymous: Execute Anonymous: system.debug(LoggingLevel.Error, accountName1); Execute Anonymous: system.debug(LoggingLevel.Error, accountId); 16:27:51.057 (57166045)|EXECUTION_STARTED 16:27:51.057 (57177189)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex 16:27:51.115 (115216244)|USER_DEBUG|[7]|ERROR|ליאת ניסיון 16:27:51.115 (115290264)|USER_DEBUG|[8]|ERROR|001g000000JYPFJAA5 16:27:51.115 (115359578)|CODE_UNIT_FINISHED|execute_anonymous_apex 16:27:51.117 (117834339)|EXECUTION_FINISHED Не совсем понял в чем проблема ?
Contact[] contacts = [Select Name, Account.Name From Contact Limit 1];
String accountName1 = (String)contacts[0].getSObject('Account').get('Name');
Contact[] contacts = [Select Name, Account.Name From Contact Limit 1]; String accountName1 = (String)contacts[0].getSObject('Account').get('Name');
[quote="Дима Лисовский"]Contact[] contacts = [Select Name, Account.Name From Contact Limit 1]; String accountName1 = (String)contacts[0].getSObject('Account').get('Name');[/quote] Спасибо
String accountName1 = (String)contacts[0].get('Account.Name'); // Ошибка
[quote="wilder"][quote="Gres"]Contact[] contacts = [Select Name, Account.Name From Contact Limit 1]; String accountName1 = (String)contacts[0].get('Account.Name'); // Ошибка [/quote] 32.0 APEX_CODE,ERROR;APEX_PROFILING,ERROR Execute Anonymous: Contact[] contacts = [Select Name, AccountId, Account.Name From Contact Limit 1]; Execute Anonymous: Execute Anonymous: String accountName1 = contacts[0].Account.Name; Execute Anonymous: Id accountId = contacts[0].AccountId; Execute Anonymous: Execute Anonymous: Execute Anonymous: system.debug(LoggingLevel.Error, accountName1); Execute Anonymous: system.debug(LoggingLevel.Error, accountId); 16:27:51.057 (57166045)|EXECUTION_STARTED 16:27:51.057 (57177189)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex 16:27:51.115 (115216244)|USER_DEBUG|[7]|ERROR|ליאת ניסיון 16:27:51.115 (115290264)|USER_DEBUG|[8]|ERROR|001g000000JYPFJAA5 16:27:51.115 (115359578)|CODE_UNIT_FINISHED|execute_anonymous_apex 16:27:51.117 (117834339)|EXECUTION_FINISHED Не совсем понял в чем проблема ?[/quote] Вот в этом была проблема String accountName1 = (String)contacts[0].get('Account.Name'); // Ошибка