function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lauren HonyotskiLauren Honyotski 

Pardot Person Accounts Trigger

I was able to get this trigger working in Sandbox, but when I tried to upload to production via change set, I received code coverage errors. Pardot is telling me to use the force.com IDE, however we do not have experience with that tool. Any ideas why this trigger cannot be uploaded to production throught a change set? The Pardot package has been installed.

trigger LogPersonAccountChange on Account (before delete, after insert, after undelete)
{
  List<pi__ObjectChangeLog__c> logs = new List<pi__ObjectChangeLog__c>();
 
  if (Trigger.new != null) {
    for (Account account : Trigger.new) {
 
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
        log.pi__ObjectFid__c = Account.PersonContactId;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
 
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
 
        }
        logs.add(log);
      }
    }
  } else if (Trigger.old != null) {
    for (Account account : Trigger.old) {
      if (Account.PersonEmail != null && Account.PersonEmail != '') {
        pi__ObjectChangeLog__c log = new pi__ObjectChangeLog__c();
 
        log.pi__ObjectFid__c = Account.PersonContactId
 
        ;
        log.pi__ObjectType__c = 1;
        log.pi__ObjectEmail__c = Account.PersonEmail;
        if  (System.Trigger.isInsert) {
          log.pi__ObjectState__c = 1;
        } else if  (System.Trigger.isDelete) {
          log.pi__ObjectState__c = 2;
        } else if  (System.Trigger.isUnDelete) {
          log.pi__ObjectState__c = 3;
        }
        logs.add(log);
      }
    }
  }
 
  if (logs.size() > 0) {
 
    insert logs;
  }
}
 
Best Answer chosen by Lauren Honyotski
Shashikant SharmaShashikant Sharma
You need to develop test class for the trigger and move it with your trigger to production.

Read this for test class development : http://forceschool.blogspot.in/2011/06/testing-trigger-structure.html

All Answers

Shashikant SharmaShashikant Sharma
You need to develop test class for the trigger and move it with your trigger to production.

Read this for test class development : http://forceschool.blogspot.in/2011/06/testing-trigger-structure.html
This was selected as the best answer
Lauren HonyotskiLauren Honyotski
Thanks, this worked.