Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:38:46+00:00 2026-06-08T20:38:46+00:00

I have written a test for a Saleforce trigger. The trigger changes the Account_Status_Change_Date__c

  • 0

I have written a test for a Saleforce trigger. The trigger changes the Account_Status_Change_Date__c value to current date whenever the ‘Account_Status__c’ changes.

I have physically changed the value of the Account Status through the Web GUI and the Account Status Change Date is indeed set to the current date. However, my test code does not seem to be setting off this trigger. I wonder if people know of any reasons for this.

My code is as follows:

@isTest
public class testTgrCreditChangedStatus {

    public static testMethod void testAccountStatusChangeDateChanged() {

        // Create an original date
        Date previousDate = Date.newinstance(1960, 2, 17);

        //Create an Account
        Account acc = new Account(name='Test Account 1');
        acc.AccountNumber = '123';
        acc.Customer_URN_Number__c = '123';
        acc.Account_Status_Change_Date__c = previousDate;
        acc.Account_Status__c = 'Good';
        insert acc;

        // Update the Credit Status to a 'Bad Credit' value e.g. Legal
        acc.Account_Status__c = 'Overdue';
        update acc;

        // The trigger should have updated the change date to the current date
        System.assertEquals(Date.today(), acc.Account_Status_Change_Date__c);
    }
}

trigger tgrCreditStatusChanged on Account (before update) {

    for(Account acc : trigger.new) {
        String currentStatus = acc.Account_Status__c;
        String oldStatus = Trigger.oldMap.get(acc.id).Account_Status__c;

        // If the Account Status has changed...
       if(currentStatus != oldStatus) {
            acc.Account_Status_Change_Date__c = Date.today();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:38:48+00:00Added an answer on June 8, 2026 at 8:38 pm

    You do not need a trigger to do this. It can be done with a straightforward workflow rule on Account. However, the issue with your test code is that you need to query for the account after you update to get the updated values in the account field.

    public static testMethod void testAccountStatusChangeDateChanged() {
    
        ...
        insert acc;
    
        Test.StartTest();
        // Update the Credit Status to a 'Bad Credit' value e.g. Legal
        acc.Account_Status__c = 'Overdue';
        update acc;
        Test.StopTest();
    
        acc = [select Account_status_change_date__c from account where id = :acc.id];
        // The trigger should have updated the change date to the current date
        System.assertEquals(Date.today(), acc.Account_Status_Change_Date__c);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a simple script I have written to test command line argument handling:
I have written a ScalaCheck test case within Specs2. The test case gives up
I have written a JUnit test for a private function which is returning String.
I have written a function that sorts a big scale of data. To test
I have a haskell file test.hs. In this file I have written a function
I have some unit tests I've written to test my Django application. One test
I have a couple of test files written in my DSL in my tests
I have different projects written in .NET 3.5 and some unit test projects to
I have a test suite DLL written in C# that uses Selenium.This is then
I have written a test where i specify my application context location with annotations.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.