• Brian Roberts 2
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 12
    Replies
Please can someone point me in the right direction as I can't see my errors?
@isTest
private class TicketInAccrual {

  public class TestData {
    public Map<String, RecordType> tirtMap;
    public FX5__Status__c newTicketStatus;
    public FX5__Status__c TicketInAccrualStatus;
    public List<FX5__Catalog_Item__c> ciList;
    public List<FX5__Price_Book_Item__c> pbiList;
    
    public String GetDefaultUOMForRecordType(String rtDeveloperName) {
        if (rtDeveloperName == 'Daily_Personnel' || rtDeveloperName == 'Daily_Equipment')
          return 'Day';
        if (rtDeveloperName == 'Hourly_Equipment' || rtDeveloperName == 'Hourly_Personnel')
          return 'Hour';
        return 'Each';
    }
    
    public void ProvisionTestData(FX_UnitTestHelper.ExproJob_LocalTestData mockData) {
          this.newTicketStatus = new FX5__Status__c(
            Name = 'New Ticket',
            FX5__SObject__c = 'Ticket__c',
            Status_Developer_Name__c = 'New_Ticket');
          this.TicketInAccrualStatus = new FX5__Status__c(
            Name = 'Ticket in Accrual',
            FX5__SObject__c = 'Ticket__c',
            Status_Developer_Name__c = 'Ticket_in_Accrual');
        insert this.newTicketStatus;
        insert this.TicketInAccrualStatus;      
      
      this.tirtMap = new Map<String,RecordType>();
      this.ciList = new List<FX5__Catalog_Item__c>();
      Integer ciCount = 1;
      for (RecordType tirt : [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket_Item__c']) {
        this.tirtMap.put(tirt.DeveloperName,tirt);
        this.ciList.add(new FX5__Catalog_Item__c(
          Name = String.valueOf(ciCount) + '-0135',
          FX5__IsArchived__c = false,
          FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
          EXPRO_SAP_Plant__c = '0135',
          FX5__Sequence_Number__c = ciCount,
          FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
          FX5__UOM__c = GetDefaultUOMForRecordType(tirt.DeveloperName)
        ));
        ciCount += 1;
        this.ciList.add(new FX5__Catalog_Item__c(
          Name = String.valueOf(ciCount) + '-0135',
          FX5__IsArchived__c = false,
          FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
          EXPRO_SAP_Plant__c = '0135',
          FX5__Sequence_Number__c = ciCount,
          FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
          FX5__UOM__c = this.GetDefaultUOMForRecordType(tirt.DeveloperName)
        ));
        ciCount += 1;
      }
      insert this.ciList;
      
      Set<Id> ciIdSet = new Set<Id>();
      for (FX5__Catalog_Item__c ci : ciList) {
        insert (new FX5__Price_Book_Item__c(
          FX5__Price_Book__c = mockData.testPriceBook.Id,
          FX5__IsArchived__c = false,
          FX5__Catalog_Item__c = ci.Id,
          FX5__Default_Quantity__c = 0,
          FX5__Price__c = 100));
        ciIdSet.add(ci.Id);
      }
      // We want to fetch the Price Book Items back after insertion so that we get the result of all triggers that fired
      this.pbiList = [
        select 
          Id,FX5__Price_Book__c,FX5__Catalog_Item__c,FX5__IsArchived__c,FX5__Default_Quantity__c,FX5__Price__c,
          FX5__Ticket_Item_Record_Type__c,FX5__Sequence_Number__c,FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c
        from FX5__Price_Book_Item__c where FX5__Catalog_Item__c in :ciIdSet];
    }
  }

