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
ThedudeThedude 

New Developer looking for help in test cases.

I am new to the apex coding. How would i be able to creat a test case for this code.

global static Map<ID, Prospect__c> GetBulkFullProspect(List<ID> prospectIDs)
{
// Ask the database for ALL the prospect fields.
string queryString = URLUtilities.GetFullBaseQuery('i360__Prospect__c');
queryString += ' WHERE ID IN :ProspectIDs ';

List<Prospect__c> FullProspects = (List<Prospect__c>)(database.query(queryString));
Map<Id,Prospect__c> retMap = new Map<ID,Prospect__c>();
for(Prospect__c prospect : FullProspects)
retMap.put(prospect.id,prospect);
return retMap;

Best Answer chosen by Admin (Salesforce Developers) 
Ben DunlapBen Dunlap

GetBulkFullProspect returns a Map and takes a List as its single argument. So this line won't compile, because it's assuming a return value of type Prospect__c and an argument of type 'Id':

 

Prospect__c NewProsp2= ProspectUtilities.GetBulkFullProspect(OldProsp2.ID);

 You probably need something more like this:

 

Map<ID, Prospect__c> bulkResults = ProspectUtilities.GetBulkFullProspect(new List<Prospect__c>{OldProsp2.Id});
TestUtilities.AssertProspect(oldProsp2, bulkResults.get(oldProsp2.Id));


All Answers

sfcksfck

A test case is there to check that the code is doing what it is supposed to do.

 

Can you explain what the code you have written is supposed to do? If you ran it, what would it mean to say that it had worked or that it had not worked?

ThedudeThedude

there is a similar test case that goes as follows:

global static Prospect__c GetFullProspect(ID proID)
{
string BasicQuery = URLUtilities.GetFullBaseQuery('i360__Prospect__c') + ' WHERE ID = :proID ';
List<Prospect__c> FullProspect = (List<Prospect__c>)(database.query(BasicQuery));
if(FullProspect.size() == 0)
return null;
else
return FullProspect[0];

 

and the test case to follow this is:

static testMethod void testGetFullProspect()
{
Prospect__c OldProsp = TestUtilities.CreateProspect(true);
Prospect__c NewProsp = ProspectUtilities.GetFullProspect(OldProsp.ID);
TestUtilities.AssertProspect(OldProsp, NewProsp);
}.

 

For what i originally wrote, the test case that I wrote is:

static testMethod void testGetBulkFullProspect()
{
Prospect__c OldProsp2= testUtilities.CreateProspect (true);
Prospect__c NewProsp2= ProspectUtilities.GetBulkFullProspect(OldProsp2.ID);
TestUtilities.AssertProspect(OldProsp2, NewProsp2);
}.

 

hope the helps you help me

 

Ben DunlapBen Dunlap

GetBulkFullProspect returns a Map and takes a List as its single argument. So this line won't compile, because it's assuming a return value of type Prospect__c and an argument of type 'Id':

 

Prospect__c NewProsp2= ProspectUtilities.GetBulkFullProspect(OldProsp2.ID);

 You probably need something more like this:

 

Map<ID, Prospect__c> bulkResults = ProspectUtilities.GetBulkFullProspect(new List<Prospect__c>{OldProsp2.Id});
TestUtilities.AssertProspect(oldProsp2, bulkResults.get(oldProsp2.Id));


This was selected as the best answer