• B2
  • 0 Points
  • Member since 2007

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0
Hi Everyone,
I'm very new to Apex code and am following the sample app that was introduced at the Salesforce Tour de Force show and attempting to learn the language.  I've created the following Apex class, but now need to unit test it and I just can't figure-out how to do it.  The workbook doesn't provide any instructions on how to write it and I've tried without success to get something running.

I talked to someone who knows Apex code and they indicated it would only take 7 or 8 lines of code to sufficiently test the attached code that would enable me to deploy it to my sandbox, but I really need some help here.
I know this is asking a lot, but could someone provide me what I need to test this code - with some remarks as well?  I would REALLY appreciate it!!
Here's the code:
public class MileageUtil {
 static final integer MAX_MILES_PER_DAY = 500;
 public static void areMilesAllowed(Mileage__c[] miles)  {
  Double totalMiles = 0;
  String createdbyId = UserInfo.getUserId();
 /* adds miles that were created in previous requests for today */
 for (Mileage__c mq: [select miles__c from Mileage__c
  where Date__c = TODAY and
  createdById = :createdbyId and
  miles__c != null]) {
  totalMiles += mq.miles__c;
 /* Totals the miles in the request */
 for (Mileage__c m:miles)  {
  totalMiles += m.miles__c;
  if (totalMiles > MAX_MILES_PER_DAY)
    m.addError ('Mileage request exceeds daily limit: ' + MAX_MILES_PER_DAY);

  • May 04, 2008
  • Like
  • 0