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
nextdoornextdoor 

Test Method {get; set}

Hi,

 

I am new in salesforce and I'm working on my first test code.

Can I have a test method example for some code below:

public class Myclass
{

public List< Something__c> Something { get; set; } 
   
    public Myclass() {   
 

    Something=[SELECT Name, Something__r.Name FROM Somethings__c WHERE Somethings__r.ID = :ApexPages.currentPage().getParameters().get('id')  ]; 

                      }
}

 

 

Any help would be greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
SamuelDeRyckeSamuelDeRycke

Have you looked at any resources at all ? I can recommend the apex documentation and and introductcion to apex code test methods.

 

public with sharing class MyClass 
{
    public List<something__c> Something { get; set; } 
   
    public Myclass(){   
    	Something=[SELECT Name, Something__r.Name FROM Somethings__c WHERE Somethings__r.ID = :ApexPages.currentPage().getParameters().get('id')  ]; 
    }
    
    //-------------------------  tests --------------------------
    @IsTest
    static void testMyClass(){
    	ApexPages.currentPage().getParameters().put('id','blablabla');
    	Myclass obj = new Myclass();
    }                          
                      
}

 

 

 

All Answers

SamuelDeRyckeSamuelDeRycke

Have you looked at any resources at all ? I can recommend the apex documentation and and introductcion to apex code test methods.

 

public with sharing class MyClass 
{
    public List<something__c> Something { get; set; } 
   
    public Myclass(){   
    	Something=[SELECT Name, Something__r.Name FROM Somethings__c WHERE Somethings__r.ID = :ApexPages.currentPage().getParameters().get('id')  ]; 
    }
    
    //-------------------------  tests --------------------------
    @IsTest
    static void testMyClass(){
    	ApexPages.currentPage().getParameters().put('id','blablabla');
    	Myclass obj = new Myclass();
    }                          
                      
}

 

 

 

This was selected as the best answer
nextdoornextdoor

Thank you !