• caangus
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hello,

I am trying to create a map of child objects as they relate to the parent object for a trigger.

I have the standard Contract object, and a custom Time Entry Object. When a Time Entry is created, udpated, or deleted my trigger kicks off and grabs all Time Entries associated with the Contract. It will then calculate the Total Time Entered and the Total Value and update this on the Contract. My current  method works, however I'm running into governor limit exceptions. Best practices states I should use a map instead of multipl SQL calls in a for loop. I've followed some examples online using this method however I am getting the error.

sObject type 'ContractwithTime' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

Code:
trigger trg_TimeEntryRollupToContract on Time_Entry__c (after delete, after insert, after update) 
{
    double dblTotalHours = 0.0;
    double curTotalValue = 0.00;


    if(Trigger.isInsert||Trigger.isUpdate||Trigger.isDelete)
    { 
        //***********************************************
        //New Record
        //***********************************************
           
        if(Trigger.isInsert)
        { 


           List<Contract> ContractwithTime = [SELECT Id, Total_Time_Entry_Value__c, Total_Time_Entry_Hours__c,
                                                    (SELECT Id, Total_Time__c, Total_Entry_Value__c FROM TimeEntry__r)
                                                    FROM ContractwithTime WHERE Id IN :Trigger.newMap.KeySet()];
            
            for(Contract con : ContractwithTime){
                for(TimeEntry__c ti : ContractwithTime.Time_Entry__r){
                    	if (ti.Total_Time__c == null) ti.Total_Time__c = 0;
                        dblTotalHours += ti.Total_Time__c;
                        if(ti.Time_Entry_Value__c!=null) curTotalValue += ti.Time_Entry_Value__c;
                        if(dblTotalHours > 0) contractwithTime.Total_Time_Entry_Hours__c = dblTotalHours;
;
                        contractwithTime.Total_Time_Entry_Value__c = curTotalValue;
                }
            }
}



 

Hello,

 

We've reached out limit of Rollups on our Project object. I need to code a roll up manually.

 

My goal is to calculate the total of all billing events per Project and update a field on Project called "Total Invoiced to Date". I'm trying to figure out the suedo code before I begin and would greatly appreciate any info more experienced coders can give. I believe it should look something like

 

trigger trg_RollupBillgEventsToProject on CCI_Invoice__c (after delete, after insert) {
	
	//*********************************
	//CCI_Project__c is parent (record to be updated)
	//CCI_Invoice__c is the roll-up object (counting the total invoiced to date and adding them to the parent record)
	
	//Create a variable to hold the total of billing events associated with the project
	double dblTotalBillingEvents = 0;
	
	//CCI_Project__c is Parent (record to be updated)
	//CCI_Invoice__c is the roll-up object (counting the sum of Total_Invoice_Value__c in all billing events)
	
	//Create a new instance of the Project Object
	CCI_Project__c [] projectToUpdate = new CCI_Project__c[]{};
	
	//******************************
	//New Records
	//******************************
	if(Trigger.isInsert||Trigger.isDelete){
		
		if(Trigger.isInsert){
			
			for(CCI_Invoice__c be: childObjectNew ){

				!!! How would I collect the billing events? !!!!

				dblTotalBillingEvents += be.Total_Invoice_Value__c;
			}

			projectToUpdate.Total_Invoiced_to_date = dblTotalBillingEvents;
		}
	}
}
                   

 Above I'm trying to figure out the insert first, than I'll move on to updates and deletes.

 

Thanks!

Hello,

I am trying to create a map of child objects as they relate to the parent object for a trigger.

I have the standard Contract object, and a custom Time Entry Object. When a Time Entry is created, udpated, or deleted my trigger kicks off and grabs all Time Entries associated with the Contract. It will then calculate the Total Time Entered and the Total Value and update this on the Contract. My current  method works, however I'm running into governor limit exceptions. Best practices states I should use a map instead of multipl SQL calls in a for loop. I've followed some examples online using this method however I am getting the error.

sObject type 'ContractwithTime' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

Code:
trigger trg_TimeEntryRollupToContract on Time_Entry__c (after delete, after insert, after update) 
{
    double dblTotalHours = 0.0;
    double curTotalValue = 0.00;


    if(Trigger.isInsert||Trigger.isUpdate||Trigger.isDelete)
    { 
        //***********************************************
        //New Record
        //***********************************************
           
        if(Trigger.isInsert)
        { 


           List<Contract> ContractwithTime = [SELECT Id, Total_Time_Entry_Value__c, Total_Time_Entry_Hours__c,
                                                    (SELECT Id, Total_Time__c, Total_Entry_Value__c FROM TimeEntry__r)
                                                    FROM ContractwithTime WHERE Id IN :Trigger.newMap.KeySet()];
            
            for(Contract con : ContractwithTime){
                for(TimeEntry__c ti : ContractwithTime.Time_Entry__r){
                    	if (ti.Total_Time__c == null) ti.Total_Time__c = 0;
                        dblTotalHours += ti.Total_Time__c;
                        if(ti.Time_Entry_Value__c!=null) curTotalValue += ti.Time_Entry_Value__c;
                        if(dblTotalHours > 0) contractwithTime.Total_Time_Entry_Hours__c = dblTotalHours;
;
                        contractwithTime.Total_Time_Entry_Value__c = curTotalValue;
                }
            }
}