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
JoshTonksJoshTonks 

Test class not finding records to pass when using a WHERE in the apex class

Ive written a custom controller for visualforce components which sit on visualforce page embedded in a case. Im using getparameters to get the case id then doing a list look up to get the accountid from that case so i know which account to look up to.

My test class inserts an account and a case and the custom object which im trying to retrieve but the test class fails against my class when im trying to filter it WHERE to the current specific account if i take the WHERE out it passes but then the apex. Its the public Id ACTIDC which im trying to filter by in the MKMsgC
 
public string ACTID = ApexPages.currentPage().getParameters().get('id');
       	Date TODAY = Date.today();
    	Date SMON = TODAY.toStartOfMonth();
        Date MON12 = SMON.addMonths(-1);
        Date MON11 = SMON.addMonths(-2);
        Date MON10 = SMON.addMonths(-3);
        Date MON09 = SMON.addMonths(-4);
    	public Id ACTIDC = [SELECT AccountId FROM Case WHERE Id = :ACTID LIMIT 1].AccountId;
 
		List<Marketing_Messages__c>MKMsgC;
        Public List <Marketing_Messages__c>getMKMsgC(){
            MKMsgC = [SELECT Id, Active__c, Account__c, Lead__c, Month__c, URL__c, Marketing_Message__c
                    FROM Marketing_Messages__c
                    WHERE Account__c = :ACTIDC AND Active__c =: 'Yes'
                    ORDER BY Id DESC LIMIT 1];
            return MKMsgC;
            
        }

My test class as you can see inserts an Account, a Case and a Marketing Message (Custom object) 
 
static testMethod void testMKMsg() {
	
	Account Acc = new Account();
	Acc.UK_Canada__c = 'UK';
	Acc.Name = 'New Account Josh';
	Acc.Type = 'Lead';
	Acc.Phone = '01234567890';
        Acc.RecordTypeId = '012D0000000BFmd';
        Acc.Industry = 'Access Equipment';
        Acc.Industry_Sector__c = 'Service/Site Based';
	insert Acc;
        
	Case c = new Case();
	c.AccountId = Acc.Id;
	c.Type = 'Support Case to Review';
	c.Description = 'This is a test record';
	c.Status = 'New Case';
	c.Origin = 'Phone';
        c.RecordTypeId = '012D00000007RTg';
	insert c;
        
     Marketing_Messages__c MM = new Marketing_Messages__c();
     MM.Account__c = Acc.Id;
     MM.Active__c = 'Yes';
     MM.Marketing_Message__c = 'This is a test record for testing the class';
        
    insert MM;
        
    TKS_AccountUsageC TKS = new TKS_AccountUsageC();
    List <Marketing_Messages__c >ListMKMsg = TKS.getMKMsgC();
      
    }
If anyone can point me in the right direction id be massively appreciative.