You need to sign in to do that
Don't have an account?
cambart14
Apex Text Class
We have the below APEX trigger written in our sandbox, but need to deploy it into production. The issue is we don't have any code coverage, and I am new to APEX programming.
Any help on creating a text class to cover 75% of this code would be much appreciated.
trigger ownerCopy on Account (before Insert, before Update) { // handle arbitrary number of opps for(Account x : Trigger.New){ // check that owner is a user (not a queue) if( ((String)x.OwnerId).substring(0,3) == '005' ){ x.Owner_Copy__c = x.OwnerId; } else{ // in case of Queue we clear out our copy field x.Owner_Copy__c = null; } } }
Thanks again for your time and input!
Kiran, thanks for your comments on queue ownership, I was able to update the trigger for that.
I was able to get this test class below to cover 75% of my trigger.
All Answers
try this.... but here u need to understand some points
1. we can't create queues for account object so there is no chance of assiging a queue to account record and also there will be no case where a record in salesforce is not having any owner. SO i dont think else part required there in the code . Any ways if no value assigned to any of the fields in the salesforce it will default to null only.
@isTest
private class TestUtil {
static void createTestAccounts() {
Account objAccount = new Account();
ObjAccount.Name = 'test account';
objAccount.ownerid = userinfo.getuserid();
//Assign all the values which are required
Test.starttest();
insert objAccount;
Test.stoptest();
}
}
Kiran, thanks for your comments on queue ownership, I was able to update the trigger for that.
I was able to get this test class below to cover 75% of my trigger.