Skip to content

Instantly share code, notes, and snippets.

@sakthivelsfdc
Created September 25, 2019 01:12
Show Gist options
  • Save sakthivelsfdc/5981ca172d1b74af53029a3c6493a1e4 to your computer and use it in GitHub Desktop.
Save sakthivelsfdc/5981ca172d1b74af53029a3c6493a1e4 to your computer and use it in GitHub Desktop.
/**
*
* This Apex Test Class Created to cover the Opportunity Trigger
* - Created Test User with non system admin profile
* - Used Syste.runAs to execute the test user
* - Created Opportunity Record
* - Deleted Opporutnity
* - Check AddError validation as per the Trigger
*
* @author Sakthivel Madesh
* @date Sep 25, 2019
*/
@isTest
public class OpportunityDeleteTriggerTestClass {
static testMethod void createOppMethod() {
try {
Test.startTest();
Profile prof = [SELECT Id FROM Profile WHERE Name = 'Standard User']; //get a profile Id
User testUser = new User(Alias = 'TDemo', Email = 'sakthi@theblogreaders.com', EmailEncodingKey = 'ISO-8859-1', FirstName = 'Demo', LanguageLocaleKey = 'en_US', LastName = 'User', LocaleSidKey = 'en_US', ProfileId = prof.Id, TimeZoneSidKey = 'America/Denver', Username = 'demo.sakthi@theblogreaders.com');
insert testUser;
System.runAs(testUser) {
Opportunity createOpp = new Opportunity();
createOpp.Name='test opp';
createOpp.StageName='Closed Won';
createOpp.Probability = 95;
createOpp.CloseDate=system.today();
insert createOpp;
Delete createOpp;
//Apex Trigger addError Checking
Opportunity testResult = [SELECT Id, IsClosed FROM Opportunity WHERE Id =: createOpp.Id];
system.debug('testResult.IsClosed:::'+testResult.IsClosed);
system.assertEquals(true, testResult.IsClosed);
}
Test.stopTest();
} catch(Exception e) {
system.debug('error::'+e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment