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
Brian FordBrian Ford 

Inbound Change Set Throws Error 0% org coverage

I deployed a class with 98% coverage and 10 minutes later I deployed another class with 89% coverage but on the 2nd deployment I received the following error:

Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

Below the error message is a list of all 64 triggers we have in production. I've gone through and spot checked a few of these triggers and they do have coverage. Our system-wide coverage is 71% but my current deployment should raise that number to 75%. I haven't seen this error before, so any suggestions would help.
Best Answer chosen by Brian Ford
Looks like you class is not compiled properly in sanbox and isValid flag is not set to true.

the link below will help

All Answers

Brian FordBrian Ford
Looking deeper, all Apex Test Failures have the same error message.

CeligoCustomerCategory line 15, column 3: Illegal assignment from LIST<OpportunityPartner> to LIST<OpportunityPartner> Stack Trace: null
UtilsClass line -1, column -1: Previous load of class failed: celigocustomercategory Stack Trace: null

Here's the code in that class and below is the code that I'm deploying into production:
global class CeligoCustomerCategory {
  webservice static void putCeligoCustomerCategory(Id oppId){
    Account account;
    Id accId = [select id, accountId from Opportunity where id =: oppId ][0].accountId;
    boolean isPartner = getCustomerCategory(accId);
      account = new Account(id = accId, Celigo_Customer_Category__c = 'Partner');
      account = new Account(id = accId, Celigo_Customer_Category__c = 'Direct');    
    if(account != null)
      update account;
  webservice static boolean getCustomerCategory(Id accId){
    Map<Id, Opportunity> oppId_OppMap = new Map<Id,Opportunity>([select id, accountId from Opportunity where accountId =: accId]);
    List<OpportunityPartner> oppPartnerIds = [select 
                          id, AccountToId, OpportunityId, isDeleted
                            AccountToId =: accId
                            OpportunityId in: oppId_OppMap.keySet()
                            isDeleted = false];
    return((oppPartnerIds != null && oppPartnerIds.size()>0) ? true : false);                  

Class that I'm deploying
public with sharing class OpportunityPartner {
//  variable access modifier must be more accessible than getter/setter
//  set these instance variables as public
    public Opportunity opp              {get; private set;}
    public Partner__c partner           {get;set;}
    public List<wrapper> displayList    {get;set;} //list for all partner records and row counter
    public Integer rowToRemove          {get;set;}
    public List<Partner__c> delList     {get;set;}
    public OpportunityPartner(ApexPages.StandardController std) {
        String retURL = ApexPages.currentPage().getParameters().get('retURL');
        displayList = new List<wrapper>();
        if (retURL != null) {
            Integer oppStartNum = retURL.indexOf('006');
            String oppId = retURL.mid(oppStartNum,15);
            this.opp = [SELECT Id, Name FROM Opportunity WHERE Id = :oppId];
        } else {
            String partnerId = ApexPages.currentPage().getParameters().get('id');
            this.partner = (Partner__c)std.getRecord();
            this.opp = [SELECT Opportunity__r.Id, Opportunity__r.Name FROM Partner__c WHERE Id = :partner.Id].Opportunity__r;
        Integer counter = 0;
        for (Partner__c p : [SELECT Id, Opportunity__c, Partner_Name__c, Partner_Role__c, Primary_Partner__c, Partner_Registered__c
                            FROM Partner__c 
                            WHERE Opportunity__c = :opp.Id]) {
            displayList.add(new wrapper(p, counter));
        if (displayList.size() == 1) {
        	displayList[0].partner.Primary_Partner__c = true;
    public void add() {
        Integer newCounter = displayList.size();
        displayList.add(new wrapper(new Partner__c(Opportunity__c = opp.Id), newCounter));
        if (displayList.size() == 1) {
        	displayList[0].partner.Primary_Partner__c = true;
    public void remove() {
        delList = new List<Partner__c>();
        if (displayList.size() == 1) {
        	displayList[0].numOfRow = 0;
            rowToRemove = 0;
        if (displayList[rowToRemove].partner.Id != null) {
            Partner__c pDelete = displayList[rowToRemove].partner;
        if (!delList.isEmpty()) {
            try {
                delete delList;    
            } catch (Exception e) {}
    public PageReference saveNew() {
        List<Partner__c>pList = new List<Partner__c>();
        Integer pCount = 0;
        for (wrapper w : displayList) {
            if (w.partner.Primary_Partner__c)
        if (pCount > 1) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Please select only 1 partner as the primary'));
            return null;
        } else if (pCount == 0 && displayList.size() > 0) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Please indicate the primary partner before saving'));
            return null;
        } else {
            try {
                upsert pList;
            } catch (Exception e){}
            PageReference oppReturn = new PageReference('/' + opp.Id);
            return oppReturn;
    public PageReference cancel() {
        PageReference pr = new PageReference('/' + opp.Id);
        return pr;
    public class wrapper {
        public Partner__c partner {get;set;}
        public Integer numOfRow   {get;set;}
        public wrapper (Partner__c p, Integer rowCounter) {
            this.partner = p;
            this.numOfRow = rowCounter;

Test Class
public class OpportunityPartnerTest {

	public static testMethod void testOpportunityPartner() {
        //create test data
        Account[] accounts = DataFactory.createAccount(5);
        Contact[] contacts = DataFactory.createContact(3, accounts);
        Campaign[] campaign = DataFactory.createCampaign(1);
        Opportunity[] opportunities = DataFactory.createOpportunity(accounts, campaign, 1);
        //create partner record for standard controller
        Partner__c p = new Partner__c(Partner_Role__c='Other',Opportunity__c=opportunities[0].id, Partner_Name__c=accounts[1].id);
        insert p;
        //add retURL to VF page URL; throwa an error if no retURL or partnerId
        //instantiate standard controller and pass it as a parameter to the extension
        ApexPages.StandardController stdController = new ApexPages.StandardController(p);
        OpportunityPartner controller = new OpportunityPartner(stdController);
        //test saveNew() positive
        String nextPage = controller.saveNew().getUrl();
        System.assertEquals('/' + opportunities[0].id, nextPage);
		//test add() positive
		Integer displayList = controller.displayList.size();
        System.assertEquals(2, displayList);
        //test remove() positive
        controller.rowToRemove = 1;
        Integer displayList2 = controller.displayList.size();
        System.assertEquals(1, displayList2);
        //test remove() positive delete
        controller.rowToRemove = 0;
        Integer pCount = [SELECT count() FROM Partner__c];
        System.assertEquals(0, pCount);
        //test cancel() positive
        String cancelPage = controller.cancel().getURL();
        System.assertEquals('/' + opportunities[0].id, cancelPage);

Looks like you class is not compiled properly in sanbox and isValid flag is not set to true.

the link below will help
This was selected as the best answer
Brian FordBrian Ford
Thanks Balaji! I was compiling in production but didn't think to do it in the sandbox. That led to solving the actual problem which is that the new class I'm trying to deploy is the same name as the standard OpportunityPartner object.