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
huskerwendyhuskerwendy 

Deployment To Production failed

I  created my first trigger and apex test class in the Sandbox. I had 100% code coverage and everything seemed to be working fine in the Sandbox. I used the Outbound Change Sets to deploy to production. When I validated the Inbound Change Set in my production environment, it failed and I don't understand what the error is.

 

API Name - KnowledgeController.null()

Type = Class

Problem = Failure Message: "line -1, column -1: Dependent class is invalid and needs recompilation: knowledgecontroller: line 292, column 16: No such column 'permissionsviewknowledge' on entity 'Profile'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the...

 

I don't understand why it says line 292 because I don't have anywhere close to 200 lines of code. Also, I'm not doing anything with knowledge base. How do I determine what is causing this error?

Thanks,

Wendy

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Hi Wendy,

 

can you try by changing the where clause during your assertion check. Because there might be some records in the system owned by User you are checking against.

 

for (VDDocs__c vd : [Select Account_Number__c from VDDocs__c where Account__c = :AccountID])
                    system.assertEquals('001234', vd.Account_Number__c);

 

I believe this will work for you.

 

with best,

crmtech

 

All Answers

Ritesh AswaneyRitesh Aswaney

If its not code you've written or know about, it could possibly be part of a package you've installed from the AppExchange or elsewhere ?

etienne.giraudyetienne.giraudy

yes the most probable scenario is that you have been testing Knowledge in your environment, but did not go further - Knowledge was then disabled.

And during your testing you have probably installed the AppExcahnge package "Sample Public Knowledge Base for Salesforce Knowledge".

 

You then need to remove (manually) the Apex classes and the VisualForce package from this package. (tip: they all have Knowledge in their name)

 

Let us know if this solves your issue!

Thanks

Etienne

huskerwendyhuskerwendy

Thanks for the replies. Etienne, I've taken over as Salesforce Admin from someone who has left the company and am not sure what all we have tested. I see that there is an app installed in both our production and sandbox orgs that is called "Sample Public Knowledge Base for Salesforce Knowledge". It looks like there are two apex classes installed - KnowledgeController and KnowledgeControllerTest. One thing I don't know is if it is being used. I've asked our support manager and she doesn't think we are using it.

 

However, if we are using it, how would I deploy my trigger and keep that active. When you say, I need to remove them manually from the Apex classes and the VisualForce package from this package what do you mean? I'm not sure how to do that.

 

Thanks so much for your help,

 

Wendy

huskerwendyhuskerwendy

Etienne, 

 

I removed the "Sample Public Knowledge Base for Salesforce Knowledge" app and validating the deploy got past that but now it's failing on the test class.  

 

Thanks for your help with the Knowledge base errors.

 

Wendy

Prafull G.Prafull G.

is the failure in your test class (created for the trigger) ?

If so, please ensure that the test class is not data dependent. I mean to say you dont have any hard coded SOQL in your test class.

 

If you wish you can share test class code so we can have better view to check the test failures.

 

with best,

 

huskerwendyhuskerwendy

Yes, the failure is in my test class.  The error is on Line 74: Failure Message: "System.AssertException: Assertion Failed: Expected: 001234, Actual: null", Failure Stack Trace: "Class.TestVDUpdateAccountNumber.testBulkInsert: line 74, column 21 External entry point". Here is my code.

