I know this is a popular topic but I am still stuck, would appreciate it a lot if i could get some help figuring out why I can't deploy this trigger and test class, it work perfectly fine in the sandbox and the test finish with 100% coverage but when I try to deploy it I get 0%.

I run specific tests when validating selecting only the two test classes I have created for the code.

trigger newLegalDocRecOnAccount on Account (after insert) {
    for (Account newAccount: trigger.New) {
        Legal_Document__c legalDoc = new Legal_Document__c(
            CB_folder__c = newAccount.Id,
            Name = newAccount.Name,
            OwnerId = newAccount.OwnerId
        insert legalDoc;
        contentVersion readMeFile = new contentVersion(
            PathOnClient = 'Readme.txt',
            VersionData = Blob.valueOf('The content of the readme file\nA second line in the readme file'),
            FirstPublishLocationId = legalDoc.Id
        insert readMeFile; 
public class testNewLegalDocRecOnAccount {
    static testMethod void insertNewAccount() {
        Account testAccount = TestDataFactory.getAccount('testLegalDoc','SEK','Telco','Telecom Multiservice','EUR',false);
        insert testAccount;

        boolean legalDocisDone;
        list<Legal_Document__c> legalDoc = [select name from Legal_Document__c WHERE CB_folder__c=:testAccount.Id];
            legalDocisDone = true;            
        System.debug('testNewLegalDocRecOnAccount legalDoc: '+legalDoc); 
        System.assertEquals(legalDocisDone, true);
public class TestDataFactory {
    public static Account getAccount(String name, string CurrencyIsoCode, string BusinessLine, string Industry, string Region, boolean doInsert){
        Account acc = new Account();
        acc.Name = name;
        acc.CurrencyIsoCode = CurrencyIsoCode;
        acc.Business_Line__c = BusinessLine;
        acc.Industry = Industry;
        acc.Region__c = Region;  
            INSERT acc;
        return acc;
  • 5
    You need to include the test class(es) in your changeset to be able to run the tests to deploy your changeset to your desired org.
    – Derek F
    Aug 30, 2021 at 13:48
  • But I do include the test class in the change set, I also explicit point out that the test should be run Aug 31, 2021 at 4:45
  • Firstly, You stated, "...selecting only the two test classes...." Are you including the TestDataFactory? I don't know whether it is a copy/paste mistake or it is actually this way, but TestDataFactory should be designated @isTest. Secondly, Does your deployment consist only of these three classes?
    – Moonpie
    Aug 31, 2021 at 11:36

3 Answers 3


I've seen this a number of times. My guess is that there have been changes made to the production org, so when you deploy you are getting an error during test execution. This is most likely to be at Account creation (though could be at the document creation). Check that you can manually create an identical account in production, I suspect that you'll see an error (i.e. a field that is now mandatory, or a process builder error, etc).


Well, I finally figured it out. In the target org there was a mandatory field not present in my sandbox and the test class failed on this.

Thanks for your suggestions though.


For others that experience this issue:

You might want to deploy the change-set to a sandbox recently refreshed from production without running tests or validation. You just want to get the changes in that environment.

Then, run each of the tests independently within that sandbox to see where the failures are. Chances are it's something like a newer validation rule or required field.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .