trigger ABCD on Account(after insert, after update) {
List < Account > AccList = [Select id, (Select Id, Status__c from Clients__r) from Account WHERE Id IN: trigger.new];
for (Account acc: AccList) {
Integer Field1 = 0;
for (Client__c pc: acc.Clients__r) {
If(Status__c != 'Lapsed') {
Field1=Field1+1;
}
acc.Field1__c = Field1;
}
}
}
Purpose -
I want to increase the count of a people in the object Account which has a lookup with another object. So I want to traverse the related list records, check if a field value is equal to lapsed, if No - increase the count.
Error -
Didn't understand relationship 'LookupNameinAccount__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Question -
- I was reading articles on the relationship name . But not sure what exactly I need to use . I am currently using the name in the Fields section .
- Is this code overall okay?