You need to sign in to do that
Don't have an account?

Trigger Deployment Errors
I am new to this org I am currently working in. I am deploying my first trigger as an admin. I received the attached 2 errors. Any ideas on how I can troubleshoot these:

You apex Test class are failing in while you are deploying .
Class 1: - Test_UpdateContactRoleCount - System Asserting is work
Class 2 :- TestClass - You are query is not returning any data. So insert data first and Query them in the test method.
Either way what is needed to move past the errors? Here is the actual trigger I am deploying:
Here are three screen shots for the second one (TestClass). The second one was written by a previous employee who had developer experience.
If there is a better way for me to get this code to you please let me know.
The assert is failing because the code is throwing an error. Do you have any validation rules or required fields that would make an insert of opporutunities or contacts fail?
Create an opportunity with the name = 'test', a close date more than 60 days in the past, Sales Stage High Level = 'Open' and add at least 1 product. That should allow that test class to work correctly and pass.
Here are the 2 errors:
Or, you can open the cls file in a text editor and grab the code from there.
@isTest(SeeAllData=true)
private class TestClass {
static testMethod void myUnitTest() {
Profile p = [Select id from Profile where Name ='System Administrator'];
Profile EUP = [Select id from Profile where Name ='EU - Standard User w/ Reporting'];
user u = [select id, ProfileId, UserRoleId,Name, Team__c, Territory__c, Region__c from User where /*Name =: 'Gavin Barber']; //*/ProfileId =: EUP.Id and isActive = true limit 1]; //
user u2 = [select id, ProfileId, UserRoleId,Name, Team__c, Territory__c, Region__c from User where /*Name =: 'Amy Harrington'];//*/ProfileId =: p.Id and isActive = true limit 1]; //
/*User u = new User(Alias = 'standt', Email='standarduser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');*/
Date d = System.Today();
DateTime dt = system.now();
date flightstart = date.valueof(dt.addMonths(-3));
date flightend = date.valueof(dt.addMonths(3));
string ThisWeek1 = dt.format('w');
string LastWeek = dt.addDays(-7).format('w');
integer Lastweeki = integer.valueof((string)Lastweek);
integer thisweeki = integer.valueof((string)thisweek1);
string thisyear = dt.format('yyyy');
string thisMonth = dt.format('MMMM');
string Quarter = ThisMonth == 'January' ? 'Q1' : ThisMonth == 'February' ? 'Q1' : ThisMonth == 'March' ? 'Q1' : ThisMonth == 'April' ? 'Q2': ThisMonth == 'May' ? 'Q2' : ThisMonth == 'June' ? 'Q2' : ThisMonth == 'July' ? 'Q3' : ThisMonth == 'August' ? 'Q3' : ThisMonth == 'September' ? 'Q3' : ThisMonth == 'October' ? 'Q4' : ThisMonth == 'November' ? 'Q4' : ThisMonth == 'December' ? 'Q4' : '' ;
list<Quota__c> qtalist = new list<Quota__c>();
Quota__c testqta = new Quota__c (OwnerId = u2.Id, January__c = 100, February__c = 100, March__c = 100, April__c = 100, May__c = 100, June__c = 100, July__c = 100, August__c = 100, September__c = 100, October__c = 100, November__c = 100, December__c = 100, RecordTypeId = '012500000009iOD',Year__c = '2013',Region__c = 'aaa',Office__c = 'aaa',Team__c = 'aaa');
qtalist.add(testqta);
Quota__c qta3 = new Quota__c (OwnerId = u2.Id, January__c = 2, February__c = 2, March__c = 2, April__c = 2, May__c = 2, June__c = 2, July__c = 2, August__c = 2, September__c = 2, October__c = 2, November__c = 2, December__c = 2, RecordTypeId = '012500000009iOD',Year__c = '2012',Region__c = 'aaa',Office__c = 'aaa',Team__c = 'aaa');
qtalist.add(qta3);
Quota__c qta2 = new Quota__c (name ='default',OwnerId = u2.Id, January__c = 2, February__c = 2, March__c = 2, April__c = 2, May__c = 2, June__c = 2, July__c = 2, August__c = 2, September__c = 2, October__c = 2, November__c = 2, December__c = 2, RecordTypeId = '012500000009iOD',Year__c = '2012',Region__c = 'aaa',Office__c = 'aaa',Team__c = 'aaa');
qtalist.add(qta2);
insert qtalist;
test.startTest();
list<Account> AdvertiserList = new list<Account>();
id holdingcompanyrt = utils.getRecordTypeId('Account', 'Holding Company');
Account HoldingCompany = new Account(Name = 'Test HoldingCompany', RecordTypeId = holdingcompanyrt, OwnerID = u2.Id);
insert HoldingCompany;
id mainagencyrt = utils.getRecordTypeId('Account', 'Main Agency');
Account MainAgency = new Account(Name = 'Test Main Agency', RecordTypeId = mainagencyrt,OwnerID = u2.Id,Holding_Company_Name__c = HoldingCompany.Id);
insert MainAgency;
id LocalAgencyrt = utils.getRecordTypeId('Account','Local Agency');
Account LocalAgency = new Account(Name = 'Test Local Agency', RecordTypeId = LocalAgencyrt, Main_Agency__c = MainAgency.Id, Holding_Company_Name__c = HoldingCompany.Id, SageID__c ='ABC100');
insert LocalAgency;
Account LocalAgency2 = new Account(Name = 'Test Local Agency2', Main_Agency__c = MainAgency.Id ,RecordTypeId = LocalAgencyrt, SageID__c ='ABC100');
insert LocalAgency2;
id Advertiserrt = utils.getRecordTypeId('Account', 'Advertiser');
Account Advertiser = new Account(Name = 'Test Advertiser', RecordTypeId = Advertiserrt, Local_Agency__c = LocalAgency.Id );
insert Advertiser;
Advertiser.BillingState = 'Idaho';
Advertiser.BillingCountry = 'United States';
Advertiser.Create_Sage__c = true;
Advertiser.SageID__c = '';
Advertiser.Main_Agency__c = null;
update Advertiser;
Advertiser.BillingState = '';
update Advertiser;
Advertiser.SageID__c ='100ABC';
update Advertiser;
test.stopTest();
}
static testmethod void testmethod2() {
test.startTest();
Opportunity opp = [select id from Opportunity where Name IN('test') and CloseDate >: system.today()-60 and Sales_Stage_High_Level__c =: 'Open' and HasOpportunityLineItem =: true limit 1];
opp.move_all_flight_dates__c = true;
opp.ContractStartDate__c = system.Today();
opp.ContractEndDate__c = system.Today()+90;
update opp;
test.stopTest();
}
static testmethod void testmethod5() {
test.startTest();
Opportunity opp = [select id from Opportunity where Name IN('test') and Sales_Stage_High_Level__c =: 'Open' and HasOpportunityLineItem =: true limit 1];
opp.StageName = 'Closed Won';
opp.HasSageID__c = false;
opp.Exception__c = false;
opp.SVP_Email__c = null;
update opp;
delete opp;
test.stopTest();
}
static testmethod void testmethod4(){
test.startTest();
Opportunity opp = [select id from Opportunity where Name IN('test') and Sales_Stage_High_Level__c =: 'Open' limit 1];
OpportunityTeamMember ot = new OpportunityTeamMember(UserId = '005500000018PC2', TeamMemberRole='Account Manager',Split__c = 50,Date_Split_Starts__c = system.Today(),Date_Split_Ends__c=system.Today()+30, OpportunityId = opp.Id);
insert ot;
test.stopTest();
}
static testmethod void testmethod6(){
test.startTest();
/* Opportunity opp = [select id from Opportunity where Name IN('test') and Sales_Stage_High_Level__c =: 'Open' and HasOpportunityLineItem =: false limit 1];
Product2 prod = new Product2(name='test product',CanUseRevenueSchedule=True);
insert prod;
PricebookEntry pbe = new PricebookEntry(UnitPrice=0, UseStandardPrice=true,Product2Id=prod.id, Pricebook2Id = '01s50000000IJr3',IsActive=true);
insert pbe;
OpportunityLineItem oliUS = new OpportunityLineItem(UnitPrice=0,Quantity=1,PricebookEntryId=pbe.Id ,OpportunityId=opp.id, Placement__c = 'aaa', Flight_Start_Date__c =system.today()-1,Flight_End_Date__c = system.today()+30, Rev_Type__c = 'CPM',Rate__c = 1, insertbudget__c = 600, distribute_evenly__c = true );
insert oliUS;*/
test.stopTest();
}
static testmethod void testmethod7(){
test.startTest();
Opportunity opp = [select id from Opportunity where Name = 'The Testing Opportunity' limit 1];
update opp;
opp.StageName = 'Closed Won';
update opp;
delete opp;
test.stopTest();
}
static testmethod void testmethod3(){
PageReference pageref = new Pagereference('apex/Account_Transfer2');
test.setcurrentpage(pageRef);
//Instantiate the standard controller
Account act = new Account();
ApexPages.StandardController sc = new Apexpages.standardController(act);
//Instantiate the extension
//Account_Transfer2 ext = new Account_Transfer2(sc);
//Do the work
//ext.getEmps();
//ext.del();
//ext.onSave();
//ext.AccountWork();
//ext.NextPage();
//ext.Opportunity_Transfer();
}
}
public class test_updatecontactrolecount
{
public static testMethod void testcreateopptywithconditionandrole()
{
//Insert Opportunities
try
{
Opportunity Oppty = new Opportunity(Name='Oppty_test1',StageName='Stage 1 - Unqualified Prospect',Type ='New Business', CloseDate=System.Today());
insert Oppty;
// insert contact
Contact[] cont = new Contact[]
{
new Contact(LastName = 'testcontact1'),
new Contact(LastName = 'testcontact2')
};
insert cont;
// insert contact role
OpportunityContactRole [] ocr = new OpportunityContactRole[]
{
new OpportunityContactRole(Role ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),
new OpportunityContactRole(Role ='Business User',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = False)
};
insert ocr;
Oppty.StageName = 'Stage 3 - Eval Request';
//Update opportunity
Test.StartTest();
update Oppty;
Test.StopTest();
Oppty =[SELECT Number_of_Contacts_Roles_Assigned__c,Primary_Contact_Assigned__c FROM Opportunity WHERE Id = :Oppty.Id];
system.assert (Oppty.Number_of_Contacts_Roles_Assigned__c == 2);
system.assert (Oppty.Primary_Contact_Assigned__c == True);
}
catch (System.DmlException e)
{
System.assert(false);
}
}
}
One of your inserts in your test is failing, so the code is throwing an exception which is causing the test to fail. Try replacing the code with this. It will provide a few more details as to what the failure is.