You need to sign in to do that
Don't have an account?
Sarah Robertson
Help test class for aura component
Hi guys
I'm wondering if someone can help me i'm quite a newbie developer
I've created a button which is updating a field on the account using a component and class. I'm having trouble gettting any coverage for my class can anyone tell me where i am going wrong ?
in my test class i'm getting an error on " updateBillingAddressPlan.UpdateBill(Acc);
" as it doesn't recognise Acc as a variable.
Here is my class
public class updateBillingAddressPlan {
@AuraEnabled
public static void UpdateBill(){
list<Account> Acc_list = new list<Account>();
Acc_list = [select id,Shipping_to_Billing__c from Account Limit 1];
Account acc =new Account();
acc.id=Acc_list[0].id;
acc.Shipping_to_Billing__c=true;
update acc;
}
}
Test class
@isTest
private class updateBillingAddressPlantest{
@AuraEnabled
public static boolean UpdateBill(){
//List<Account> Acc_list = new list<Account>();
// Acc_list = [select id,Shipping_to_Billing__c from Account Limit 1];
// system.debug(Acc_list.size());
Account acc =new Account();
// acc.id=Acc_list[0].id;
acc.name ='test account';
acc.Siret_Number__c='12345678911111';
acc.Shipping_to_Billing__c=true;
insert acc;
system.debug('inserting account was a success');
return acc.Shipping_to_Billing__c;
}
static testmethod void doTest(){
Test.startTest();
User U = new User();
U.FirstName = 'Testy';
U.LastName = 'Tester';
// U.CurrencyIsoCode = 'GBP';
U.Username = 'tester_User@test.com';
U.email = 'tester@test.com';
U.Alias = 'tstr';
U.TimeZoneSidKey = 'Europe/London';
U.LocaleSidKey ='en_GB';
U.EmailEncodingKey ='ISO-8859-1';
U.LanguageLocaleKey = 'en_US';
U.profileID = '00e1t000000FMFdAAO';
// U.Annual_Target_New_TCVP__c = 100000;
// U.Booked_YTD_New_TCVP__c = 50000;
Insert U;
System.runAs(U){
Account Acc = new Account();
// Acc.recordTypeID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('UK Account').getRecordTypeId();
Acc.Name = 'Account Testing';
Acc.Siret_Number__c='12345678923456';
// Acc.cf_customer_sector__c = 'Public';
// Acc.cf_customer_segment__c = 'SMB';
Acc.cf_customer_vertical__c = 'Finance';
insert Acc;
Opportunity opp = new Opportunity();
opp.name = 'Test Opportunity';
// opp.Start_Date__c = system.today();
opp.closeDate = system.today().addDays(1);
opp.stageName = 'Stage 2: Prospect';
insert opp;}
updateBillingAddressPlan.UpdateBill(Acc);
Test.stopTest();
}}
I'm wondering if someone can help me i'm quite a newbie developer
I've created a button which is updating a field on the account using a component and class. I'm having trouble gettting any coverage for my class can anyone tell me where i am going wrong ?
in my test class i'm getting an error on " updateBillingAddressPlan.UpdateBill(Acc);
" as it doesn't recognise Acc as a variable.
Here is my class
public class updateBillingAddressPlan {
@AuraEnabled
public static void UpdateBill(){
list<Account> Acc_list = new list<Account>();
Acc_list = [select id,Shipping_to_Billing__c from Account Limit 1];
Account acc =new Account();
acc.id=Acc_list[0].id;
acc.Shipping_to_Billing__c=true;
update acc;
}
}
Test class
@isTest
private class updateBillingAddressPlantest{
@AuraEnabled
public static boolean UpdateBill(){
//List<Account> Acc_list = new list<Account>();
// Acc_list = [select id,Shipping_to_Billing__c from Account Limit 1];
// system.debug(Acc_list.size());
Account acc =new Account();
// acc.id=Acc_list[0].id;
acc.name ='test account';
acc.Siret_Number__c='12345678911111';
acc.Shipping_to_Billing__c=true;
insert acc;
system.debug('inserting account was a success');
return acc.Shipping_to_Billing__c;
}
static testmethod void doTest(){
Test.startTest();
User U = new User();
U.FirstName = 'Testy';
U.LastName = 'Tester';
// U.CurrencyIsoCode = 'GBP';
U.Username = 'tester_User@test.com';
U.email = 'tester@test.com';
U.Alias = 'tstr';
U.TimeZoneSidKey = 'Europe/London';
U.LocaleSidKey ='en_GB';
U.EmailEncodingKey ='ISO-8859-1';
U.LanguageLocaleKey = 'en_US';
U.profileID = '00e1t000000FMFdAAO';
// U.Annual_Target_New_TCVP__c = 100000;
// U.Booked_YTD_New_TCVP__c = 50000;
Insert U;
System.runAs(U){
Account Acc = new Account();
// Acc.recordTypeID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('UK Account').getRecordTypeId();
Acc.Name = 'Account Testing';
Acc.Siret_Number__c='12345678923456';
// Acc.cf_customer_sector__c = 'Public';
// Acc.cf_customer_segment__c = 'SMB';
Acc.cf_customer_vertical__c = 'Finance';
insert Acc;
Opportunity opp = new Opportunity();
opp.name = 'Test Opportunity';
// opp.Start_Date__c = system.today();
opp.closeDate = system.today().addDays(1);
opp.stageName = 'Stage 2: Prospect';
insert opp;}
updateBillingAddressPlan.UpdateBill(Acc);
Test.stopTest();
}}
Greetings to you!
Please try the below code, it will give you 100% code coverage for above-mentioned class.
You are getting this error because you are passing a parameter to the method in test class but in the business class, there is no parameter for UpdateBill method.
Please refer to the below links which might help you further.
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please try the below code, it will give you 100% code coverage for above-mentioned class.
You are getting this error because you are passing a parameter to the method in test class but in the business class, there is no parameter for UpdateBill method.
Please refer to the below links which might help you further.
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Try this test class: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi