• SeanCo
  • NEWBIE
  • 75 Points
  • Member since 2010

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 18
    Replies

Is there a way to restrict users from adding tabs to a App in SF?  In otherwords, can you configure a particular app in SF to omit the 'All Tabs' link in order to prevent users from adding additional tabs to a custom app?

 

 

Hope that makes sense and thanks in advance!

 

~ Sean

I am in the process of setting a custom app which contains a couple of custom tabs (referencing VF pages / custom list view).  Ideally we are trying to limit how the user can navigate within the custom app/tabs.  One thing I notices is that after creating a new object the page layout contains the following link at the top of the page:

 

 

 

 

Is there a way, using built in features, to prevent the link from displaying on the page layout?  The problem is that the link directs user back to the default object view list instead of the custom view we have associated with the app tab.  Hope that makes sense and thanks in advnace!

Does anyone know if ProjectForce (http://code.google.com/p/projectforce/) is still avialable in any form?  I checked on AppExchange and no search resutls were found.  Thanks in advance!

 

~ Sean

 

  • February 11, 2011
  • Like
  • 0

Hi,

 

I am trying to see if it is possible to dynamically insert the current month into the 'subject' line of a VisualForce email template.  More specifically, I need to display the month in 'MMMMM' format (Ex:  December).  I am aware that the following expressions work:

 

 

  • {!TODAY()}
  • {!MONTH(TODAY())}
  • {!DAY(TODAY())}
  • {!YEAR(TODAY())}

 

 

Example:

 

 

<messaging:emailTemplate subject="{!MONTH(TODAY())} This is my subject!" 
recipientType="Contact"
relatedToType="Custom_Object__c"
replyTo="everyone@world.com" >

 

Any way to format the date in 'MMMMM' format (Ex:  December)?

 

Thanks in advance!

 

  • January 28, 2011
  • Like
  • 0

Currently, we have a custom object containing a custom button linking to a VisualForce email template; when the button is selected it performs a mail merge collecting all the needed data from the custom object to the email template.  We then send the email template, one by one, from each custom object record (as needed).  This was phase one for us and up next we would like to further automate this process by being able to send all the emails in bulk.  We would still need to collect (merge) data unique to each custom object record and email to the appropriate contact(s).  I am just in the research/planning stages for this so I am not looking for a step by step solution here.  If you can provide any tips, advice, references to specific documentation/examples it would be greatly appreciated?  Thanks in advance!

  • October 28, 2010
  • Like
  • 0

I am trying to figure out how to test fields (included within a apex:repeat) to see if they are blank, or null, and if so display some alternate text (Ex: No records to display) in the table instead of a blank table.  Example code snippet below:

 

 

<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
   <tr>
    <td>
	<apex:outputField value="{!auditList.Audit_Type__c}" />
    </td>
    <td>
       	<apex:outputField value="{!auditList.Delivery_Date__c}" />
    </td>
    <td>
	<apex:outputField value="{!auditList.Review_Date__c}" />
    </td>
   </tr>
</apex:repeat>

 

Thanks for any help or suggestions! 

 

  • August 09, 2010
  • Like
  • 0

I am working on outputting a custom object to PDF by Email/VisualForce template.  So far I have been successful with everything, but just ran across something that I need help with.  As part of the PDF we are including four related lists that display on the objects page view.  All the related lists contain fields from a single object except one.  One of the related lists displays fields from two custom objects (Training_Attendee__c & Training_Course__c) on the page view.  On the object this relationship is formed by a lookup field from the 'Training_Attendee__c'  object to the 'Training_Course__c' object.  This is what I am having trouble with.  For the other three related lists I ran a apex:repeat and associated it with the single object that was needed and that worked fine...code example below:


<apex:repeat var="cx" value="{!relatedTo.Cases__r}">     
   <tr>
    <td>
       {!cx.CaseNumber}
    </td>
    <td>
       {!cx.Subject}
    </td>
    <td>
       {!cx.Case_Hours__c}
    </td>
   </tr>
</apex:repeat>


Except now that I need to pull data from two objects I am not sure how to associate both objects to the same apex:repeat statement ...current code example for this particular related list is below:

 

<apex:repeat var="IGXTraining" value="{!relatedTo.Training_Attendee__r}">
   <tr>
    <td>
       <apex:outputField value="{!IGXTraining.Name}" />
    </td>
    <td>
       <apex:outputField value="{!IGXTraining.Training__c}" />
    </td>
    <td>
	// value is from another custom object (Training_Course__c)
	// association is by lookup field on Training_Attendee__c to Training_Course__c
       {Location}
    </td>
    <td>
	// value is from another custom object (Training_Course__c)
	// association is by lookup field on Training_Attendee__c to Training_Course__c
       {StartDate}
    </td>
    <td>
       <apex:outputField value="{!IGXTraining.Course_Credit__c}" />
    </td>
   </tr>
</apex:repeat>

 

On the related list it automatically makes the association between the two objects so you can list fields from both on the page view:

 

 

 

Is it possible to associate a two object relationship using apex:repeat?  If so any examples would really be appreciated.  Thanks in advance!

Trying to solve one last problem on a trigger I am working on. Currently, the trigger works fine on 'insert' and 'delete', but generating the following error message when 'updating':

 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger rollupCaseHoursTo360 caused an unexpected exception, contact your administrator: rollupCaseHoursTo360: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.rollupCaseHoursTo360: line 91, column 44

 

The problem occurs when one of our particular fields is NULL; which is the case most of the time.  So the update trigger needs to test to make sure the value is not NULL before executing the rest of the code.  Below is a copy of the update section of trigger and comments of how I tried to test for the NULL value and section generating error:

 

 

.
.
.
else if(Trigger.isUpdate)
{
	//Tried adding test to verify value was not null before executing rest of code
	if (Case.X360_Contract_Cycle__c != NULL) {
	
	//sum total both old and new
	Case [] oldTime = Trigger.old;
	Case [] newTime = Trigger.new;
	Double newSum = 0.0;
	Double oldSum = 0.0;

	for(Case newTe: newTime)
		{
			for(Case oldTe : oldTime)
				{

// SECTION GENERATING ERROR IF 'X360_Contract_Cycle__c' IS NULL
X360_Contract_Cycle__c oldTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :oldTe.X360_Contract_Cycle__c];

X360_Contract_Cycle__c newTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :newTe.X360_Contract_Cycle__c];
					
					
					Case [] newSumHours = [Select Id, Case_Hours__c  from Case where X360_Contract_Cycle__c = :newTimesheet.Id];
					Case [] oldSumHours = [Select Id, Case_Hours__c from Case where X360_Contract_Cycle__c = :oldTimesheet.Id];

							//sum premiums from child objects
							for(Case oldSumHour : oldSumHours)
							{
								//converting 'Case_Hours__c' from string data type to number (double)
    							double oldCaseHours = double.valueOf(oldSumHour.Case_Hours__c);
								oldSum += oldCaseHours;
							}

							for(Case newSumHour : newSumHours)
							{
								//converting 'Case_Hours__c' from string data type to number (double)
    							double newCaseHours = double.valueOf(newSumHour.Case_Hours__c);
								newSum += newCaseHours;
							}

					newTimesheet.Delivered_Hours__c = newSum;
					oldTimesheet.Delivered_Hours__c = oldSum;

					//sheetsToUpdate.add(newTimesheet);
					//sheetsToUpdate.add(oldTimesheet);

					sheetsToUpdate.add(newTimesheet);
					if(newTimesheet.Id != oldTimesheet.Id){
						sheetsToUpdate.add(oldTimesheet);
					}

				}
			}


update sheetsToUpdate;

}

}

 

