You need to sign in to do that
Don't have an account?
Jeff Bomar
Code coverage on a Apex trigger
Any Help would be much apricated I created an Apex Trigger and am having trouble writing the test class for code coverage really green when it comes to this
Triger
trigger updateCustomDev on Custom_Programming__c (before Insert) {
for (Custom_Programming__c Custom : trigger.new) {
//SQL statement to lookup price
List<PricebookEntry> sqlResult = [SELECT UnitPrice
FROM PricebookEntry
WHERE Product2.Name = 'Custom Development'
AND PriceBook2.Name='DAKCS'];
//save the returned SQL result inside the field
Custom.Hourly_Cost__c = sqlResult[0].UnitPrice;
}
}
Test Class
@IsTest
public class TestupdateCustomDev {
@IsTest static void testHourlyCost(){
//Create Custom
Custom_Programming__c c = new Custom_Programming__c(Name='Test',Custom_State__c='Active',Custom_Type__c='Custom',Status__c='New');
Test.startTest();
Database.SaveResult result = Database.insert (c, true);
System.assert(result.isSuccess());
Test.stopTest();
}
}
I was hoping this would be really simple all I want the trigger to do is update a field with an entry from pice book entry.
Thanks again
Triger
trigger updateCustomDev on Custom_Programming__c (before Insert) {
for (Custom_Programming__c Custom : trigger.new) {
//SQL statement to lookup price
List<PricebookEntry> sqlResult = [SELECT UnitPrice
FROM PricebookEntry
WHERE Product2.Name = 'Custom Development'
AND PriceBook2.Name='DAKCS'];
//save the returned SQL result inside the field
Custom.Hourly_Cost__c = sqlResult[0].UnitPrice;
}
}
Test Class
@IsTest
public class TestupdateCustomDev {
@IsTest static void testHourlyCost(){
//Create Custom
Custom_Programming__c c = new Custom_Programming__c(Name='Test',Custom_State__c='Active',Custom_Type__c='Custom',Status__c='New');
Test.startTest();
Database.SaveResult result = Database.insert (c, true);
System.assert(result.isSuccess());
Test.stopTest();
}
}
I was hoping this would be really simple all I want the trigger to do is update a field with an entry from pice book entry.
Thanks again
It's not very beautiful but it should cover 100%:
Let me know if you get any errors and I'll try to help you sort it out :)
All Answers
It's not very beautiful but it should cover 100%:
Let me know if you get any errors and I'll try to help you sort it out :)