• Cmoutes
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Integration Consultant | Force.com Developer
  • Work Horse Integrrations


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
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:
 
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:

User-added image

Any and all help would be greatly appreciated!
Im not exactly sure what happened, but I followed this project to the tee, also i did the whole thing over again and it isnt working when i run the test with Tim Barr I will post photos below of the process itself. Any help would be greatly appreciated!

Yes it is Active!


User-added image
User-added image
User-added image
 
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:
 
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:

User-added image

Any and all help would be greatly appreciated!
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:
 
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:

User-added image

Any and all help would be greatly appreciated!
Im not exactly sure what happened, but I followed this project to the tee, also i did the whole thing over again and it isnt working when i run the test with Tim Barr I will post photos below of the process itself. Any help would be greatly appreciated!

Yes it is Active!


User-added image
User-added image
User-added image