function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
System Admin 949System Admin 949 

Testclass for Apex

Hi Community,
i am facing some problem for writing the test class for below apex class,can any provide sample code for this to write the test class
apex class
public class ProductNoteListController {
  public static List<CustomerProduct__c> getProductNotes(Id meetingRecId) {
    List<CustomerProduct__c> pdtNoteList =  [SELECT Id, Product__r.Id,Product__r.Name, MeetingNotes__c,MeetingId__c,RecordType.DeveloperName
            FROM CustomerProduct__c  
            WHERE MeetingId__c =: meetingRecId
            ORDER BY createdDate DESC];
      for(CustomerProduct__c cpRec : pdtNoteList){
              cpRec.MeetingNotes__c = cpRec.MeetingNotes__c.replaceAll('<[^>]+>',' ');
      return pdtNoteList;
    public static void updateCustProdRT(Id recordId)
            List<RecordType> rtypes = [Select Id From RecordType where Name='Customer Product' AND SobjectType = 'CustomerProduct__c'];
            CustomerProduct__c CP = [select id from CustomerProduct__c  WHERE Id=:recordId];
            update CP;
        catch(DmlException ex)
            throw new AuraHandledException(ex.getMessage());
thanks in advance
hi try something like this :
private class testClassSample {
  static testMethod void testMethodOne() {
      CustomerProduct__c obj = new CustomerProduct__c();
	    obj.MeetingNotes__c = 'test';
		obj.MeetingId__c = '123456789123456789';
		// *********add all requred fields here before insert record *******
		insert obj;

Thank, let us know if it helps you 
Raj VakatiRaj Vakati
try this
Private Class CustomerProductListControllerTest

	static Testmethod void CampaignMemberEx()

		 Pricebook2 pb22 = new Pricebook2(Name='Addressable');
 insert pb22;

Product2 pro2 = new Product2(Product_Line__c='DIE',Name='Addressable',Product_Code_Item_Number__c='BXCD24', isActive=true);
insert pro2;

		  List<RecordType> rtypes = [Select Id From RecordType where Name='Customer Product' AND SobjectType = 'CustomerProduct__c'];
		  Meeting__c mo = new Meeting__c() ;
		  mo.Name ='Test';
		  mo.MeetingNotes__c ='Test';
		  insert mo ;
		  CustomerProduct__c co = new CustomerProduct__c() ;
		  co.Name ='Test'; 
		  co.MeetingId__c = mo.Id ;
		  // Add other filew 
		  co.Product__c = ; 
		  co.RecordTypeId =: rtypes.get(0).Id ; 
		  // add other fields 
		  insert co ;