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
NakataNakata 

How can i do a test method for my code ?

Good day, 

 

I always have problem to create test method :(

 

May i know how can we do the test method for below method 

 

 

public static void myMethod(List<String> tempCampaignIDList){
	if(tempCampaignIDList.size()>0){
		List<Campaign> campaignList = [SELECT Id, Type FROM Campaign WHERE id IN :tempCampaignIDList];
	for(Campaign cp : campaignList){
		if(!CampaignVehicleLookupMap.containsKey(cp.id)){
			CampaignVehicleLookupMap.put(cp.id, cp.type);
					}
				}
			}
}

Thanks in advance !

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Anup JadhavAnup Jadhav

Hi Nakata,

 

If you are new to Force.com  platform, I'd recommend reading this introduction to Test Methods article:

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

In this instance, I'd suggest the following steps:

 

1. Create test data - create and insert some test campaigns and add their ids to a list

2. Test the method - call the 'myMethod' with the list created above

3. Check the value in the 'CampaignVehicleLookupMap' using either System.Assert or System.AssertEquals method.

 

Regards,

A J

All Answers

Anup JadhavAnup Jadhav

Hi Nakata,

 

If you are new to Force.com  platform, I'd recommend reading this introduction to Test Methods article:

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

In this instance, I'd suggest the following steps:

 

1. Create test data - create and insert some test campaigns and add their ids to a list

2. Test the method - call the 'myMethod' with the list created above

3. Check the value in the 'CampaignVehicleLookupMap' using either System.Assert or System.AssertEquals method.

 

Regards,

A J

This was selected as the best answer
NK123NK123

How come the test methods consumes Autonumbers from an autonumber column? Why is this not fixed by salesforce?

~NK