• Marco__o
  • -1 Points
  • Member since 2010

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 4
Ok, I have a workflow rule that sends out an email regarding contracts that are due to expire. This rules is based on a custom formula field in the contracts object. The formula calculates the remaining months for a contract. How can I get this rule to trigger even though the record is not physically edited or created. What we have to do right now is wipe out all the contracts every night and rebuild them with a data push from our servers and that will trigger the rule to look at each record and it's respective "Month's remaining" field value and trigger the email or not. Has anybody encountered this problem and be able to solve it wiht an apex trigger? I have not prior experianc eusing or implemnting APex triggers so please keep that in mind when you point me in the right direction. Thank you very much Anthony
  • August 30, 2010
  • Like
  • 0


I have an requirement here.I need to design a visualforce page like a table.The data in the table should dispLAY THE analytic data.Like number of accounts created this year.And kind of number of contacts,It just display the count of the data.

I tried to use the count function in the controller.But its hitting the governor limits number of records fetched is greater than 10,000 records.


So I am looking for alternative like can we fetch the data from reports.I know reports is not an Object in salesforce, It doesnt have fields to access.But i am looking for any alternative to fetch the data from existing reports.

Hi All,


I have two triggers which are working fine, however the code coverage results are showing 64% only. Not sure what more I should be testing in order to achieve 100%.


Any tips/pointers very much welcome


Trigger 1



trigger CreateContractHeader on Order__c (after update) {

	//Get Order object values
	for(Order__c ord : Trigger.new){
		Boolean bTerms = ord.Accepted_Terms__c;
		Boolean bPayment = ord.Payment_Terms_Agreed__c;
		List<Contract> ordId = [select Id from Contract where Order__c=:ord.Id]; 
		// Create contract if not existing
		if (ordId.size() == 0){
			// Check terms have been agreed
			if (bTerms==true && bPayment == true){

			Contract newContract = new Contract();
			newContract.AccountId = ord.Account__c;
			newContract.Order__c = ord.Id;
			Date startdate = Date.today();
			newContract.StartDate = startdate;
			newContract.ContractTerm = 12;
			insert newContract;


Trigger 2


trigger CreateContractCredits on Contract (after insert) {

		for (Contract cont : Trigger.new){
			// Fetch order credits
			Order__c orderCredits = [select Total_Order_Credits__c from Order__c where id=:cont.Order__c];
			// Convert credits to int
			double d = orderCredits.Total_Order_Credits__c;
			integer x;
			x = d.intValue();
			// Create credits for total number of credits
			for (Integer i = 0;  i < x; i++){
				Credit__c credit = new Credit__c();
				credit.Contract__c = cont.Id;
				credit.Account__c = cont.AccountId;
				insert credit;



Here is my test class


private class testContract {

    static testMethod void myUnitTest() {
    	// Insert Test Product
    	Product2 prod = new Product2(name ='WR');
    	insert prod;
    	// Insert Test Account
    	Account acc = new Account(name='Mike');	
     	insert acc;
     	// Insert Test Order
     	Order__c ord = new Order__c();
     	ord.Account__c = acc.Id;
     	insert ord;
     	// Insert Single Order Line
     	OrderItems__c ordlines = new OrderItems__c();
     	ordlines.Order__c = ord.Id;
     	ordlines.Product__c = prod.Id;
     	insert ordlines;
  	 	// Update Order
     	ord.Payment_Terms_Agreed__c = true;
     	ord.Accepted_Terms__c = true;   	
     	update ord;
     	// Insert Contract
     	Contract contract = new Contract();
     	contract.AccountId = acc.Id;
     	contract.Order__c = ord.Id;
     	insert contract;
     	// Insert Credits
     	Credit__c credits = new Credit__c();
     	credits.Account__c = acc.Id;
     	credits.Contract__c = contract.Id;
     	insert credits;












I've noticed that when setting Dataloader's batch size option to 200, triggers are operating in batches of 100. This is not a problem in itself, but I've also noticed that static variables are not cleared between the 100 batch runs. I've included a short example below, but basically all I'd like to know is:

Why are the Dataloader batches broken up, and when does this happen?
Should the static variables be cleared automatically?

As I say, here's a quick example; it's a trigger on Contact and a class with a static variable:

public class quickClass {
    public static boolean lock = false;

trigger quick on Contact (before insert) { 
    System.debug('lock: ' + quickClass.lock);
    quickClass.lock = true;
    System.debug('Trigger.new.size(): ' + Trigger.new.size());

When we insert, say, 150 Contacts, using Dataloader with a batch size of 200 in the log file we will see:

lock: false
Trigger.new.size(): 100
lock: true
Trigger.new.size(): 50

It doesn't look like it's Dataloader fault - it does look like it's sending 150 Contacts, rather than 100 and then 50.

Like I say, I don't mind the process being broken up, but obviously I'd also like the static variables to be cleared between the processing of the first 100 records finishing, and the processing of the next 50 records starting, as we are using static variables to control execution flow. If these variables are keeping their value, it causes a problem for us!

Hope that's enough detail, thanks in advance for any help...

  • December 05, 2008
  • Like
  • 1