You need to sign in to do that
Don't have an account?
IR_Admin IR_Salesforce
I need to write a test class for apex class to update all Opportunities
I think I have an Apex Class that will update all Opportunities at night so that the workflows will run on them on a nightly basis.
public class updateOpportunity {
public static void checkUpdate(Opportunity[] objects){
for(Opportunity obj: objects){
}
}
}
I need to write a test class so that I can move this over into production. Can someone please help me?
public class updateOpportunity {
public static void checkUpdate(Opportunity[] objects){
for(Opportunity obj: objects){
}
}
}
I need to write a test class so that I can move this over into production. Can someone please help me?
All Answers
I've got it done to this:
@isTest
public class TestupdateOpportunity {
static testMethod void insertNewOpportunity() {
Opportunity testOpportunity = new Opportunity(
Name = 'Test Opportunity Triggers',
StageName = 'Sourcing Demand'
);
insert testOpportunity;
Test.startTest();
Opportunity[] objects = new Opportunity[] {
objects.add(testOpportunity) };
updateOpportunity.checkUpdate( objects);
Test.stopTest();
}
}
But am now getting this error :
Error: Compile Error: Variable does not exist: objects at line 11 column 9
I tried to do the same for updating the Opportunity line item but seem to be having some trouble.
Apex Class:
public class UpdateOpportunityLineItem {
public static void checkUpdate(OpportunityLineItem[] objects){
for(OpportunityLineItem obj: objects){
}
}
}
@isTest
public class TestupdateOpportunityLineItem {
static testMethod void insertNewOpportunityLineItem() {
OpportunityLineItem testOpportunityLineItem = new OpportunityLineItem(
Type__c = 'New',
Position_Status__c = 'Recruiting to Confirm',
OpportunityId = opp.Id,
Start_Date__c = Date.newInstance(2016, 12, 9),
Disciplines__c = 'JavaScript Engineering'
);
insert testOpportunityLineItem;
Test.startTest();
OpportunityLineItem[] objects = new OpportunityLineItem[] {testOpportunityLineItem };
updateOpportunityLineItem.checkUpdate(objects);
Test.stopTest();
}
}
I'm unsure what to enter for OpportunityId = opp.Id?