You need to sign in to do that
Don't have an account?
Eric Blaxton 11
Issues with a simple SOQL Query test class...no coverage at all.
Hi and thanks in advance for your help. I wrote this test and can't figure out why I can't get any coverage. Seems so simple.
public with sharing class AccountStatus
{
@AuraEnabled
public static Account getAccount(Id accountId)
{
//Query fields from Parent record to prepopulate New RTO
return [SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,
BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,
Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,
Current_Brand__c
FROM Account where id = :accountId];
}
}
Test class
@isTest
private class AccountStatusTest
{
static testMethod void getAccount()
{
Account a = new Account();
a.name='Test';
a.phone='12345';
a.Account_Status__c = 'Active Account';
a.Bill_To_DUNs_Number__c = '1234567890';
a.BillingCountry = 'United States';
a.BillingStreet = 'Main Street';
a.BillingCity = 'Dallas';
a.BillingState = 'Texas';
a.BillingPostalCode = '76543';
a.Billing_County__c = 'Blackland';
a.BillingStateCode = 'TX';
a.Legal_Entity_Name__c = 'TestParent';
a.Type__c = 'Retail Outlet';
// a.Account_Record_ID__c = '0120W000001USkRQAW';
a.Current_Brand__c = 'Sunoco';
insert a;
Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,
BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,
Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,
Current_Brand__c
FROM Account where id = :a.id];
System.assert(a2!=null);
}
}
Thank You,
Eric
public with sharing class AccountStatus
{
@AuraEnabled
public static Account getAccount(Id accountId)
{
//Query fields from Parent record to prepopulate New RTO
return [SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,
BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,
Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,
Current_Brand__c
FROM Account where id = :accountId];
}
}
Test class
@isTest
private class AccountStatusTest
{
static testMethod void getAccount()
{
Account a = new Account();
a.name='Test';
a.phone='12345';
a.Account_Status__c = 'Active Account';
a.Bill_To_DUNs_Number__c = '1234567890';
a.BillingCountry = 'United States';
a.BillingStreet = 'Main Street';
a.BillingCity = 'Dallas';
a.BillingState = 'Texas';
a.BillingPostalCode = '76543';
a.Billing_County__c = 'Blackland';
a.BillingStateCode = 'TX';
a.Legal_Entity_Name__c = 'TestParent';
a.Type__c = 'Retail Outlet';
// a.Account_Record_ID__c = '0120W000001USkRQAW';
a.Current_Brand__c = 'Sunoco';
insert a;
Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,
BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,
Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,
Current_Brand__c
FROM Account where id = :a.id];
System.assert(a2!=null);
}
}
Thank You,
Eric
Test class need to call main class and execute method of class by passing record Id explicitly in order to cover code. here is some sample code
Hope it helps.
All Answers
Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,
BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,
Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,
Current_Brand__c
FROM Account where id = :a.id];
with the following code:
Account a2 = AccountStatus.getAccount(a.Id);
Your suggestion cleaned it up, but the code coverage for this class is still at 0%.
Eric
Test class need to call main class and execute method of class by passing record Id explicitly in order to cover code. here is some sample code
Hope it helps.