I am far from a full fledged Developer so trying to hack my way through this a bit.  Logically I thought the IF test would work, but the rest of the code appears to execute regardless if the value is NULL or not.  If the value is not NULL the update works fine.  Any suggestions?  Thanks!!

 

Foreword:  First and foremost let me start by saying I am a *Newbie* to APEX and just getting my feet wet with more complex programming (I come from a web development background & in that sense VisualForce is much more on my level at this point).  I am not looking for someone to write the entire test unit code for me.  I do need help getting started and perhaps some very clear/basic explanation on how to get started.

 

Background:  We have a custom object (X360_Contract_Cycle__c) that is associated to cases by a lookup field (lookup field is on the case standard object).  The logic is when the Contract Name is the same as the value of the lookup field sum all case hours and populate a field on the custom object.  I was able to take code from the following article (http://colinloretz.com/2008/10/salesforce-rollup-summary-fields-using-apex-code/) and change the values to get it working in our Sandbox environment.  Here is my final code:

 

 

trigger rollupCaseHoursTo360 on Case (after delete, after insert, after update) {

double sumTotalHours = 0.0;
X360_Contract_Cycle__c [] sheetsToUpdate = new X360_Contract_Cycle__c[]{};


//***********************************************
//Updating new records
//***********************************************

if(Trigger.isInsert)
    {       
        
        Case [] teNew = trigger.new;

            for(Case te : teNew)
                {
                    
                    // 'X360_Contract_Cycle__c' that is part of the bind if the lookup field not custom object
                    for (X360_Contract_Cycle__c timesheet : [select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :te.X360_Contract_Cycle__c])
                        {
                                //Sum all the timesheet entries
                                for (Case timeEntries: [select Id, Case_Hours__c from Case where Case_Hours__c != NULL and X360_Contract_Cycle__c = :timesheet.id])
                                    {
                                        //converting 'Case_Hours__c' from string data type to number (double)
                                        double caseHours = double.valueOf(timeEntries.Case_Hours__c);
                                        sumTotalHours += caseHours;
                                    }
                            
                            timesheet.Delivered_Hours__c = sumTotalHours;

                            //add timesheet to list to be updated outside of the loop
                            sheetsToUpdate.add(timesheet);
                        }
                }

//commit the changes to Salesforce
update sheetsToUpdate;
}


//***********************************************
//Code for updating when a record is deleted
//***********************************************

else if(Trigger.isDelete)
{
	Case [] teOld = trigger.old;

		for(Case te: teOld)
		{

			for (X360_Contract_Cycle__c timesheet: [select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :te.X360_Contract_Cycle__c])
				{

                	for (Case timeEntries: [select Id, Case_Hours__c from Case where Case_Hours__c != NULL and X360_Contract_Cycle__c = :timesheet.id])
                  		{
                   			//converting 'Case_Hours__c' from string data type to number (double)
                    		double caseHours = double.valueOf(timeEntries.Case_Hours__c);
                    		sumTotalHours += caseHours;
                  		}

					timesheet.Delivered_Hours__c = sumTotalHours;
					sheetsToUpdate.add(timesheet);
				}
		}
		
update sheetsToUpdate;
}

//***********************************************
//Code for updating when a record is updated
//***********************************************

else if(Trigger.isUpdate)
{
//sum total both old and new
Case [] oldTime = Trigger.old;
Case [] newTime = Trigger.new;
Double newSum = 0.0;
Double oldSum = 0.0;

for(Case newTe: newTime)
{
for(Case oldTe : oldTime)
{

X360_Contract_Cycle__c oldTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :oldTe.X360_Contract_Cycle__c];
X360_Contract_Cycle__c newTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :newTe.X360_Contract_Cycle__c];

Case [] newSumHours = [Select Id, Case_Hours__c  from Case where X360_Contract_Cycle__c = :newTimesheet.Id];
Case [] oldSumHours = [Select Id, Case_Hours__c from Case where X360_Contract_Cycle__c = :oldTimesheet.Id];

//sum premiums from child objects
for(Case oldSumHour : oldSumHours)
{
	
	//converting 'Case_Hours__c' from string data type to number (double)
    double oldCaseHours = double.valueOf(oldSumHour.Case_Hours__c);
	oldSum += oldCaseHours;
}

for(Case newSumHour : newSumHours)
{
	
	//converting 'Case_Hours__c' from string data type to number (double)
    double newCaseHours = double.valueOf(newSumHour.Case_Hours__c);
	newSum += newCaseHours;
}

newTimesheet.Delivered_Hours__c = newSum;
oldTimesheet.Delivered_Hours__c = oldSum;

//sheetsToUpdate.add(newTimesheet);
//sheetsToUpdate.add(oldTimesheet);

sheetsToUpdate.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id){
sheetsToUpdate.add(oldTimesheet);
}

}
}