@isTest
private class TestVDUpdateAccountNumber {
    static testMethod void testInsert() {
        List<VDDocs__c> vdDocs = new List<VDDocs__c>();

        // create user to run the test as
        User u = [select id from user where name = 'Lindsay Kelly'];
        
        // create test account
        Account testAccount = new Account(Name='Wendy Test Company Name', AccountNumber = '001234', Type = 'Client');
        insert testAccount;
        
        // get testAccount id
        String AccountID = testAccount.id;
        
        // test single insert
        VDDocs__c v = new VDDocs__c(
                Name = 'wendy test document' ,
                OwnerID = u.id,
                Account__c = AccountID,
                Work_Order_ID__c = '123456');
        
        Test.startTest();
                
        System.runAs(u) {       
            insert v;
        }
        Test.stopTest();
                
        // query for inserted doc
        list <VDDocs__c> insertedDocs = [SELECT Work_Order_ID__c, Account_Number__c FROM VDDocs__c WHERE Account__c = :AccountID];
                    
        for(VDDocs__c v1: insertedDocs){
            system.assertEquals('001234', v1.Account_Number__c);                   
        }
    }
     static testMethod void testBulkInsert() {
        List<VDDocs__c> vdDocs = new List<VDDocs__c>();
        List<account> accounts = new List<account>();
        
      // create user to run the test as
      User u = [select id from user where name = 'Lindsay Kelly'];   
      
      // create test account
      Account testAccount = new Account(Name='Wendy Test Company Name', AccountNumber = '001234', Type = 'Client');
      insert testAccount;
        
        // get testAccount id
      String AccountID = testAccount.id;
        
        // add 200 versadoc documents to the list to be inserted
      for (Integer i=0;i<200;i++) {
            
            VDDocs__c v = new VDDocs__c(
                Name = 'wendy test document' +i,
                OwnerID = u.id,
                Account__c = AccountID,
                Work_Order_ID__c = 'test'+i);
                
                vdDocs.add(v);
        }
                
                Test.startTest();
                
                // run as different user
                System.runAs(u) {
                insert vdDocs;
                }
            
                Test.stopTest();
                
                //query for all documents created and assert that the account number was added
                for (VDDocs__c vd : [Select Account_Number__c from VDDocs__c where OwnerID = :u.Id])
                    system.assertEquals('001234', vd.Account_Number__c);   
    }
    static testMethod void testUpdate() {
            // create user to run the test as
        User u = [select id from user where name = 'Lindsay Kelly'];
        
        // create test account
        Account testAccount = new Account(Name='New Company', AccountNumber = '001235', Type = 'Client');
        insert testAccount;
        
        String accountID = testAccount.id; 
        
        // create a new document
        // test single insert
        VDDocs__c v = new VDDocs__c(
                Name = 'new test doc' ,
                OwnerID = u.id,
                Account__c = AccountID,
                Work_Order_ID__c = '77887788');
        
        insert v;
        
        Test.startTest();
                
        System.runAs(u) {       
            // create test account for update
                Account testAccount1 = new Account(Name='New Company', AccountNumber = '001236', Type = 'Client');
                insert testAccount1;
                String accountID1 = testAccount1.id; 
        
            VDDocs__c vd = [select Account__c from VDDocs__c where id = :v.ID];
            
            vd.Account__c = accountID1;
            
            update vd;
        }
        Test.stopTest();
        
        // query for updated doc
        list <VDDocs__c> updatedDocs = [SELECT Account__c, Work_Order_ID__c, Account_Number__c FROM VDDocs__c WHERE Account__c = :accountID];
                    
        for(VDDocs__c v1: updatedDocs){
            system.assertEquals(accountID, v1.Account__c);              
        
      }  
    }
}

Here's the trigger code:

 

trigger UpdateAccountNumber on VDDocs__c (before insert, before update) {
    if (Trigger.isInsert){
        // create a set of all the unique accountIds
        Set<id> accountIds= new Set<id>();
        for (VDDocs__c v : Trigger.new)
           accountIds.add(v.Account__c); 
       
       // create a map for a lookup / hash table for the account info
        Map<id, Account> accts = new Map<id, Account>([Select AccountNumber from Account Where Id in :accountIds]);  
         
         // iterate over the list of records being processed in the trigger and set the AccountNumber
        for (VDDocs__c a : Trigger.new)
                a.Account_Number__c = accts.get(a.Account__c).AccountNumber; 
    } else{
        if (Trigger.isUpdate){
        
            Set<id> accountIds= new Set<id>();
            for (VDDocs__c v : Trigger.new) {
                if (Trigger.oldMap.get(v.Id).Account__c != Trigger.newMap.get(v.Id).Account__c) {
                    accountIds.add(v.Account__c); 
                }
            }
            
            // create a map for a lookup / hash table for the account info
            Map<id, Account> accts = new Map<id, Account>([Select AccountNumber from Account Where Id in :accountIds]);

            for (VDDocs__c v : Trigger.new) {
                if (Trigger.oldMap.get(v.Id).Account__c != Trigger.newMap.get(v.Id).Account__c) {
                    v.Account_Number__c = accts.get(v.Account__c).AccountNumber;
                }
            }
        }                
    }
}

 

 

 

I don't really know what I'm doing yet and am planning on going through the lab exercises. Any advice and help is greatly appreciated.

Wendy

 

Prafull G.Prafull G.

Hi Wendy,

 

can you try by changing the where clause during your assertion check. Because there might be some records in the system owned by User you are checking against.

 

for (VDDocs__c vd : [Select Account_Number__c from VDDocs__c where Account__c = :AccountID])
                    system.assertEquals('001234', vd.Account_Number__c);

 

I believe this will work for you.

 

with best,

crmtech

 

This was selected as the best answer
huskerwendyhuskerwendy

Thanks so much crmtech. That fixed it.