You need to sign in to do that
Don't have an account?
Callum Whitehouse
Help needed in creating simple test class
I've tried to complete the Trailhead for Apex test classes however I've not been able to apply the knowledge to our specific scenario. For our Salesforce Community, external users will have access to some or all of our marketing toolkits. This access is dependent on whether they have a certain field checked as true in their profile (e.g. BiRetix_Toolkit__c).
Apex class to test:
public class FileRepositoryController {
@AuraEnabled
public static List<Contact> getItems() {
List<Contact> TK = [SELECT BiRetix_Toolkit__c, AesthetiCare_Cleansers_Toolkit__c,
EDS_Toolkit__c, Endocare_CELLPRO_Toolkit__c, Endocare_Concentrates_Toolkit__c,
Endocare_Growth_Factor_Facials__c, Endocare_Tensage_Toolkit__c, Endocare_C_Ferulic_Toolkit__c,
ENDYMED_Toolkit__c, G_T_Peels_Toolkit__c, Heliocare_360_Toolkit__c, NeoRettin_Toolkit__c,
NeoRetin_Rejuvemax_Toolkit__c, Retriderm_Toolkit__c FROM Contact WHERE AccountId IN
(SELECT AccountId FROM User WHERE username=:UserInfo.getUsername())];
return TK;
}
}
Would someone be able to assist in helping me write a correct test class please?
Apex class to test:
public class FileRepositoryController {
@AuraEnabled
public static List<Contact> getItems() {
List<Contact> TK = [SELECT BiRetix_Toolkit__c, AesthetiCare_Cleansers_Toolkit__c,
EDS_Toolkit__c, Endocare_CELLPRO_Toolkit__c, Endocare_Concentrates_Toolkit__c,
Endocare_Growth_Factor_Facials__c, Endocare_Tensage_Toolkit__c, Endocare_C_Ferulic_Toolkit__c,
ENDYMED_Toolkit__c, G_T_Peels_Toolkit__c, Heliocare_360_Toolkit__c, NeoRettin_Toolkit__c,
NeoRetin_Rejuvemax_Toolkit__c, Retriderm_Toolkit__c FROM Contact WHERE AccountId IN
(SELECT AccountId FROM User WHERE username=:UserInfo.getUsername())];
return TK;
}
}
Would someone be able to assist in helping me write a correct test class please?
Thanks
All Answers
Please Try Below Code. Please let me know if you are getting any issue.
Thanks
Hemant
I've tried the following code however the code coverage is 0%, 0/4 lines.
Any corrections would be much appreciated, thanks.
Field is not writeable: User.AccountId
Thanks
Hemant
Thanks
Please mark this solved As well.
Thanks