• me_help
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi,

 

I am new to salesforce and have writte the following trigger but not able to write test class for it.

Can anyone help me with the code for its test class??

 

Trigger

 

trigger increaseCount on Employee__c (after insert) 
{
List<Employee__c> EmployeeToUpdate = new List<Employee__c>{};
for(Employee__c emp : Trigger.new)
  {
  Company__c company =[ select Number_of_Employees__c from Company__c where Id= :emp.Company__c ];
    if (company.Number_of_Employees__c==Null)
   {
   company.Number_of_Employees__c=1;
   }
   else
   {company.Number_of_Employees__c =company.Number_of_Employees__c+1;}
   update company;
  }
}

Hi,

 

I am new to salesforce and have writte the following trigger but not able to write test class for it.

Can anyone help me with the code for its test class??

 

Trigger

 

trigger increaseCount on Employee__c (after insert) 
{
List<Employee__c> EmployeeToUpdate = new List<Employee__c>{};
for(Employee__c emp : Trigger.new)
  {
  Company__c company =[ select Number_of_Employees__c from Company__c where Id= :emp.Company__c ];
    if (company.Number_of_Employees__c==Null)
   {
   company.Number_of_Employees__c=1;
   }
   else
   {company.Number_of_Employees__c =company.Number_of_Employees__c+1;}
   update company;
  }
}

Hello, I have an SQL statement returns the count of of the number of records in my object:

 

countrecord = [SELECT COUNT(Probability__c)totalcount FROM Pipeline_Tracker_Ver_2__c];

 

I want to convert this to an integer, and add the value 1, so that I can set this as a dynamic value for ROWSPAN on one of my tables. I figured that since I am returning a count, I should be able to easily convert this to an integer. I have been trying the formula:

 

public Integer count;
count = integer.valueof(countrecord) + 1;

 

However, I get the following error. It seems to be getting totalcount correct, which is 2, but I'm not sure why it's an invalid integer, or what they mean by external entry point.

 

System.TypeException: Invalid integer: [AggregateResult (totalcount:2)]

 

Class.MarginEscalatorsThermometerChart_Q1_2011.getCount: line 231, column 17 External entry point

 

Any insight would be great, as I'm not sure what else to try.

 

Thanks!

Mike

I am brand new to Apex and wrote my first trigger. a very simple one - and it works perfectly but a I'm not sure where to even start with writing an apex test class..

 

My trigger is setup to update a lookup field based on the value of another lookup field. (basically so the user can select the "account" from a record, hit save, and have the "parent account" automatically populate into the other lookup field. Rather than having to select a value for both lookup fields.)

 

Here is the trigger:

 

trigger UpdateManagementCompanyField on Transfer__c (before insert, before update) {for(Transfer__c a:Trigger.new){a.Management_Company__c = a.Management_Company_ID__c;}

}

 

Any help would be greatly appreciated!

 

 

  • March 08, 2011
  • Like
  • 0