Есть выборка и цикл:
for (Contact c : [SELECT Id, (SELECT Event.ActivityDate FROM EventRelations allrows WHERE isdeleted = false and Event.ActivityDate!=NULL AND Event.ActivityDate<TODAY AND Event.Type IN :lastOnsiteVisit AND Event.OwnerId IN: RetUserId ORDER BY Event.ActivityDate DESC LIMIT 1) FROM Contact WHERE Id IN :newContacts.keySet()]) {
if (!c.EventRelations.isEmpty()) {
newContacts.get(c.Id).Last_Onsite_Visit__c = c.EventRelations[0].Event.ActivityDate;
}
}
Есть выборка и цикл: [code] for (Contact c : [SELECT Id, (SELECT Event.ActivityDate FROM EventRelations allrows WHERE isdeleted = false and Event.ActivityDate!=NULL AND Event.ActivityDate<TODAY AND Event.Type IN :lastOnsiteVisit AND Event.OwnerId IN: RetUserId ORDER BY Event.ActivityDate DESC LIMIT 1) FROM Contact WHERE Id IN :newContacts.keySet()]) { if (!c.EventRelations.isEmpty()) { newContacts.get(c.Id).Last_Onsite_Visit__c = c.EventRelations[0].Event.ActivityDate; } } [/code] Данная выборка не рабочая. Точнее не совсем рабочая, из за ограничений SF я не могу тут выбрать поля Event в выборке EventRelations. Могу только - [SELECT Id, (SELECT EventID FROM EventRelations allrows WHERE isdeleted = false) FROM Contact WHERE Id IN :newContacts.keySet()] Задача: повторить функционал выборки и цикла, но при условии что можно выбрать только EventID у EventRelations. Буду очень рад если кто то додумается.... Сам тоже капаю...
такой вариант приемлем?
List<SObject> contactRelatedEvents =[
SELECT
WhoId, ActivityDate
FROM Event ALLROWS
WHERE
IsDeleted = false AND
Event.ActivityDate != NULL AND
Event.ActivityDate < TODAY AND
WhoId IN :newContacts.keySet() AND
Event.Type IN :lastOnSiteVisit AND
Event.OwnerId IN :retUserId
GROUP BY WhoId, ActivityDate
ORDER BY ActivityDate DESC
LIMIT :newContacts.keySet().size()
];
for(SObject event : contactRelatedEvents) {
newContacts.get((Id)event.get('WhoId')).Last_Onsite_Visit__c = (Date)event.get('ActivityDate');
}
такой вариант приемлем? [code]List<SObject> contactRelatedEvents =[ SELECT WhoId, ActivityDate FROM Event ALLROWS WHERE IsDeleted = false AND Event.ActivityDate != NULL AND Event.ActivityDate < TODAY AND WhoId IN :newContacts.keySet() AND Event.Type IN :lastOnSiteVisit AND Event.OwnerId IN :retUserId GROUP BY WhoId, ActivityDate ORDER BY ActivityDate DESC LIMIT :newContacts.keySet().size() ]; for(SObject event : contactRelatedEvents) { newContacts.get((Id)event.get('WhoId')).Last_Onsite_Visit__c = (Date)event.get('ActivityDate'); }[/code]
К сожалению нет( Есть определённые ограничения самого SF. Выбрать могу только айдишку.
[quote="d9d9_homer"]такой вариант приемлем? [code]List<SObject> contactRelatedEvents =[ SELECT WhoId, ActivityDate FROM Event ALLROWS WHERE IsDeleted = false AND Event.ActivityDate != NULL AND Event.ActivityDate < TODAY AND WhoId IN :newContacts.keySet() AND Event.Type IN :lastOnSiteVisit AND Event.OwnerId IN :retUserId GROUP BY WhoId, ActivityDate ORDER BY ActivityDate DESC LIMIT :newContacts.keySet().size() ]; for(SObject event : contactRelatedEvents) { newContacts.get((Id)event.get('WhoId')).Last_Onsite_Visit__c = (Date)event.get('ActivityDate'); }[/code][/quote] К сожалению нет( Есть определённые ограничения самого SF. Выбрать могу только айдишку.