    static testMethod void TestTicketItemSequencingForSAP() {
        FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
        mockData.ProvisionTestData(true);
        TestData testData = new TestData();
        testData.ProvisionTestData(mockData);
         
        List<FX5__Ticket__c> tktList = FX_UnitTestHelper.CreateTickets(mockData.testJob, 2, true);
        FX5__Ticket__c readyForInvTicket = tktList.get(0);
        FX5__Ticket__c newTicket = tktList.get(1);
        
        List<FX5__Ticket_Item__c> testTktItems = new List<FX5__Ticket_Item__c>();
        // Add ticket items to the each mock ticket
        for (FX5__Ticket__c tkt : tktList) {
          for (FX5__Price_Book_Item__c pbi : testData.pbiList) {
            RecordType tiRT = testData.tirtMap.get(pbi.FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c);
            testTktItems.add(new FX5__Ticket_Item__c(
              FX5__Ticket__c = tkt.Id,
              FX5__Price_Book_Item__c = pbi.Id,
              RecordTypeId = tiRT.Id));
          }
        }
        insert testTktItems;
        
        Test.startTest();
        
      newTicket.FX5__Status__c = testData.newTicketStatus.Id;
      TicketInAccrualTicket.FX5__Status__c = testData.TicketinAccrualStatus.Id;
      
      update newTicket;      
      update TicketInAccrualTicket;
        
        Test.stopTest();
        
        List<FX5__Ticket_Item__c> newTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c from FX5__Ticket_Item__c where FX5__Ticket__c = :newTicket.Id];
        // Ensure that Ticket items on the "New Ticket" items did not update EXPRO_SAP_Item_Number__c
        for (FX5__Ticket_Item__c tktItem : newTicketItems) {
          System.assert(tktItem.EXPRO_SAP_Item_Number__c == null, 'Expected null for EXPRO_SAP_Item_Number__c on "New Ticket" Ticket Item.');
        } 
        
        List<FX5__Ticket_Item__c> TicketInAccrualTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c,Record_Type_Sort_Index__c,RecordTypeId from FX5__Ticket_Item__c where FX5__Ticket__c = :TicketInAccrualTicket.Id order by EXPRO_SAP_Item_Number__c];
        System.assert(TicketInAccrualTicketItems.size() > 0);
        for (Integer i=0; i < TicketInAccrualTicketItems.size(); i+=1) {
          FX5__Ticket_Item__c ti = TicketInAccrualTicketItems.get(i);
          System.assertEquals((i+1)*10, ti.EXPRO_SAP_Item_Number__c);
        }
    }
    
    /*
    * This test ensures that a Ticket that does not have a status will not crash the Ticket On After trigger and will not cause any other 
    * unit tests to fail that do not have a status reference. 
     */
    static testMethod void TestInsertTicketWithNullStatus() {
      FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
        mockData.ProvisionTestData(true);
        
        RecordType ftRT = [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket__c' and DeveloperName='Field_Ticket'];
        FX5__Ticket__c t = new FX5__Ticket__c(
          FX5__Job__c = mockData.testJob.Id,
          RecordTypeId = ftRT.Id
        );
        
        Test.startTest();
        insert t;        
        Test.stopTest();
        
        System.assertEquals(1,([select Id from FX5__Ticket__c where FX5__Job__c = :mockData.testJob.Id]).size());
    }
    
}
Hi, I have a dilema we have certain clients that would like the 24 hour clock to read 24:00 at the end of the day as oppossed to 23:59 then moving to 00:00 again, how can I get this to read 24:00 instead of the 23:59?
I would like to divide a 24 hour day into 15 minute increments so a time worked can be selected from a picklist value and multiplied by the daily rate to get a total cost. the picklist is broken down into 15 minute increments as follows 00:15, 00:30, 00:45, 01:00, 01:15 and so on. Can anyonr advise me on the best way to do this?
Please can someone point me in the right direction as I can't see my errors?
@isTest
private class TicketInAccrual {

  public class TestData {
    public Map<String, RecordType> tirtMap;
    public FX5__Status__c newTicketStatus;
    public FX5__Status__c TicketInAccrualStatus;
    public List<FX5__Catalog_Item__c> ciList;
    public List<FX5__Price_Book_Item__c> pbiList;
    
    public String GetDefaultUOMForRecordType(String rtDeveloperName) {
        if (rtDeveloperName == 'Daily_Personnel' || rtDeveloperName == 'Daily_Equipment')
          return 'Day';
        if (rtDeveloperName == 'Hourly_Equipment' || rtDeveloperName == 'Hourly_Personnel')
          return 'Hour';
        return 'Each';
    }
    
