• Cody Sanders 33
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 3
    Replies
We are using scratch orgs for our development and are facing very peculiar issue. Even when Knowledge feature is already ENABLED in the orgs, when we are pushing the code to our org or even when we are running simple query on SObject Knowledge__kav object.

Query below is giving this error
SELECT Id, Title FROM Knowledge__kav

Error: sObject type 'Knowledge__kav' is not supported

Pushing code with a Tab attached to standard Knowledge__kav object to scratch org is giving error:
no CustomObject named Knowledge__kav found

Any help is highly appreciated.
I'm currently working on a sandbox record creation class so I can prepopulate a couple records when refreshing sandboxes. However, I'm very inexperienced with Apex code and am hitting query limits, most likely because I'm having to look up the records previously created in the class. Is there a way that I can set the newly created record in the class so that I can then use the record ID as a variable in later methods? Basically all the queries here should be variables.
Here's the class:
public class SandboxClass {
    // Use this method to insert the accounts, the contacts, and the donations
    // you will need one method per object here is the account method
    public Account InsertCouplesAccount(){
        Account Acct1 = new Account();
        Acct1.Name='Couples Household';
        Acct1.Type='Household';
        Acct1.Location__c='City';
        Acct1.BillingCity ='City';
        Acct1.BillingCountry='United States';
        Acct1.BillingStreet='123 Test St.';
        Acct1.BillingState='Illinois';
        Acct1.BillingPostalCode='12345';   
        
        
        insert Acct1;
        return Acct1;
    } 
    public  Account InsertSingleAccount() {
    	Account Acct2 = new Account();
        Acct2.Name='Single Household';
        Acct2.Type='Household';
        Acct2.Location__c='Town';
        Acct2.BillingCity ='Indescript City';
        Acct2.BillingCountry='United States';
        Acct2.BillingStreet='321 Testing St.';
        Acct2.BillingState='Illinois';
        Acct2.BillingPostalCode='54321';
        
        insert Acct2;
        return Acct2;
    } 
    public Contact InsertHusbandContact() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact HusbCon = new Contact();
        HusbCon.Salutation = 'Mr.';
        HusbCon.FirstName = 'John';
        HusbCon.LastName = 'Couples';
        HusbCon.AccountId = Acct.Id;
        
        insert HusbCon;
        return HusbCon;
    }
    public Contact InsertWifeContact() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact HusbCon = [SELECT Id FROM Contact WHERE LastName = 'Couples'];
        Contact WifeCon = new Contact();
        WifeCon.Salutation = 'Mrs.';
        WifeCon.FirstName = 'Jane';
        WifeCon.LastName = 'Couples';
        WifeCon.AccountId = Acct.Id;
        WifeCon.Spouse__c = HusbCon.Id;
        
        insert WifeCon;
        return WifeCon;
    }
    public Contact UpdateHusbandContact() {
        Contact HusbCon = [SELECT Id FROM Contact WHERE FirstName = 'John'];
        Contact WifeCon = [SELECT Id FROM Contact WHERE FirstName = 'Jane'];
        HusbCon.Spouse__c = WifeCon.Id;
        
        update HusbCon;
        return HusbCon;
    }
    public Contact InsertSingleContact() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact SingCon = new Contact();
        SingCon.Salutation = 'Mr.';
        SingCon.FirstName = 'Jack';
        SingCon.LastName = 'Single';
        SingCon.AccountId = Acct.Id;
        
        insert SingCon;
        return SingCon;
    }
    public Opportunity InsertCoupleDonation1() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'John'];
        Opportunity Don1 = new Opportunity();
        Don1.AccountId = Acct.Id;
        Don1.Contact__c = Cont.Id;
        Don1.StageName = 'Posted';
        Don1.Name = 'Couple Donation 1';
        Don1.Amount = 15;
        Don1.CloseDate = System.today();
        Don1.Location__c = 'City';
        Don1.Method_of_Payment__c = 'Cash';
        Don1.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don1;
        return Don1;
    }
    public Opportunity InsertCoupleDonation2() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Couples Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jane'];
        Opportunity Don2 = new Opportunity();
        Don2.AccountId = Acct.Id;
        Don2.Contact__c = Cont.Id;
        Don2.StageName = 'Posted';
        Don2.Name = 'Couple Donation 2';
        Don2.Amount = 20;
        Don2.CloseDate = System.today();
        Don2.Location__c = 'Town';
        Don2.Method_of_Payment__c = 'Credit Card';
        Don2.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don2;
        return Don2;
    }
    public Opportunity InsertSingleDonation1() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jack'];
        Opportunity Don3 = new Opportunity();
        Don3.AccountId = Acct.Id;
        Don3.Contact__c = Cont.Id;
        Don3.StageName = 'Posted';
        Don3.Name = 'Single Donation 1';
        Don3.Amount = 10;
        Don3.CloseDate = System.today();
        Don3.Location__c = 'City';
        Don3.Method_of_Payment__c = 'Cash';
        Don3.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don3;
        return Don3;
    }
    public Opportunity InsertSingleDonation2() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jack'];
        Opportunity Don4 = new Opportunity();
        Don4.AccountId = Acct.Id;
        Don4.Contact__c = Cont.Id;
        Don4.StageName = 'Posted';
        Don4.Name = 'Single Donation 2';
        Don4.Amount = 25;
        Don4.CloseDate = System.today();
        Don4.Location__c = 'Town';
        Don4.Method_of_Payment__c = 'Cash';
        Don4.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don4;
        return Don4;
    }
    public Opportunity InsertSingleDonation3() {
        Account Acct = [SELECT Id FROM Account WHERE Name = 'Single Household'];
        Contact Cont = [SELECT Id FROM Contact WHERE FirstName = 'Jack'];
        Opportunity Don5 = new Opportunity();
        Don5.AccountId = Acct.Id;
        Don5.Contact__c = Cont.Id;
        Don5.StageName = 'Posted';
        Don5.Name = 'Single Donation 3';
        Don5.Amount = 45;
        Don5.CloseDate = System.today();
        Don5.Location__c = 'Town';
        Don5.Method_of_Payment__c = 'Cash';
        Don5.RecordTypeId ='0121N000000uGN8QAM';

        
        insert Don5;
        return Don5;
    }
}

 
Hello, i'm an admin who is rather inexperienced at Apex but this project was kind of dumped in my lap by a developer who has other positions he's filling right now, and I am in need of help since I can't find an answer to my particular problem. I am trying to test this query class and the test class keeps bringing the "attempt to de-reference a null object" error and I'm super confused. It's referring to line 6 in the test class so something with invoking the class is off, it seems but my lack of knowledge isn't particularly helping me figure out what I need to do. I'll leave the code for the class and test class below:
Class
public class AlroOrderBoMQuery {
	public Production_Tracking_Record__c custObj;
    public string HsgMat { get; set; }
    public string ECMat { get; set; }
    public string WPMat { get; set; }
    public string ThrtMat { get; set; }
    public string LnrMat { get; set; }
    
public AlroOrderBoMQuery(){
    }    
    
