You need to sign in to do that
Don't have an account?
cjen
Need some help with @isTest - need coverage for queries only
hi, i have an apex class that just runs querries. I am trying to write the test class but failing to get any coverage. First of all, i am not too sure what i am testing here, just creating an account and a custom object related record, then query for it. My current test passes, but my controller still shows 0/23 code coverage? Any help much appreciated, thanks!
controller: public class extendAccountsChannel2 { public List <Investor_Channel__c> channels{get; set;} public List <Investor_Channel__c> channelsWholesale{get; set;} public List <Investor_Channel__c> channelsMiniCorrespondent{get; set;} public List <Investor_Channel__c> channelsCorrespondentAOTDirectTrade{get; set;} public List <Investor_Channel__c> channelsCorrespondentBestEfforts{get; set;} public List <Investor_Channel__c> channelsCorrespondentMandatoryBulkFlow{get; set;} public List <Investor_Channel__c> channelsCorrespondentNonDelegated{get; set;} public List <Investor_Channel__c> channelsCorrespondentNonDelMandatory{get; set;} public Account accounts {get;set;} public Account acc {get;set;} public extendAccountsChannel2(ApexPages.StandardController controller) { Id id = ApexPages.currentPage().getParameters().get('id'); if(ApexPages.currentPage().getParameters().get('id') != null){ id accRecId = [select id from Account where id = :id].id; if(accRecId != null){ channels = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Retail' AND Investor_Status__c = 'Active' LIMIT 1]; channelsWholesale = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Wholesale' LIMIT 1]; channelsMiniCorrespondent = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Mini Correspondent' LIMIT 1]; channelsCorrespondentAOTDirectTrade = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Correspondent AOT / Direct Trade' LIMIT 1]; channelsCorrespondentBestEfforts = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Correspondent Best Efforts' LIMIT 1]; channelsCorrespondentMandatoryBulkFlow = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Correspondent Mandatory (Bulk/Flow)' LIMIT 1]; channelsCorrespondentNonDelegated = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Correspondent Non Delegated' LIMIT 1]; channelsCorrespondentNonDelMandatory = [SELECT Id,name from Investor_Channel__c WHERE Account_Name__r.id= :accRecId AND Channel__c = 'Correspondent Non-Del Mandatory' LIMIT 1]; } } } }
@isTest private class extendAccountsChannel2_Test{ static testMethod void extendAccountsChannel2_channels(){ Account aa = new Account(); aa.name='TestInvestor'; insert aa; Investor_Channel__c ic = new Investor_Channel__c(); ic.Channel__c ='Retail'; ic.Account_Name__c = aa.Id; insert ic; //Verify that records were created for(Investor_Channel__c channels : [SELECT Id FROM Investor_Channel__c WHERE Account_Name__r.id = :aa.Id AND Channel__c ='Retail'LIMIT 1]){ } } }
I found an article that I think will help you resolve your issue. Please refer to this link: How to Test StandardController Classes (https://salesforce.stackexchange.com/questions/102740/how-to-write-test-class-for-standard-controller-along-with-extensions)
If you need additional help, feel free to reach out and I'll help you create a test code for this.