You need to sign in to do that
Don't have an account?
Saurabh Bisht 19
can we make bulk test Apex class for this
@isTest
public class StateNameTest{
@testSetup static void setup()
{
StateName__c newStates=new StateName__c();
newStates.Name='Goa';
insert newStates;
}
@isTest
static void checkStatenamesTest()
{
StateName__c testStates=[Select Id from StateName__c where State__c='Goa'];
Opportunity newOpportunity=new Opportunity();
newOpportunity.Name='Saurabh Bisht';
newOpportunity.CloseDate=System.today().addMonths(1);
newOpportunity.StageName='Qualification';
newOpportunity.State__c='Goa';
insert newOpportunity;
Opportunity testOpportunity=[Select Id,StateName__c from Opportunity where id=:newOpportunity.Id];
system.assertequals(testStates.Id,testOpportunity.StateName__c);
}
public class StateNameTest{
@testSetup static void setup()
{
StateName__c newStates=new StateName__c();
newStates.Name='Goa';
insert newStates;
}
@isTest
static void checkStatenamesTest()
{
StateName__c testStates=[Select Id from StateName__c where State__c='Goa'];
Opportunity newOpportunity=new Opportunity();
newOpportunity.Name='Saurabh Bisht';
newOpportunity.CloseDate=System.today().addMonths(1);
newOpportunity.StageName='Qualification';
newOpportunity.State__c='Goa';
insert newOpportunity;
Opportunity testOpportunity=[Select Id,StateName__c from Opportunity where id=:newOpportunity.Id];
system.assertequals(testStates.Id,testOpportunity.StateName__c);
}
What is the issue, you were facing?
Thanks!!
if you watch it i create a single record odf statename as Goa and
one opportunity in second metyhod so iwant this class should run with
bulk records bulk records od statename custom obj and opportunity bulk records.
can you make same test class for bulk
public class StateNameHelper{
public static Map<String,Id> getRecords(List<Opportunity> listOfOpportunities)
{
Set<String> setOfStates=new Set<String>();
for(Opportunity op:listOfOpportunities)
{
if(op.State__c!=null)
{
setOfStates.add(op.State__c);
}
}
Map<String,Id> mapOfStates=new Map<String,Id>();
List<StateName__c> stateNameList=[Select Id,Name from StateName__c where Name=:setOfStates];
for(StateName__c st:stateNameList)
{
mapOfStates.put(st.Name,st.Id);
}
return mapOfStates;
}
public static void checkStatenames(Map<String,Id> statesMaps,Opportunity ops)
{
if(statesMaps.containsKey(ops.State__c) && ops.State__c!=null)
{
ops.StateName__c=statesMaps.get(ops.State__c);
}
else if(!statesMaps.containsKey(ops.State__c) && ops.State__c!=null)
{
ops.addError('wE need to create account');
}
}
}
try with below code.
If this helps, Please mark it as best answer.
Thanks!!