function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak Sharma 184Deepak Sharma 184 

trigger error- anybody help.

Have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fields total actual cost. means all the "total actual cost" fields of different projects associated with the "project portfolio" should come into "total actual cost" field of "project portfolio" object.

Both the objects have same fields.

API Names- 

Project- CloudbyzITPM__Project__c
Project Portfolio- CloudbyzITPM__Project_Portfolio__c
Field name- CloudbyzITPM__Total_Actual_Cost__c

below is my code and iam getting error- "Didn't understand relationship 'Projects__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".


trigger UpdateTotalActualCosts on CloudbyzITPM__Project__c (after insert,after update, after delete,after undelete) {

  List<id> QuotationsIds = new List<id>();

    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){

        For(CloudbyzITPM__Project__c con1 : Trigger.new){

            QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);

        }

    }

    if(Trigger.isDelete){

        For(CloudbyzITPM__Project__c con1 : Trigger.old){

            QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);

        }

    }

    List<CloudbyzITPM__Project_Portfolio__c> QuotationsToUpdate = new List<CloudbyzITPM__Project_Portfolio__c>();

    decimal sum = 0;

    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){

        For(CloudbyzITPM__Project_Portfolio__c q : [select CloudbyzITPM__Total_Actual_Cost__c,(SELECT id,CloudbyzITPM__Total_Actual_Cost__c  FROM Projects__r) FROM CloudbyzITPM__Project_Portfolio__c WHERE id =: QuotationsIds]){

            sum = 0;

            for(CloudbyzITPM__Project__c p : q.Projects__r)
                sum = sum + p.CloudbyzITPM__Total_Actual_Cost__c ;

            q.CloudbyzITPM__Total_Actual_Cost__c = sum;

            QuotationsToUpdate.add(q);

        }

        try{

            update QuotationsToUpdate ;

        }Catch(Exception e){

            System.debug('Exception :'+e.getMessage());

        }

    }

}
UC InnovationUC Innovation
Hi Deepak,

I think you just put the wrong relationship name. Go to your project object's field list, and find the lookup field to project portfolio. There if you go to the detail page, you should see a field called child relationship name. That's the name you want to use in your query.
Deepak Sharma 184Deepak Sharma 184
Hi UC Innovation,

iam putting that only child relationship name in my trigger. Project>fields>project portfolio> child relationship name- Project.


 
UC InnovationUC Innovation
If it's Project, then you should use Project__r in your query. You're using Projects__r. Maybe that's the issue? Your error message indicates that it's just a naming spelling error, not a syntax/logic error.
Deepak Sharma 184Deepak Sharma 184
Hi UC Innovation,

Can u help me in this.

i have a same scenerio-

there r two objects "project member" and "resource" in which under "project member" object i have to update the field "hour rate" with "resource" object field "hour cost", when something is written in "hour cost" field, otherwise "hour rate" field not update and able to enter something and save it.

i have written a code here-

public class updateHourlyRate
{
  public static list< CloudbyzITPM__Resource__c> affectedRec= new list<CloudbyzITPM__Resource__c>();
    public static set<id> afc1 = new set<id>();
    public static void processAfterUpdateOrInsertHourlyRate();
    {
        affectedRec = (list<CloudbyzITPM__Resource__c>)Trigger.New;
        if(affectedRec.size()>0)
        {
            for(CloudbyzITPM__Resource__c aff1 : affectedRec)
            {
                afc1.add(aff1.CloudbyzITPM__Hourly_Cost__c);
            }
        }
        CloudbyzITPM__Resource__c fn1 = [select id, CloudbyzITPM__Hourly_Cost__c from CloudbyzITPM__Resource__c where id in:afc1 limit 1];
         list<CloudbyzITPM__Team_Member__c> affectedRec1 = [select id, name,CloudbyzITPM__Resource__c,CloudbyzITPM__Hourly_Cost__c,CloudbyzITPM__Hourly_Rate__c from CloudbyzITPM__Team_Member__c where CloudbyzITPM__Resource__c = :fn1.Id];
    Decimal i=0;
        
  
    if(affectedRes1.size()>0)
    {
        for(CloudbyzITPM__Team_Member__c aff1: affectedRec1)
        {
            i = i + aff1.CloudbyzITPM__Hourly_Cost__c;
        }
    }
    
    if(i>0){
     System.debug('@@pBUFinal@@');
    fn1.CloudbyzITPM__Hourly_Rate__c = i;
    }
     update fn1; 
      System.debug('@@fn4@@'+fn1);
    }

}


API name are-

Project member- "CloudbyzITPM__Team_Member__c"
Resource- "CloudbyzITPM__Resource__c"
Hour Cost-"CloudbyzITPM__Hourly_Cost__c"
Hour Rate- "CloudbyzITPM__Hourly_Rate__c"

error is - 

No such column 'CloudbyzITPM__Hourly_Cost__c' on entity 'CloudbyzITPM__Team_Member__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.