You need to sign in to do that
Don't have an account?
Nathan Prats 22
Test Class for a Schedulable Apex Class
Hi !
I created a Schedulable Apex Class to reassign opportunities to the account owner every morning at 6 AM.
I started to code this Test Class but I'm stuck. I have no idea what to do from here.
Any help would be more than welcome.
Nathan
I created a Schedulable Apex Class to reassign opportunities to the account owner every morning at 6 AM.
global class ReassignOpps implements Schedulable { global void execute(SchedulableContext ctx) { List<Opportunity> OppList = [SELECT Id,OwnerId,Account.OwnerId FROM Opportunity WHERE Opportunity_Owner_Account_Owner__c = TRUE AND IsClosed = FALSE AND IsExcludedFromTerritory2Filter = FALSE]; for(Opportunity Opp : OppList){ Opp.OwnerId = Opp.Account.OwnerId ; } update OppList; } }I'm fairly new to Apex, but I think I need to create a Test Class for this Class.
I started to code this Test Class but I'm stuck. I have no idea what to do from here.
@isTest private class ReassignOppsTest { //Create 2 users User u1 = TestUtils.CreateAdminUser('user1'); User u2 = TestUtils.CreateAdminUser('user2'); //Create an account owned by X and an opportunity owned by Y Account acct = TestUtils.CreateAccount('name'); Account pacct = TestUtils.CreatePartnerAccount('Partner name'+' partner'); Contact con = TestUtils.CreateContact('firstName','lastName',acct); Opportunity opp = TestUtils.CreateOpportunity(acct, pacct, con,'CA'); acct.OwnerId = u1.Id; opp.OwnerID = u2.Id; //Call ReassignOpp Class??? // test }I know that I need to create 2 users, 1 Account and 1 Opportunity, then launch the class somehow and then see if the opportunity has been reassign correctly.
Any help would be more than welcome.
Nathan
Please check once following sample code.
Hope this helps you.
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com