update sheetsToUpdate;
}



}

 

At this point I need to write a test unit with a fair amount of coverage to deploy the trigger to production.  I am really struggling trying to understand how to get started with the test unit.  If anyone can provide assistance on how to get started I would be very grateful .  Thanks in advance!

 

Hi, I am fairly new to customizing SalesForce and trying to figure out the best approach (formula or trigger) to the following problem:
 
We have a custom object called 'Contract' that has a lookup field to 'Account'.  One of the fields on the 'Contract' custom object will need to calculate (sum) all case hours where Case Account Name value is same as Contract Account Name value.  In addition to the condition just mentioned we only need case hours that fall in between the contract start date and end date (fields on the custom object).  
 
Can this be achieved using a formula?  I almost got it worked out using SOQL but ran into some limitations since you cannot do field comparisons.  Thanks for any help you might be able to provide!  
  • February 10, 2010
  • Like
  • 0

Is there a way to restrict users from adding tabs to a App in SF?  In otherwords, can you configure a particular app in SF to omit the 'All Tabs' link in order to prevent users from adding additional tabs to a custom app?

 

 

Hope that makes sense and thanks in advance!

 

~ Sean

Hi,

 

I am trying to see if it is possible to dynamically insert the current month into the 'subject' line of a VisualForce email template.  More specifically, I need to display the month in 'MMMMM' format (Ex:  December).  I am aware that the following expressions work:

 

 

  • {!TODAY()}
  • {!MONTH(TODAY())}
  • {!DAY(TODAY())}
  • {!YEAR(TODAY())}

 

 

Example:

 

 

<messaging:emailTemplate subject="{!MONTH(TODAY())} This is my subject!" 
recipientType="Contact"
relatedToType="Custom_Object__c"
replyTo="everyone@world.com" >

 

Any way to format the date in 'MMMMM' format (Ex:  December)?

 

Thanks in advance!

 

  • January 28, 2011
  • Like
  • 0

Currently, we have a custom object containing a custom button linking to a VisualForce email template; when the button is selected it performs a mail merge collecting all the needed data from the custom object to the email template.  We then send the email template, one by one, from each custom object record (as needed).  This was phase one for us and up next we would like to further automate this process by being able to send all the emails in bulk.  We would still need to collect (merge) data unique to each custom object record and email to the appropriate contact(s).  I am just in the research/planning stages for this so I am not looking for a step by step solution here.  If you can provide any tips, advice, references to specific documentation/examples it would be greatly appreciated?  Thanks in advance!

  • October 28, 2010
  • Like
  • 0

I am trying to figure out how to test fields (included within a apex:repeat) to see if they are blank, or null, and if so display some alternate text (Ex: No records to display) in the table instead of a blank table.  Example code snippet below:

 

 

<apex:repeat var="auditList" value="{!relatedTo.Site_Audit__r}">
   <tr>
    <td>
	<apex:outputField value="{!auditList.Audit_Type__c}" />
    </td>
    <td>
       	<apex:outputField value="{!auditList.Delivery_Date__c}" />
    </td>
    <td>
	<apex:outputField value="{!auditList.Review_Date__c}" />
    </td>
   </tr>
</apex:repeat>

 

Thanks for any help or suggestions! 

 

  • August 09, 2010
  • Like
  • 0

I am working on outputting a custom object to PDF by Email/VisualForce template.  So far I have been successful with everything, but just ran across something that I need help with.  As part of the PDF we are including four related lists that display on the objects page view.  All the related lists contain fields from a single object except one.  One of the related lists displays fields from two custom objects (Training_Attendee__c & Training_Course__c) on the page view.  On the object this relationship is formed by a lookup field from the 'Training_Attendee__c'  object to the 'Training_Course__c' object.  This is what I am having trouble with.  For the other three related lists I ran a apex:repeat and associated it with the single object that was needed and that worked fine...code example below:


<apex:repeat var="cx" value="{!relatedTo.Cases__r}">     
   <tr>
    <td>
       {!cx.CaseNumber}
    </td>
    <td>
       {!cx.Subject}
    </td>
    <td>
       {!cx.Case_Hours__c}
    </td>
   </tr>
</apex:repeat>


Except now that I need to pull data from two objects I am not sure how to associate both objects to the same apex:repeat statement ...current code example for this particular related list is below:

 

<apex:repeat var="IGXTraining" value="{!relatedTo.Training_Attendee__r}">
   <tr>
    <td>
       <apex:outputField value="{!IGXTraining.Name}" />
    </td>
    <td>
       <apex:outputField value="{!IGXTraining.Training__c}" />
    </td>
    <td>
	// value is from another custom object (Training_Course__c)
	// association is by lookup field on Training_Attendee__c to Training_Course__c
       {Location}
    </td>
    <td>
	// value is from another custom object (Training_Course__c)
	// association is by lookup field on Training_Attendee__c to Training_Course__c
       {StartDate}
    </td>
    <td>
       <apex:outputField value="{!IGXTraining.Course_Credit__c}" />
    </td>
   </tr>
