• David Langan -Carte
  • NEWBIE
  • 0 Points
  • Member since 2013

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

I've created my first Trigger (yay me) to automatically update a picklist field on a custom Policy object to "Pending" when a task has been created with something selected from the custom "Type_of_Action" field.  I've also written a test class; however I'm getting an error:  "System.AssertException: Assertion Failed: Expected: Pending, Actual: Null"

 

Below is the Trigger and Test Class - any help would be greatly appreciated.

 

 

trigger policyStatusUpdate onTask (beforeinsert, beforeupdate) {

String desiredNewPolStatus = 'Pending';

 

    List<Id> polIds=new List<Id>();

    for(Task t:trigger.new) {

        if (t.IsClosed==FALSE){

            if(String.valueOf(t.whatId).startsWith('a06d') && (t.Type_of_Action__c != null)==TRUE) {//check if the task is associated with a policy

                polIds.add(t.whatId);

            }//if 2

        }//if 1

    }//for

    List<Policy__c> polToUpdate=[SELECT Id, Status__c FROM Policy__c WHERE Id IN :polIds];

    For (Policy__c l:polToUpdate){

        l.Status__c=desiredNewPolStatus;

    }//for

    

    try{

        update polToUpdate;

    }catch(DMLException e){

        system.debug('Policies were not all properly updated.  Error: '+e);

    }

}

 

TEST CLASS:

 

@isTest

 

private class policyStatusUpdate { 

 

    static testMethod void myUpdateTest() {

//CREATE A POLICY RECORD 

    Policy__c aDS = new Policy__c(name='TestPolicy1', Policy_Holder_Name__c='001d000000AoHIr');

    insert aDS; 

 

//CREATE A TASK ASSIGNED TO THE POLICY

        Task t1 = new Task(subject='testupdate 1', WhatId = aDS.id, description = 'test description', Type_of_Action__c='Medicals');     

 

        insert t1;   

 

//RUN AN ASSERT CALL TO MAKE SURE THAT THE CUSTOM FIELD ON THE POLICY HAS THE VALUE OF PENDING

Policy__c assertToTest = [Select Status__c from Policy__c where id = :aDS.id];

system.AssertEquals('Pending', assertToTest.Status__c);

    

    }

}

I've created my first Trigger (yay me) to automatically update a picklist field on a custom Policy object to "Pending" when a task has been created with something selected from the custom "Type_of_Action" field.  I've also written a test class; however I'm getting an error:  "System.AssertException: Assertion Failed: Expected: Pending, Actual: Null"

 

Below is the Trigger and Test Class - any help would be greatly appreciated.

 

 

trigger policyStatusUpdate onTask (beforeinsert, beforeupdate) {

String desiredNewPolStatus = 'Pending';

 

    List<Id> polIds=new List<Id>();

    for(Task t:trigger.new) {

        if (t.IsClosed==FALSE){

            if(String.valueOf(t.whatId).startsWith('a06d') && (t.Type_of_Action__c != null)==TRUE) {//check if the task is associated with a policy

                polIds.add(t.whatId);

            }//if 2

        }//if 1

    }//for

    List<Policy__c> polToUpdate=[SELECT Id, Status__c FROM Policy__c WHERE Id IN :polIds];

    For (Policy__c l:polToUpdate){

        l.Status__c=desiredNewPolStatus;

    }//for

    

    try{

        update polToUpdate;

    }catch(DMLException e){

        system.debug('Policies were not all properly updated.  Error: '+e);

    }

}

 

TEST CLASS:

 

@isTest

 

private class policyStatusUpdate { 

 

    static testMethod void myUpdateTest() {

//CREATE A POLICY RECORD 

    Policy__c aDS = new Policy__c(name='TestPolicy1', Policy_Holder_Name__c='001d000000AoHIr');

    insert aDS; 

 

//CREATE A TASK ASSIGNED TO THE POLICY

        Task t1 = new Task(subject='testupdate 1', WhatId = aDS.id, description = 'test description', Type_of_Action__c='Medicals');     

 

        insert t1;   

 

//RUN AN ASSERT CALL TO MAKE SURE THAT THE CUSTOM FIELD ON THE POLICY HAS THE VALUE OF PENDING

Policy__c assertToTest = [Select Status__c from Policy__c where id = :aDS.id];

system.AssertEquals('Pending', assertToTest.Status__c);

    

    }

}