You need to sign in to do that
Don't have an account?
Test class in Lightning
Hi,
iam tried to create the test class for this below apex class but facing some issue,can any one provide some code how to write the test class for this .
apex class:
public class CustomerProductListController
{
@AuraEnabled
public static List<CustomerProduct__c> getProductNotes(Id meetingRecId)
{
List<RecordType> rtypes = [Select Id From RecordType where Name='Customer Product' AND SobjectType = 'CustomerProduct__c'];
List<CustomerProduct__c> pdtNoteList = [SELECT Id, Product__r.Id,Product__r.Name, MeetingNotes__c,MeetingId__c
FROM CustomerProduct__c
WHERE MeetingId__c =: meetingRecId AND RecordTypeId =: rtypes.get(0).Id
ORDER BY createdDate DESC];
for(CustomerProduct__c cpRec : pdtNoteList)
{
if(cpRec.MeetingNotes__c!=Null)
{
cpRec.MeetingNotes__c = cpRec.MeetingNotes__c.replaceAll('<[^>]+>',' ');
}
}
System.debug('**********'+pdtNoteList);
return pdtNoteList;
}
}
thanks.
Add all required fields on object
apex class is
@isTest(seeAllData=true)
private class CustomerProductListController_TC {
@isTest static void myTest()
{
try
{
Test.startTest();
Account acc = new Account(Name='Test Account');
insert acc;
Pricebook2 pb22 = new Pricebook2(Name='Standard Price Book',IsActive=true);
insert pb22;
Product2 pro2 = new Product2(Name='Test Product',ProductCode='BXCD24', isActive=true);
insert pro2;
List<RecordType> rtypes = [Select Id From RecordType where Name='Customer Product' AND SobjectType = 'CustomerProduct__c'];
Event e = new Event() ;
e.Subject ='Meeting';
e.DurationInMinutes=60;
e.ActivityDateTime=system.today();
//e.StartDateTime=system.today();
//e.EndDateTime=system.today()+5;
insert e ;
CustomerProduct__c co = new CustomerProduct__c() ;
co.Account__c = acc.Id;
co.MeetingId__c = e.Id ;
co.Product__c = pro2.id ;
co.RecordTypeId =rtypes.get(0).Id ;
insert co ;
CustomerProductListController.getProductNotes(e.Id);
Test.StopTest();
}
catch(DMLException ex)
{
system.assertEquals(ex.getMessage(), ex.getMessage());
}
}
}