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
GaneeeshGaneeesh 

Can any one help me how to write test class for this class?


  id myProductId; 
  Public Document_Reference_Junction__c DocuRefIP { Get; Set; }
Hi

while running test classs , test method has failed it shows List has no rows for assignment to SObject. any one help me how to avoid this error. and this is my class.

public class sample{
public sample(){
  DocuRefIP = New Document_Reference_Junction__c();
  myProductId=ApexPages.CurrentPage().getParameters().get('Id');
  DocuRefIP.Installed_Product__c=[select id from SVMXC__Installed_Product__c where id=:myProductId limit 1].id;
  }  
}
SunidharSunidhar
First you need to insert SVMXC__Installed_Product__c object  test record and then u need to pass that id, your test class will be like this:

@isTest
public Class CSARevisePageForQuotePrpsalControlerTest {        
    public static testMethod void samTest() {
        SVMXC__Installed_Product__c ip = new SVMXC__Installed_Product__c();
        // enter the mandatory fields to insert sample test record
        ip.name = 'test record';
        insert ip;
         Apexpages.currentpage().getparameters().put('id',ip.id);
         ApexPages.StandardController con = new ApexPages.StandardController(ip);
         sample sam = new sample(con);
    }
}
SunidharSunidhar
sry about that, can you try with this

@isTest
public Class CSARevisePageForQuotePrpsalControlerTest {        
    public static testMethod void samTest() {
        SVMXC__Installed_Product__c ip = new SVMXC__Installed_Product__c();
        // enter the mandatory fields to insert sample test record
        ip.name = 'test record';
        insert ip;
         sample sam = new sample();
         sam.myProductId = ip.id;
    }
}

And one more thing is, why is the need of querying the Id when u are having the Id ??