+ Start a Discussion
Deepak Sharma 184Deepak Sharma 184 

trigger scenario-

have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fiels 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" 

Both have total actual cost field.

code-

trigger UpdateTotalActualCost on CloudbyzITPM__Project_Portfolio__c (after insert, after update) 
{
    
          List<CloudbyzITPM__Project_Portfolio__c> Portfoliorecords =
         (List<CloudbyzITPM__Project_Portfolio__c>)Trigger.New;
     Set<id> recordId = new Set<id>();
     for(CloudbyzITPM__Project_Portfolio__c  port : Portfoliorecords)
     {
     recordId.add(port.id);
     }

     List<CloudbyzITPM__Project__c> fn = [Select id,
CloudbyzITPM__Total_Costs__c from CloudbyzITPM__Project__c where id IN
:recordId];
     if(fn.size()>0)
     {
     for(CloudbyzITPM__Project__c  affc : fn)
     {
     Portfoliorecords.CloudbyzITPM__Total_Actual_Cost__c =
Portfoliorecords.CloudbyzITPM__Total_Actual_Cost__c +
affc.CloudbyzITPM__Total_Costs__c;
     }
     }
    update Portfoliorecords ;
}




error - "Initial term of field expression must be a concrete SObject: List<CloudbyzITPM__Project_Portfolio__c>"
EldonEldon
Hi

Use below code
 
trigger DevComPob3 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());
        }
    }
}

Regards
Deepak Sharma 184Deepak Sharma 184
hi ,

Same error.