    public void ProvisionTestData(FX_UnitTestHelper.ExproJob_LocalTestData mockData) {
          this.newTicketStatus = new FX5__Status__c(
            Name = 'New Ticket',
            FX5__SObject__c = 'Ticket__c',
            Status_Developer_Name__c = 'New_Ticket');
          this.TicketInAccrualStatus = new FX5__Status__c(
            Name = 'Ticket in Accrual',
            FX5__SObject__c = 'Ticket__c',
            Status_Developer_Name__c = 'Ticket_in_Accrual');
        insert this.newTicketStatus;
        insert this.TicketInAccrualStatus;      
      
      this.tirtMap = new Map<String,RecordType>();
      this.ciList = new List<FX5__Catalog_Item__c>();
      Integer ciCount = 1;
      for (RecordType tirt : [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket_Item__c']) {
        this.tirtMap.put(tirt.DeveloperName,tirt);
        this.ciList.add(new FX5__Catalog_Item__c(
          Name = String.valueOf(ciCount) + '-0135',
          FX5__IsArchived__c = false,
          FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
          EXPRO_SAP_Plant__c = '0135',
          FX5__Sequence_Number__c = ciCount,
          FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
          FX5__UOM__c = GetDefaultUOMForRecordType(tirt.DeveloperName)
        ));
        ciCount += 1;
        this.ciList.add(new FX5__Catalog_Item__c(
          Name = String.valueOf(ciCount) + '-0135',
          FX5__IsArchived__c = false,
          FX5__Description__c = 'Test Item ' + String.valueOf(ciCount),
          EXPRO_SAP_Plant__c = '0135',
          FX5__Sequence_Number__c = ciCount,
          FX5__Ticket_Item_Record_Type__c = tirt.DeveloperName,
          FX5__UOM__c = this.GetDefaultUOMForRecordType(tirt.DeveloperName)
        ));
        ciCount += 1;
      }
      insert this.ciList;
      
      Set<Id> ciIdSet = new Set<Id>();
      for (FX5__Catalog_Item__c ci : ciList) {
        insert (new FX5__Price_Book_Item__c(
          FX5__Price_Book__c = mockData.testPriceBook.Id,
          FX5__IsArchived__c = false,
          FX5__Catalog_Item__c = ci.Id,
          FX5__Default_Quantity__c = 0,
          FX5__Price__c = 100));
        ciIdSet.add(ci.Id);
      }
      // We want to fetch the Price Book Items back after insertion so that we get the result of all triggers that fired
      this.pbiList = [
        select 
          Id,FX5__Price_Book__c,FX5__Catalog_Item__c,FX5__IsArchived__c,FX5__Default_Quantity__c,FX5__Price__c,
          FX5__Ticket_Item_Record_Type__c,FX5__Sequence_Number__c,FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c
        from FX5__Price_Book_Item__c where FX5__Catalog_Item__c in :ciIdSet];
    }
  }

    static testMethod void TestTicketItemSequencingForSAP() {
        FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
        mockData.ProvisionTestData(true);
        TestData testData = new TestData();
        testData.ProvisionTestData(mockData);
         
        List<FX5__Ticket__c> tktList = FX_UnitTestHelper.CreateTickets(mockData.testJob, 2, true);
        FX5__Ticket__c readyForInvTicket = tktList.get(0);
        FX5__Ticket__c newTicket = tktList.get(1);
        
        List<FX5__Ticket_Item__c> testTktItems = new List<FX5__Ticket_Item__c>();
        // Add ticket items to the each mock ticket
        for (FX5__Ticket__c tkt : tktList) {
          for (FX5__Price_Book_Item__c pbi : testData.pbiList) {
            RecordType tiRT = testData.tirtMap.get(pbi.FX5__Catalog_Item__r.FX5__Ticket_Item_Record_Type__c);
            testTktItems.add(new FX5__Ticket_Item__c(
              FX5__Ticket__c = tkt.Id,
              FX5__Price_Book_Item__c = pbi.Id,
              RecordTypeId = tiRT.Id));
          }
        }
        insert testTktItems;
        
        Test.startTest();
        
      newTicket.FX5__Status__c = testData.newTicketStatus.Id;
      TicketInAccrualTicket.FX5__Status__c = testData.TicketinAccrualStatus.Id;
      
      update newTicket;      
      update TicketInAccrualTicket;
        
        Test.stopTest();
        
        List<FX5__Ticket_Item__c> newTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c from FX5__Ticket_Item__c where FX5__Ticket__c = :newTicket.Id];
        // Ensure that Ticket items on the "New Ticket" items did not update EXPRO_SAP_Item_Number__c
        for (FX5__Ticket_Item__c tktItem : newTicketItems) {
          System.assert(tktItem.EXPRO_SAP_Item_Number__c == null, 'Expected null for EXPRO_SAP_Item_Number__c on "New Ticket" Ticket Item.');
        } 
        
