You need to sign in to do that
Don't have an account?
srinu namani 12
Help me in writing Test Class for this
public with sharing class AccountBeforeUpdateTriggerHandler extends TriggerHandlerBase{
//This method is called when trigger is called for the first time. Functionality defined in this function will be executed only once
public override void mainEntry(){
changeAccountOwnership();
if(!CONSTANTS.SICTRANSLATIONLOGIC_TRIGGERED)
CommonUtility.FS_SICTranslationToGeneralIndustries(Trigger.new);
}
//When trigger is i
public override void inProgressEntry(){
}
/*Approval process Final Approval and rejection actions*/
public void changeAccountOwnership(){
if(Trigger.new!=null && Trigger.new.size()==1){
Account oldAcc = (Account) Trigger.old[0];
Account newAcc = (Account) Trigger.new[0];
//Case of OwnershipChange : Approved
if (oldAcc.Change_Owner_Approval_Status__c == 'In Process' &&
oldAcc.Eligible_for_Owner_Change__c == true &&
newAcc.Change_Owner_Approval_Status__c == 'Approved'){
newAcc.OwnerId = oldAcc.Potential_Account_Owner__c;
newAcc.Eligible_for_Owner_Change__c = false;
newAcc.Potential_Account_Owner__c = null;
newAcc.Change_Owner_Approval_Status__c = null;
}
//Case : Rejected
else if(oldAcc.Change_Owner_Approval_Status__c == 'In Process' &&
oldAcc.Eligible_for_Owner_Change__c == true &&
newAcc.Change_Owner_Approval_Status__c == 'Rejected'){
newAcc.Eligible_for_Owner_Change__c = false;
newAcc.Potential_Account_Owner__c = null;
newAcc.Change_Owner_Approval_Status__c = null;
}
}
}
}
//This method is called when trigger is called for the first time. Functionality defined in this function will be executed only once
public override void mainEntry(){
changeAccountOwnership();
if(!CONSTANTS.SICTRANSLATIONLOGIC_TRIGGERED)
CommonUtility.FS_SICTranslationToGeneralIndustries(Trigger.new);
}
//When trigger is i
public override void inProgressEntry(){
}
/*Approval process Final Approval and rejection actions*/
public void changeAccountOwnership(){
if(Trigger.new!=null && Trigger.new.size()==1){
Account oldAcc = (Account) Trigger.old[0];
Account newAcc = (Account) Trigger.new[0];
//Case of OwnershipChange : Approved
if (oldAcc.Change_Owner_Approval_Status__c == 'In Process' &&
oldAcc.Eligible_for_Owner_Change__c == true &&
newAcc.Change_Owner_Approval_Status__c == 'Approved'){
newAcc.OwnerId = oldAcc.Potential_Account_Owner__c;
newAcc.Eligible_for_Owner_Change__c = false;
newAcc.Potential_Account_Owner__c = null;
newAcc.Change_Owner_Approval_Status__c = null;
}
//Case : Rejected
else if(oldAcc.Change_Owner_Approval_Status__c == 'In Process' &&
oldAcc.Eligible_for_Owner_Change__c == true &&
newAcc.Change_Owner_Approval_Status__c == 'Rejected'){
newAcc.Eligible_for_Owner_Change__c = false;
newAcc.Potential_Account_Owner__c = null;
newAcc.Change_Owner_Approval_Status__c = null;
}
}
}
}
Each test should follow the following structure:
- Setup of test data. This includes creation of any data needed by your class. Account, Contacts etc
- Starting the test. This is calling Test.startTest() to reset the governor limits
- Calling your class / method
- Stopping the test.This is calling Test.stopTest() to reset the governor limits and allow for any async jobs to finish
- Asserting that your changes have worked
- If you have inserted/updated/deleted data, you need to query for the updates
- Run System.assert, System.assertEquals, System.assertNotEquals to verify that you got the correct data back
If you have any specific problems with your tests, feel free to create a new post with the part of the class you are trying to test and your current test method, and you will more likely get a better response then asking for someone to essentially write an entire test class for you.[1] http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
[2] http://pcon.github.io/presentations/testing/
[3] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
[4] http://blog.deadlypenguin.com/blog/testing/strategies/