You need to sign in to do that
Don't have an account?
Cmoutes
Rollup Summary Trigger Help
I am trying to create an Apex Trigger that performs a Rollup from a custom object to Contacts. Here is the error that I am receiving: Didn't understand relationship 'Assignments__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.
Below is the code:
Here is a snip of the Child Relationship name:
Any and all help would be greatly appreciated!
Below is the code:
trigger RollupActiveAssigmentLevelsToContact on pse__Assignment__c (after insert, after update, after delete) { set<Id> set_id = new set<Id>(); List<Contact> con_list = new List<Contact>(); if(trigger.isInsert || trigger.isUpdate){ for(pse__Assignment__c myAssignment : trigger.New) { set_id.add(myAssignment.pse__Resource__c); } } else if(trigger.isDelete){ for(pse__Assignment__c myAssignment : trigger.Old){ set_id.add(myAssignment.pse__Resource__c); } } if(trigger.isAfter && (trigger.isInsert || trigger.isUpdate || trigger.isDelete)){ con_list = [SELECT id,Total_Levels__c, (SELECT id,name FROM Assignments__r WHERE Active_Assignment__c = TRUE) FROM Contact WHERE id IN :set_id]; for(Contact con : con_list){ if(con.Assignments__r.size()>0) con.Total_Levels__c = con.Assignments__r.size(); else con.Total_Levels__c = 0; } if(!con_list.isEmpty()) update con_list; } }
Here is a snip of the Child Relationship name:
Any and all help would be greatly appreciated!
Please refer the below trigger to count child records and make changes according to your requirement.
In the below example, I am counting the contacts of an Account. Here "Number_of_Contacts__c" is custom field of Account object.
trigger CountContacts on Contact (after update, after insert, after delete, after undelete)
{
Set<id> accountIds = new Set<id>();
if(Trigger.IsInsert || Trigger.IsUndelete || Trigger.IsUpdate)
{
for(Contact con: Trigger.new)
{
accountIds.add(con.AccountId);
}
}
if(Trigger.isDelete)
{
for(Contact con:Trigger.old)
{
accountIds.add(con.AccountId);
}
}
List<Account> accList = [select Id, Number_of_Contacts__c, (select Id from Contacts) from Account
where Id IN :accountIds];
for(Account acc:accList)
{
acc.Number_of_Contacts__c=acc.contacts.size();
}
update accList;
}
Please mark it as best answer if it is helped you on resolving the issue.
Thank You,
Sohel Mohd
I have verified that I have access to the object and to the Contact lookp field on the Assignment obect. And no Yuchen it is supposed to be Assigments__r the pse_ does not need to be on the front. Any other ideas lol I am lost