        List<FX5__Ticket_Item__c> TicketInAccrualTicketItems = [select Id,FX5__Ticket__c,EXPRO_SAP_Item_Number__c,Record_Type_Sort_Index__c,RecordTypeId from FX5__Ticket_Item__c where FX5__Ticket__c = :TicketInAccrualTicket.Id order by EXPRO_SAP_Item_Number__c];
        System.assert(TicketInAccrualTicketItems.size() > 0);
        for (Integer i=0; i < TicketInAccrualTicketItems.size(); i+=1) {
          FX5__Ticket_Item__c ti = TicketInAccrualTicketItems.get(i);
          System.assertEquals((i+1)*10, ti.EXPRO_SAP_Item_Number__c);
        }
    }
    
    /*
    * This test ensures that a Ticket that does not have a status will not crash the Ticket On After trigger and will not cause any other 
    * unit tests to fail that do not have a status reference. 
     */
    static testMethod void TestInsertTicketWithNullStatus() {
      FX_UnitTestHelper.ExproJob_LocalTestData mockData = new FX_UnitTestHelper.ExproJob_LocalTestData();
        mockData.ProvisionTestData(true);
        
        RecordType ftRT = [select Id,DeveloperName from RecordType where IsActive=true and SobjectType='FX5__Ticket__c' and DeveloperName='Field_Ticket'];
        FX5__Ticket__c t = new FX5__Ticket__c(
          FX5__Job__c = mockData.testJob.Id,
          RecordTypeId = ftRT.Id
        );
        
        Test.startTest();
        insert t;        
        Test.stopTest();
        
        System.assertEquals(1,([select Id from FX5__Ticket__c where FX5__Job__c = :mockData.testJob.Id]).size());
    }
    
}

I want to forbid sending emails without a subject via SalesForce!

Or simply make the Email Subject A mandatory field!

Bests and Thank you

Hi All - I was so excited I was able to create this very "simple" trigger (so new to this) and when I went to deploy it to Prod I received a 0% Code Coverage error. Could someone please help me understand this code coverage madness and what I actually need to do? Is it an Apex Class? I'm so lost...any help is much appreciated, my trigger below for reference.

trigger AttachmentCount on Attachment (after insert)
{

List<lead> co = [select id, Attachment_Added__c from lead where id =:
Trigger.New[0].ParentId];
if(co.size()>0)
{
co[0].Attachment_Added__c = True;
update co;
}
}
I would like to divide a 24 hour day into 15 minute increments so a time worked can be selected from a picklist value and multiplied by the daily rate to get a total cost. the picklist is broken down into 15 minute increments as follows 00:15, 00:30, 00:45, 01:00, 01:15 and so on. Can anyonr advise me on the best way to do this?

Hi I am writing a trigger on opportunity

here is my code. the problem is i can see the opps.stagename in the debug statement, But i am get the compile error:Variable does not exist when using it within if statement. Can anyone help

 

trigger ClosedWon on Opportunity (before delete)
{
    if(system.Trigger.isDelete)
    {
    for (Opportunity Opps : trigger.old)
     System.debug('Opps'+Opps.StageName);
       Profile p = [SELECT Name FROM Profile WHERE Id = :Userinfo.getProfileId()];
       System.debug('Profile'+p);
        if(p.Name!='System Administrator')
        {
        System.debug('Opps           '+Opps.StageName);
         if (Opps.StageName == 'Closed Won')

            {
            
            Opps.addError('Cannot delete a Closed Won Opportunity');

            }
        }
    }



}

 

  • August 18, 2011
  • Like
  • 0