• Jolene Scott-Martin
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
I'm very new to this and managed to write a trigger, preventing a duplicates on a custom object 'Time Estimating' and giving a customised error on screen.  Code is below.

The trigger works perfectly in Sandbox but I can't move the trigger into production as it doesn't include tests.  So I have written a separate apex class to test.  The code is also below.  When I debug I get the following error 'required (...)+ loop did not match anything at input '<EOF>'.  I have googled this to death with no helpful result. When I run tests I get 0% code coverage for the trigger.

Can anyone advise what I have done wrong?  

I'm using the Developer Console (can't install anything else).

Apex Trigger to check for duplicates (called PreventDuplicate)
trigger PreventDuplicate on Time_Estimating__c (before insert, before update){
 
    List<String> uniqueValueList = new List<String>();
    for(Time_Estimating__c a : Trigger.new){
        uniqueValueList.add(a.Unique_Year_Estimate__c);
    }

    List<Time_Estimating__c> acctList = [select id, name, Unique_Year_Estimate__c from Time_Estimating__c where Unique_Year_Estimate__c IN :uniqueValueList];
    Map<String,Time_Estimating__c> uniqueValueMap = new Map<String,Time_Estimating__c>();
    for(Time_Estimating__c a : acctList){
        uniqueValueMap.put(a.Unique_Year_Estimate__c,a);       
    }
 
    for(Time_Estimating__c a : Trigger.new){
        if(uniqueValueMap.containsKey(a.Unique_Year_Estimate__c)){
           
            if(trigger.isInsert || (trigger.isUpdate && a.id<>uniqueValueMap.get(a.Unique_Year_Estimate__c).id)){
                a.addError('A Time Estimate for the year you have specified already exists.  Please click the cancel button and update the existing time estimate.');
            }          
        }
    }
}

Apex class to test trigger (called PreventDuplicateTest)
@isTest

//test for PreventDuplicate trigger on Time Estimating
Public Class PreventDuplicateTest
{
   Static testMethod Void PreventDuplicate()
   {
      Boolean result = false;
      Time_Estimating__c firstAcc = new 
          Time_Estimating__c(Unique_Year_Estimate__c = 'test - 2015',Matter_Name__c = 'test');
      insert firstAcc;
      try{
           Time_Estimating__c secondAcc = new 
               Time_Estimating__c(Unique_Year_Estimate__c = 'test - 2015',Matter_Name__c = 'test');
           insert secondAcc;
       }catch(DmlException ex){ result = true;}
      System.assert(result);
   }
}

Many thanks for your help!
Hello,
I am having a challenge where I need to, with one button click, clone a record and then change the record type of the original record.   This is on a custom object called Employee.  My record types are “Current” and “Historical”.  Ideally I will have an employee record the is “Current” that needs updated and my HR manager will go to that record.  She will then push a button that will convert that record to the “Historical” record type and clone the new employee record to the “Current” record type. 

Any help or ideas on how to accomplish this would be greatly appreciated.
 
Hi, 
We just started using Agile accelerator. is there a way to turn off the emails from agile? Or set preferences for what we want to get emailed on?

Thanks!
I'm very new to this and managed to write a trigger, preventing a duplicates on a custom object 'Time Estimating' and giving a customised error on screen.  Code is below.

The trigger works perfectly in Sandbox but I can't move the trigger into production as it doesn't include tests.  So I have written a separate apex class to test.  The code is also below.  When I debug I get the following error 'required (...)+ loop did not match anything at input '<EOF>'.  I have googled this to death with no helpful result. When I run tests I get 0% code coverage for the trigger.

Can anyone advise what I have done wrong?  

I'm using the Developer Console (can't install anything else).

Apex Trigger to check for duplicates (called PreventDuplicate)
trigger PreventDuplicate on Time_Estimating__c (before insert, before update){
 
    List<String> uniqueValueList = new List<String>();
    for(Time_Estimating__c a : Trigger.new){
        uniqueValueList.add(a.Unique_Year_Estimate__c);
    }

    List<Time_Estimating__c> acctList = [select id, name, Unique_Year_Estimate__c from Time_Estimating__c where Unique_Year_Estimate__c IN :uniqueValueList];
    Map<String,Time_Estimating__c> uniqueValueMap = new Map<String,Time_Estimating__c>();
    for(Time_Estimating__c a : acctList){
        uniqueValueMap.put(a.Unique_Year_Estimate__c,a);       
    }
 
    for(Time_Estimating__c a : Trigger.new){
        if(uniqueValueMap.containsKey(a.Unique_Year_Estimate__c)){
           
            if(trigger.isInsert || (trigger.isUpdate && a.id<>uniqueValueMap.get(a.Unique_Year_Estimate__c).id)){
                a.addError('A Time Estimate for the year you have specified already exists.  Please click the cancel button and update the existing time estimate.');
            }          
        }
    }
}

Apex class to test trigger (called PreventDuplicateTest)
@isTest

//test for PreventDuplicate trigger on Time Estimating
Public Class PreventDuplicateTest
{
   Static testMethod Void PreventDuplicate()
   {
      Boolean result = false;
      Time_Estimating__c firstAcc = new 
          Time_Estimating__c(Unique_Year_Estimate__c = 'test - 2015',Matter_Name__c = 'test');
      insert firstAcc;
      try{
           Time_Estimating__c secondAcc = new 
               Time_Estimating__c(Unique_Year_Estimate__c = 'test - 2015',Matter_Name__c = 'test');
           insert secondAcc;
       }catch(DmlException ex){ result = true;}
      System.assert(result);
   }
}

Many thanks for your help!