    public AlroOrderBoMQuery(ApexPages.StandardController controller){
        custObj=(Production_Tracking_Record__c)controller.getRecord();
        
           }
		Production_Tracking_Record__c ptr = [Select Id, Name, Product__c from Production_Tracking_Record__c where id =: custObj.Id limit 1];
    	
    	Product2 prod = [Select Id, Housing_Assembly__c, Drive_Endcap_Assembly__c, Tail_Endcap_Assembly__c, Housing_Material__c, Liner_Material__c, Endcap_Material__c, Wearplate__c, Housing_Throat_Plates__c from Product2 where id =: ptr.Product__c limit 1];
    	{
        HsgMat = prod.Housing_Material__c;
        ECMat = prod.Endcap_Material__c;
        WPMat = prod.Wearplate__c;
        ThrtMat = prod.Housing_Throat_Plates__c;
        LnrMat = prod.Liner_Material__c;
    	}
		List<Housing_Assembly_Attachment__c> HsgAsmAtt = [SELECT Quantity__c, Name, Id, Housing_Assembly__c FROM Housing_Assembly_Attachment__c WHERE Housing_Assembly__c =: prod.Housing_Assembly__c];
    	public List<Housing_Assembly_Attachment__c> getHsgAsmAtt() {
        return HsgAsmAtt;
    	   }
    	List<Endcap_Assembly_Attachment__c> DECAsmAtt = [SELECT Quantity__c, Name, Id, Endcap_Assembly__C FROM Endcap_Assembly_Attachment__c WHERE Endcap_Assembly__c =: prod.Drive_Endcap_Assembly__c];
    	public List<Endcap_Assembly_Attachment__c> getDECAsmAtt() {
        return DECAsmAtt;
    	   }
    	List<Endcap_Assembly_Attachment__c> TECAsmAtt = [SELECT Quantity__c, Name, Id, Endcap_Assembly__C FROM Endcap_Assembly_Attachment__c WHERE Endcap_Assembly__c =: prod.Tail_Endcap_Assembly__c];
    	public List<Endcap_Assembly_Attachment__c> getTECAsmAtt() {
        return TECAsmAtt;
    	}

    	
}

