You need to sign in to do that
Don't have an account?
MAITREYEE DINGARE 3
Test Class for Update List APEX Class
Hi,
I have an APEX Class that is updating a list and later I am presenting that list via LWC on the Lightning Record Page.
I would like to write a test Class for the APEX Class.
APEX Class:
I have an APEX Class that is updating a list and later I am presenting that list via LWC on the Lightning Record Page.
I would like to write a test Class for the APEX Class.
APEX Class:
public class PriceBookEntriesFromAccount { @AuraEnabled public static List<BB_Produkt__c> getPriceBookEntries(String artId) { List<BB_Produkt__c> bb = [SELECT Name, Id, Berichsartikel__c, Berichsartikel_Copy__c, Produkt__r.Name, Verkostung__c, Kaufinteresse__c, Unternehmen__r.Name, CreatedDate FROM BB_Produkt__c WHERE Unternehmen__r.Id = :[SELECT Unternehmen__r.Name FROM Besuchsbericht__c WHERE Id =:artId].Unternehmen__r.Id ORDER BY CreatedDate DESC]; //Add isAccessible() check return bb; } @AuraEnabled public static void updateRelatedList(List<BB_Produkt__c> Bblist) { if(Bblist!= null && Bblist.size()>0) { update Bblist; Bblist.sort(); } } }So far this is what I have written, but I am getting 0% code coverage:
@isTest(SeeAllData=true) public class testPriceBookEntriesFromAccount { public static testMethod void testBB_Produkt() { Account createAccount =new Account(Name='TestA'); insert createAccount; Product2 createProduct2 =new Product2(Name='TestP'); insert createProduct2; BB_Produkt__c createBB_Produkt =new BB_Produkt__c(Produkt__c=createProduct2.ID, Unternehmen__c=createAccount.Id); insert createBB_Produkt; createBB_Produkt.Feedback_Verkostung_1_5__c = 2; update createBB_Produkt; } }
Your test class needs to be like below:
Please don't use the (SeeAllData=true) in test class
Thanks,
Maharajan.C
All Answers
Your test class needs to be like below:
Please don't use the (SeeAllData=true) in test class
Thanks,
Maharajan.C
Thank you for your reply. It worked! Coverage 100%
Thanks a lot.