</apex:repeat>

 

On the related list it automatically makes the association between the two objects so you can list fields from both on the page view:

 

 

 

Is it possible to associate a two object relationship using apex:repeat?  If so any examples would really be appreciated.  Thanks in advance!

Trying to solve one last problem on a trigger I am working on. Currently, the trigger works fine on 'insert' and 'delete', but generating the following error message when 'updating':

 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger rollupCaseHoursTo360 caused an unexpected exception, contact your administrator: rollupCaseHoursTo360: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.rollupCaseHoursTo360: line 91, column 44

 

The problem occurs when one of our particular fields is NULL; which is the case most of the time.  So the update trigger needs to test to make sure the value is not NULL before executing the rest of the code.  Below is a copy of the update section of trigger and comments of how I tried to test for the NULL value and section generating error:

 

 

.
.
.
else if(Trigger.isUpdate)
{
	//Tried adding test to verify value was not null before executing rest of code
	if (Case.X360_Contract_Cycle__c != NULL) {
	
	//sum total both old and new
	Case [] oldTime = Trigger.old;
	Case [] newTime = Trigger.new;
	Double newSum = 0.0;
	Double oldSum = 0.0;

	for(Case newTe: newTime)
		{
			for(Case oldTe : oldTime)
				{

// SECTION GENERATING ERROR IF 'X360_Contract_Cycle__c' IS NULL
X360_Contract_Cycle__c oldTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :oldTe.X360_Contract_Cycle__c];

X360_Contract_Cycle__c newTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :newTe.X360_Contract_Cycle__c];
					
					
					Case [] newSumHours = [Select Id, Case_Hours__c  from Case where X360_Contract_Cycle__c = :newTimesheet.Id];
					Case [] oldSumHours = [Select Id, Case_Hours__c from Case where X360_Contract_Cycle__c = :oldTimesheet.Id];

							//sum premiums from child objects
							for(Case oldSumHour : oldSumHours)
							{
								//converting 'Case_Hours__c' from string data type to number (double)
    							double oldCaseHours = double.valueOf(oldSumHour.Case_Hours__c);
								oldSum += oldCaseHours;
							}

							for(Case newSumHour : newSumHours)
							{
								//converting 'Case_Hours__c' from string data type to number (double)
    							double newCaseHours = double.valueOf(newSumHour.Case_Hours__c);
								newSum += newCaseHours;
							}

					newTimesheet.Delivered_Hours__c = newSum;
					oldTimesheet.Delivered_Hours__c = oldSum;

					//sheetsToUpdate.add(newTimesheet);
					//sheetsToUpdate.add(oldTimesheet);

					sheetsToUpdate.add(newTimesheet);
					if(newTimesheet.Id != oldTimesheet.Id){
						sheetsToUpdate.add(oldTimesheet);
					}

				}
			}


update sheetsToUpdate;

}

}

 

I am far from a full fledged Developer so trying to hack my way through this a bit.  Logically I thought the IF test would work, but the rest of the code appears to execute regardless if the value is NULL or not.  If the value is not NULL the update works fine.  Any suggestions?  Thanks!!

 

Foreword:  First and foremost let me start by saying I am a *Newbie* to APEX and just getting my feet wet with more complex programming (I come from a web development background & in that sense VisualForce is much more on my level at this point).  I am not looking for someone to write the entire test unit code for me.  I do need help getting started and perhaps some very clear/basic explanation on how to get started.

 

Background:  We have a custom object (X360_Contract_Cycle__c) that is associated to cases by a lookup field (lookup field is on the case standard object).  The logic is when the Contract Name is the same as the value of the lookup field sum all case hours and populate a field on the custom object.  I was able to take code from the following article (http://colinloretz.com/2008/10/salesforce-rollup-summary-fields-using-apex-code/) and change the values to get it working in our Sandbox environment.  Here is my final code:

 

 

trigger rollupCaseHoursTo360 on Case (after delete, after insert, after update) {

double sumTotalHours = 0.0;
X360_Contract_Cycle__c [] sheetsToUpdate = new X360_Contract_Cycle__c[]{};


//***********************************************
//Updating new records
//***********************************************

if(Trigger.isInsert)
    {       
        
        Case [] teNew = trigger.new;

            for(Case te : teNew)
                {
                    
                    // 'X360_Contract_Cycle__c' that is part of the bind if the lookup field not custom object
                    for (X360_Contract_Cycle__c timesheet : [select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :te.X360_Contract_Cycle__c])
                        {
                                //Sum all the timesheet entries
                                for (Case timeEntries: [select Id, Case_Hours__c from Case where Case_Hours__c != NULL and X360_Contract_Cycle__c = :timesheet.id])
                                    {
                                        //converting 'Case_Hours__c' from string data type to number (double)
                                        double caseHours = double.valueOf(timeEntries.Case_Hours__c);
                                        sumTotalHours += caseHours;
                                    }
                            
                            timesheet.Delivered_Hours__c = sumTotalHours;

                            //add timesheet to list to be updated outside of the loop
                            sheetsToUpdate.add(timesheet);
                        }
                }

//commit the changes to Salesforce
update sheetsToUpdate;
}


//***********************************************
//Code for updating when a record is deleted
//***********************************************

else if(Trigger.isDelete)
{
	Case [] teOld = trigger.old;

		for(Case te: teOld)
		{

			for (X360_Contract_Cycle__c timesheet: [select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :te.X360_Contract_Cycle__c])
				{

                	for (Case timeEntries: [select Id, Case_Hours__c from Case where Case_Hours__c != NULL and X360_Contract_Cycle__c = :timesheet.id])
                  		{
                   			//converting 'Case_Hours__c' from string data type to number (double)
                    		double caseHours = double.valueOf(timeEntries.Case_Hours__c);
                    		sumTotalHours += caseHours;
                  		}

					timesheet.Delivered_Hours__c = sumTotalHours;
					sheetsToUpdate.add(timesheet);
				}
		}
		
update sheetsToUpdate;
}

//***********************************************
//Code for updating when a record is updated
//***********************************************

else if(Trigger.isUpdate)
{
//sum total both old and new
Case [] oldTime = Trigger.old;
Case [] newTime = Trigger.new;
Double newSum = 0.0;
Double oldSum = 0.0;

for(Case newTe: newTime)
{
for(Case oldTe : oldTime)
{

X360_Contract_Cycle__c oldTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :oldTe.X360_Contract_Cycle__c];
X360_Contract_Cycle__c newTimesheet = [Select Id, Name, Delivered_Hours__c from X360_Contract_Cycle__c where Id = :newTe.X360_Contract_Cycle__c];

Case [] newSumHours = [Select Id, Case_Hours__c  from Case where X360_Contract_Cycle__c = :newTimesheet.Id];
Case [] oldSumHours = [Select Id, Case_Hours__c from Case where X360_Contract_Cycle__c = :oldTimesheet.Id];

//sum premiums from child objects
for(Case oldSumHour : oldSumHours)
{
	
	//converting 'Case_Hours__c' from string data type to number (double)
    double oldCaseHours = double.valueOf(oldSumHour.Case_Hours__c);
	oldSum += oldCaseHours;
}

for(Case newSumHour : newSumHours)
{
	
	//converting 'Case_Hours__c' from string data type to number (double)
    double newCaseHours = double.valueOf(newSumHour.Case_Hours__c);
	newSum += newCaseHours;
}

newTimesheet.Delivered_Hours__c = newSum;
oldTimesheet.Delivered_Hours__c = oldSum;

//sheetsToUpdate.add(newTimesheet);
//sheetsToUpdate.add(oldTimesheet);

sheetsToUpdate.add(newTimesheet);
if(newTimesheet.Id != oldTimesheet.Id){
sheetsToUpdate.add(oldTimesheet);
}

}
}


update sheetsToUpdate;
}



}

 

At this point I need to write a test unit with a fair amount of coverage to deploy the trigger to production.  I am really struggling trying to understand how to get started with the test unit.  If anyone can provide assistance on how to get started I would be very grateful .  Thanks in advance!

 

Hi, I am fairly new to customizing SalesForce and trying to figure out the best approach (formula or trigger) to the following problem:
 
We have a custom object called 'Contract' that has a lookup field to 'Account'.  One of the fields on the 'Contract' custom object will need to calculate (sum) all case hours where Case Account Name value is same as Contract Account Name value.  In addition to the condition just mentioned we only need case hours that fall in between the contract start date and end date (fields on the custom object).  
 
Can this be achieved using a formula?  I almost got it worked out using SOQL but ran into some limitations since you cannot do field comparisons.  Thanks for any help you might be able to provide!  
  • February 10, 2010
  • Like
  • 0