Test Class
@isTest
    private class TestAlroOrderBoMQuery {
        public static List<Opportunity> OpportunityList;
    
      static testMethod void TestAlroOrderBoMQuery() {
          AlroOrderBoMQuery BOM = new AlroOrderBoMQuery();

         
        Make__c make = new Make__c(Name='Kice');
        insert make;
        Model__c model = new Model__c(Name='Kice VJ 14x10x10',
                                     Make__c=make.Id,
                                     Product_Passage__c='Drop Thru');
        insert model;
        Housing_Assembly__c hsasm = new Housing_Assembly__c(Name='Kice Housing 1',
                                                            Model__c=model.Id,
                                                            Product_Passage__c='Drop-Through',
                                                            Housing_Type__c='Rebuild',
                                                            verified__c=true);
        insert hsasm;
        Housing_Assembly_Attachment__c hsasmatt = new Housing_Assembly_Attachment__c(Name='Drawing 1',
                                                                                    Housing_Assembly__c=hsasm.Id,
                                                                                    Quantity__c=1);
        insert hsasmatt;
        Attachment hsgatt = new Attachment(Name='Test Housing Attachment.jpg',
                                        ParentId=hsasmatt.Id,
                                        Body=Blob.valueOf('Test Housing Attachment'),
                                        IsPrivate=false);
        insert hsgatt;
        Endcap_Assembly__c ecasm = new Endcap_Assembly__c(Name='Kice Endcap 1',
                                                          Model__c=model.Id,
                                                          Endcap_Type__c='Rebuild',
                                                          Configuration__c='Inboard',
                                                          verified__c=true);
        insert ecasm;
        Endcap_Assembly_Attachment__c ecasmatt = new Endcap_Assembly_Attachment__c(Name='Drawing 2',
                                                                                    Endcap_Assembly__c=ecasm.Id,
                                                                                    Quantity__c=1);
        insert ecasmatt;
        Attachment ecatt = new Attachment(Name='Test Endcap Attachment.jpg',
                                        ParentId=hsasmatt.Id,
                                        Body=Blob.valueOf('Test Endcap Attachment'),
                                        IsPrivate=false);
        insert ecatt;
        Product2 prod = new Product2(Name='Test Product',
                                     Family='Kice',
                                     IsActive=true,
                                     Inboard_or_Outboard__c='Inboard',
                                     Rotor_Configuration__c='Open Fixed',
                                     Product_Passage__c='Drop Thru',
                                     Housing_Type__c='Rebuild',
                                     RecordTypeId='012G0000000qdfL',
                                     Make_Lookup__c=make.Id,
                                     Model_Lookup__c=model.Id,
                                     Housing_Assembly__c=hsasm.Id,
                                     Drive_Endcap_Assembly__c=ecasm.Id,
                                     Tail_Endcap_Assembly__c=ecasm.Id,
                                     Verified__c=true);
        insert prod;
        PricebookEntry PBE = new PricebookEntry(IsActive=true,
                                                UnitPrice=1000,
                                                UseStandardPrice=false,
                                                Pricebook2Id='01sG00000001zX0',
                                                Product2Id=prod.Id);
        insert PBE;
        Account acct = new Account(Name='Test Account',
                                   Type='Direct Customer',
                                   Shipping__c='Prepaid',
                                   Ship_Via__c='UTS',
                                   Sales_Discount__c=0);
        insert acct;
        Opportunity opp = new Opportunity(Name='12345',
                                          RA__c='12345',
                                          StageName='Quote Sent',
                                          CloseDate=System.today(),
                                          AccountId=acct.Id,
                                          Product__c=prod.Id,
                                          Make__c='Kice',
                                          Model__c='VJ 14x10x10',
                                          Max_Temp__c='120',
                                          Serial__c='N/A',
                                          Cold_Clr_Radial__c='.004-.007',
                                          Cold_Clr_Side__c='.004-.007');
        insert opp;
        Quote quote = new Quote(Name=opp.RA__c,
                                OpportunityId=opp.Id,
                                Pricebook2Id='01sG00000001zX0');
        insert quote;
        /*QuoteLineItem QLI = new QuoteLineItem(QuoteId=quote.Id,
                                              Product2Id=prod.Id,
                                              Quantity=1,
                                              PricebookEntryId=PBE.Id,
                                              UnitPrice=1000,
                                              Additional_Charges__c=0,
                                              Discounted_Amount__c=0,
                                              Core_Charge__c=0,
                                              Credit_Amount__c=0,
                                              Shipping_and_Handling__c=0,
                                              Rush_Charges__c=0);
        insert QLI; */
        
        
        Test.startTest();
        Production_Tracking_Record__c PTR = new Production_Tracking_Record__c(Name='12345',
                                                                              RA__c=opp.Id,
                                                                              Product__c=prod.Id,
                                                                              Housing_and_Endcaps_Order_Date__c=null,
                                                                              Shaft_Steps_on_Drive_End__c='1');
        insert PTR;
                  
        Test.stopTest();
        
        Production_Tracking_Record__c newptr = [ select id from Production_Tracking_Record__c where id =: BOM.custObj.Id];
        System.assertNotEquals('', BOM.custObj.Id, 'There is no ID');
        
        
    }
}
When I save there's not an error, but tests keep failing. If anyone could help, I'd greatly appreciate it!