• Kevin Kneip
  • 5 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
  • 3
I acquired the Apex trigger below and I've been trying to create a test class for it but I keep getting 0 coverage. Would anyone have any tips on how to create this?
Trigger AccountHistoryTracker on Account (after update) {

final List<Schema.FieldSetMember> trackedFields = 

if (trackedFields.isEmpty()) return;

final List<AccountHistoryTracking__c> fieldChanges = 
    new List<AccountHistoryTracking__c>();


for (Account newAccount : trigger.new) {

    final Account oldAccount = trigger.oldmap.get(newAccount.Id);

    for (Schema.FieldSetMember fsm : trackedFields) {

        String fieldName  = fsm.getFieldPath();
        String fieldLabel = fsm.getLabel();
     System.debug( fieldname + fieldLabel );

        if (newAccount.get(fieldName) == oldAccount.get(fieldName))

        String oldValue = String.valueOf(oldAccount.get(fieldName));
        String newValue = String.valueOf(newAccount.get(fieldName));

        if (oldValue != null && oldValue.length()>255) 
            oldValue = oldValue.substring(0,255);

        if (newValue != null && newValue.length()>255) 
            newValue = newValue.substring(0,255); 

        final AccountHistoryTracking__c accountHistory = 
            new AccountHistoryTracking__c();

        accountHistory.apiName__c   = fieldName;
        accountHistory.Account__c      = newAccount.id;
        accountHistory.OldValue__c  = oldValue;
        accountHistory.NewValue__c  = newValue;


if (!fieldChanges.isEmpty()) {
    insert fieldChanges;


I created a simple checkbox field on a custom object that "checks" if another DateTime field is TODAY. It works great... however there is a discrepancy between the Details page, View and Reports. The Details page Checkbox field "checks" at 12am however, the View and Reports only checks after 1am. Does anyone know of a bug or why in one place the field works and nother the field won't.

I need to be able to highlight a row within a view to indicate that the case is due today. Please let me know how I can achieve that.
I'd like to create a flow that our HR department can use for onboarding a new hire that creates a user account and configures settings such as assigning a managed package, setting a role, setting a profile, etc.

I haven't found a lot of information on this... is it even possible?
I am trying to implement my own email-to-case class and I have the following code, which is working in my sandbox, to create an EmailMessage on a case using email services:
EmailMessage[] newEmail = new EmailMessage[0];
newEmail.add(new EmailMessage(FromAddress = email.fromAddress,
FromName = email.fromName,
ToAddress = email.toAddresses[0],
Subject = email.subject,
TextBody = email.plainTextBody,
HtmlBody = email.htmlBody,
ParentId = newCase[0].Id, 
ActivityId = newTask[0].Id));   // (newCase and newTask are the newly created case and task from earlier code)
insert newEmail;
I have several questions.  Is it possible to set the email message status to "New"?  If I attempt to add "Status = 'New'" in the .add() method I get an error: Message: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Status: bad value for restricted picklist field: New: [Status] null.  If I don't attempt to set the status, it defaults to "Sent".
Also, does anyone have any sample code to share that adds headers and attachments from an inbound email to an Email Message object?  I'm struggling with that one.
Another minor issue that is bugging me is that in the Email Section of the Case page in my sandbox, the column labelled "Email Address" shows the 'to address' and my production version using the the standard SFDC email to case application will have the 'from address' (contact's address) displayed.  Does anyone know what field in the Email Message object this data comes from?
Thanks for the help!
Salesforce has history tracking for many objects but nothing for accounts that I can tell. 
It sounds like Apex will be able to help us here but is it the best solution?  Are their other ways to do this?
Our current business problem is history tracking on the account level, there are several extremely important fields and we need to know:
-When they changed
-Who changed them
-What value was before change
-What value is after change
We could create a custom object called "Account History" that could store all the relevant info. Using APEX can we create one of these "Account History" objects each time an account is Created\Updated\Saved?
We are going through an audit and our auditors want a see a way to track... well almost everything!
Can I do it using Apex?  Or should I do it some other way?