You need to sign in to do that
Don't have an account?
JP Nikko AM Systems
Apex Trigger Deployment Fails (Test Coverage 0%)
We created an Apex Trigger on our Sandbox (a before insert, before update trigger on Contact which just basically updates some custom field). Tested it with an Apex class and Code Coverage is 100% (12/12).
But when we deploy it to Production validation fails.
Below is our Apex Class to test.
@isTest
public class TriggerTest {
static testMethod void verifyTrigger (){
User u1 = [SELECT Id FROM User WHERE Alias='alias'];
System.RunAs(u1)
{
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId());
List<Contact> contacts = new List<Contact>{};
for(Integer i = 0; i < 1000; i++) {
Contact a = new Contact(LastName = 'Test'+i, AccountId = 'xxxxxxxxxxxxxxx',Owner=u1 );
contacts.add(a);
}
test.startTest();
insert contacts;
test.stopTest();
}
}
}
Any ideas why? I have tried Compiling all classes. And even Run all from Developer Console but no luck.
But when we deploy it to Production validation fails.
Below is our Apex Class to test.
@isTest
public class TriggerTest {
static testMethod void verifyTrigger (){
User u1 = [SELECT Id FROM User WHERE Alias='alias'];
System.RunAs(u1)
{
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId());
List<Contact> contacts = new List<Contact>{};
for(Integer i = 0; i < 1000; i++) {
Contact a = new Contact(LastName = 'Test'+i, AccountId = 'xxxxxxxxxxxxxxx',Owner=u1 );
contacts.add(a);
}
test.startTest();
insert contacts;
test.stopTest();
}
}
}
Any ideas why? I have tried Compiling all classes. And even Run all from Developer Console but no luck.
All Answers
1) Do you have user where Alias='alias' in your prod org
2) do you have AccountId = 'xxxxxxxxxxxxxxx' in your prod org
3) check in the debug logs for any validation errors that might be preventing the insert operation in turn preventing your Trigger code.