You need to sign in to do that
Don't have an account?
Rachel Linder 8
My Trigger Failed Deployment - errors with two test classes
I am trying to deploy the following trigger into production. I am getting a code coverage error of 69%. It shows it failed with two test classes. What can I do to correct. I need to unfortunately have this deployed this evening or first thing in the morning. Any help would be greatly appreciated. I am a Salesforce Administrator not a Developer so I am a beginner to say the least.
TRIGGER CODE
trigger Opportunity_Adelphic_AE_Email_Trigger on Opportunity (before insert, before update) {
map<string, string> DM = new map<string, string>();
Set<String> Person = new Set<String>();
For(Opportunity opp : trigger.new)
{
if(opp.Adelphic_AE__c!=null)
Person.add(opp.Adelphic_AE__c);
}
List<Holding_Object__c> HoldingLst = new List<Holding_Object__c>();
if(Person!=null && Person.size()>0)
{
HoldingLst=[select Persons_Name__c, Email_Address__c from Holding_Object__c where Persons_Name__c in: Person];
}
if(HoldingLst!=null && HoldingLst.size()>0)
{
for(Holding_Object__c hd : HoldingLst)
{
DM.put(hd.Persons_Name__c, hd.Email_Address__c);
}
}
for(opportunity opp : trigger.new)
{
if(DM.Containskey(opp.Adelphic_AE__c) && DM.get(opp.Adelphic_AE__c)!=null)
opp.Adelphic_AE_Email__c = DM.get(opp.Adelphic_AE__c);
}
}
MassLeadConverterControllerTest Test Class Error:
Error Message: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, There's a problem with this country, even though it may appear correct. Please select a country/territory from the list of valid countries.: [BillingCountry]
Stack Trace: Class.MassLeadConverterControllerTest.massLeadTest: line 11, column 1
test_updatecontactrolecount Test Class Error:
Error Message: System.Exception: Assertion Failed
Stack Trace: Class.test_updatecontactrolecount.testcreateopptywithconditionandrole: line 38, column 1
TRIGGER CODE
trigger Opportunity_Adelphic_AE_Email_Trigger on Opportunity (before insert, before update) {
map<string, string> DM = new map<string, string>();
Set<String> Person = new Set<String>();
For(Opportunity opp : trigger.new)
{
if(opp.Adelphic_AE__c!=null)
Person.add(opp.Adelphic_AE__c);
}
List<Holding_Object__c> HoldingLst = new List<Holding_Object__c>();
if(Person!=null && Person.size()>0)
{
HoldingLst=[select Persons_Name__c, Email_Address__c from Holding_Object__c where Persons_Name__c in: Person];
}
if(HoldingLst!=null && HoldingLst.size()>0)
{
for(Holding_Object__c hd : HoldingLst)
{
DM.put(hd.Persons_Name__c, hd.Email_Address__c);
}
}
for(opportunity opp : trigger.new)
{
if(DM.Containskey(opp.Adelphic_AE__c) && DM.get(opp.Adelphic_AE__c)!=null)
opp.Adelphic_AE_Email__c = DM.get(opp.Adelphic_AE__c);
}
}
MassLeadConverterControllerTest Test Class Error:
Error Message: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, There's a problem with this country, even though it may appear correct. Please select a country/territory from the list of valid countries.: [BillingCountry]
Stack Trace: Class.MassLeadConverterControllerTest.massLeadTest: line 11, column 1
test_updatecontactrolecount Test Class Error:
Error Message: System.Exception: Assertion Failed
Stack Trace: Class.test_updatecontactrolecount.testcreateopptywithconditionandrole: line 38, column 1
@isTest
private class MassLeadConverterControllerTest {
static testMethod void massLeadTest() {
// set up account
Account acc = new Account();
acc.Name = 'Acme Account Test';
acc.BillingCountry = 'US'; //-------------> Please enter a valid country here
acc.ShippingCountry = 'US'; //-------------> Please enter a valid country here
acc.BillingState = 'IL'; //-------------> Please enter a valid state here
insert acc;
// set up leads
List<Lead> testLeads = new List<Lead>();
Lead lead1 = new Lead();
lead1.Company = 'Test 1 New Company';
lead1.LastName = 'Martha';
lead1.LeadSource = 'Not Converted';
testLeads.add(lead1);
Lead lead2 = new Lead();
lead2.Company = 'Test 12';
lead2.LastName = 'Jordan';
lead2.LeadSource = 'Not Converted';
testLeads.add(lead2);
Lead lead3 = new Lead();
lead3.Company = 'Test 3';
lead3.LastName = 'Paul';
lead3.LeadSource = 'Not Converted';
testLeads.add(lead3);
Lead lead4 = new Lead();
lead4.Company = 'Test 1';
lead4.LastName = 'Cathy';
lead4.LeadSource = 'Not Converted';
testLeads.add(lead4);
Lead lead5 = new Lead();
lead5.Company = 'Test 1';
lead5.LastName = 'Dereck';
lead5.LeadSource = 'Not Converted';
testLeads.add(lead5);
Lead lead6 = new Lead();
lead6.Company = 'Test 1';
lead6.LastName = 'Benjamin';
lead6.LeadSource = 'Not Converted';
testLeads.add(lead6);
Lead lead7 = new Lead();
lead7.Company = 'Test 1';
lead7.LastName = 'Franklin';
lead7.LeadSource = 'Not Converted';
testLeads.add(lead7);
insert testLeads;
// set up extension
List<Lead> selectedLeads = new List<Lead>();
selectedLeads.add(lead1);
selectedLeads.add(lead2);
ApexPages.Standardsetcontroller con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
MassLeadConverterController mlc = new MassLeadConverterController(con);
// try with new account
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Create an opportunity for each lead';
mlc.convertLeads();
List<Contact> resultingContacts = [select Id from Contact Where Account.Name = 'Test 1 New Company'];
System.assertEquals(2, resultingContacts.size());
List<Opportunity> resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'Test 1 New Company'];
System.assertEquals(2, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead3);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and do not create opportunity
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Do not create new opportunity';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(1, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'Acme Account Test'];
System.assertEquals(0, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead4);
selectedLeads.add(lead5);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and only create one opportunity and a task for each lead
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Combine all leads into a single opportunity';
mlc.taskOption = 'Create a task for each lead';
mlc.opportunityName = 'acme opp';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(3, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'acme opp'];
System.assertEquals(1, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead6);
selectedLeads.add(lead7);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and only create one opportunity and a task for each lead
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Create an opportunity for each lead';
mlc.taskOption = 'Create a task for each lead';
mlc.opportunityName = 'multiple opps';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(5, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'multiple opps'];
System.assertEquals(2, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
System.assertEquals(false, mlc.isEditable);
}
}
-----------------
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);
}
}
}
Let us know if this will help you
All Answers
You must be creating a test records there , provide valid country
2) you have used system.assert at line 38. check either both values are equal or not.
If it is possible than share your both test classes
Please mark it as solved if this solves your problem
You need to update both classes
@isTest
private class MassLeadConverterControllerTest {
static testMethod void massLeadTest() {
// set up account
Account acc = new Account();
acc.Name = 'Acme Account Test';
acc.BillingCountry = 'US';
acc.ShippingCountry = 'US';
acc.BillingState = 'IL';
insert acc;
// set up leads
List<Lead> testLeads = new List<Lead>();
Lead lead1 = new Lead();
lead1.Company = 'Test 1 New Company';
lead1.LastName = 'Martha';
lead1.LeadSource = 'Not Converted';
testLeads.add(lead1);
Lead lead2 = new Lead();
lead2.Company = 'Test 12';
lead2.LastName = 'Jordan';
lead2.LeadSource = 'Not Converted';
testLeads.add(lead2);
Lead lead3 = new Lead();
lead3.Company = 'Test 3';
lead3.LastName = 'Paul';
lead3.LeadSource = 'Not Converted';
testLeads.add(lead3);
Lead lead4 = new Lead();
lead4.Company = 'Test 1';
lead4.LastName = 'Cathy';
lead4.LeadSource = 'Not Converted';
testLeads.add(lead4);
Lead lead5 = new Lead();
lead5.Company = 'Test 1';
lead5.LastName = 'Dereck';
lead5.LeadSource = 'Not Converted';
testLeads.add(lead5);
Lead lead6 = new Lead();
lead6.Company = 'Test 1';
lead6.LastName = 'Benjamin';
lead6.LeadSource = 'Not Converted';
testLeads.add(lead6);
Lead lead7 = new Lead();
lead7.Company = 'Test 1';
lead7.LastName = 'Franklin';
lead7.LeadSource = 'Not Converted';
testLeads.add(lead7);
insert testLeads;
// set up extension
List<Lead> selectedLeads = new List<Lead>();
selectedLeads.add(lead1);
selectedLeads.add(lead2);
ApexPages.Standardsetcontroller con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
MassLeadConverterController mlc = new MassLeadConverterController(con);
// try with new account
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Create an opportunity for each lead';
mlc.convertLeads();
List<Contact> resultingContacts = [select Id from Contact Where Account.Name = 'Test 1 New Company'];
System.assertEquals(2, resultingContacts.size());
List<Opportunity> resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'Test 1 New Company'];
System.assertEquals(2, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead3);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and do not create opportunity
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Do not create new opportunity';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(1, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'Acme Account Test'];
System.assertEquals(0, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead4);
selectedLeads.add(lead5);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and only create one opportunity and a task for each lead
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Combine all leads into a single opportunity';
mlc.taskOption = 'Create a task for each lead';
mlc.opportunityName = 'acme opp';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(3, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'acme opp'];
System.assertEquals(1, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead6);
selectedLeads.add(lead7);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and only create one opportunity and a task for each lead
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Create an opportunity for each lead';
mlc.taskOption = 'Create a task for each lead';
mlc.opportunityName = 'multiple opps';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(5, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'multiple opps'];
System.assertEquals(2, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
System.assertEquals(false, mlc.isEditable);
}
}
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);
}
}
}
@isTest
private class MassLeadConverterControllerTest {
static testMethod void massLeadTest() {
// set up account
Account acc = new Account();
acc.Name = 'Acme Account Test';
acc.BillingCountry = 'US'; //-------------> Please enter a valid country here
acc.ShippingCountry = 'US'; //-------------> Please enter a valid country here
acc.BillingState = 'IL'; //-------------> Please enter a valid state here
insert acc;
// set up leads
List<Lead> testLeads = new List<Lead>();
Lead lead1 = new Lead();
lead1.Company = 'Test 1 New Company';
lead1.LastName = 'Martha';
lead1.LeadSource = 'Not Converted';
testLeads.add(lead1);
Lead lead2 = new Lead();
lead2.Company = 'Test 12';
lead2.LastName = 'Jordan';
lead2.LeadSource = 'Not Converted';
testLeads.add(lead2);
Lead lead3 = new Lead();
lead3.Company = 'Test 3';
lead3.LastName = 'Paul';
lead3.LeadSource = 'Not Converted';
testLeads.add(lead3);
Lead lead4 = new Lead();
lead4.Company = 'Test 1';
lead4.LastName = 'Cathy';
lead4.LeadSource = 'Not Converted';
testLeads.add(lead4);
Lead lead5 = new Lead();
lead5.Company = 'Test 1';
lead5.LastName = 'Dereck';
lead5.LeadSource = 'Not Converted';
testLeads.add(lead5);
Lead lead6 = new Lead();
lead6.Company = 'Test 1';
lead6.LastName = 'Benjamin';
lead6.LeadSource = 'Not Converted';
testLeads.add(lead6);
Lead lead7 = new Lead();
lead7.Company = 'Test 1';
lead7.LastName = 'Franklin';
lead7.LeadSource = 'Not Converted';
testLeads.add(lead7);
insert testLeads;
// set up extension
List<Lead> selectedLeads = new List<Lead>();
selectedLeads.add(lead1);
selectedLeads.add(lead2);
ApexPages.Standardsetcontroller con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
MassLeadConverterController mlc = new MassLeadConverterController(con);
// try with new account
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Create an opportunity for each lead';
mlc.convertLeads();
List<Contact> resultingContacts = [select Id from Contact Where Account.Name = 'Test 1 New Company'];
System.assertEquals(2, resultingContacts.size());
List<Opportunity> resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'Test 1 New Company'];
System.assertEquals(2, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead3);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and do not create opportunity
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Do not create new opportunity';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(1, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'Acme Account Test'];
System.assertEquals(0, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead4);
selectedLeads.add(lead5);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and only create one opportunity and a task for each lead
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Combine all leads into a single opportunity';
mlc.taskOption = 'Create a task for each lead';
mlc.opportunityName = 'acme opp';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(3, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'acme opp'];
System.assertEquals(1, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
selectedLeads.add(lead6);
selectedLeads.add(lead7);
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
// try with existing account and only create one opportunity and a task for each lead
mlc.accOption = 'Add to existing account';
mlc.con.AccountId = acc.Id;
mlc.leadTask.ActivityDate = System.today();
mlc.leadTask.Subject = 'hi';
mlc.leadTask.Status = 'In Progress';
mlc.leadTask.Priority = 'High';
mlc.oppOption = 'Create an opportunity for each lead';
mlc.taskOption = 'Create a task for each lead';
mlc.opportunityName = 'multiple opps';
mlc.convertLeads();
resultingContacts = [select Id from Contact Where AccountId = :acc.Id];
System.assertEquals(5, resultingContacts.size());
resultingOpp = [select Id from Opportunity Where Opportunity.Name = 'multiple opps'];
System.assertEquals(2, resultingOpp.size());
// re-set up extension
selectedLeads = new List<Lead>();
con = new ApexPages.Standardsetcontroller(selectedLeads);
con.setSelected(selectedLeads);
mlc = new MassLeadConverterController(con);
System.assertEquals(false, mlc.isEditable);
}
}
-----------------
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);
}
}
}
Let us know if this will help you
- I am assuming I need to make these changes in our sandbox and then deploy to production. Is this correct?
- If I make these changes will it disrupt anything we currently have running in production? Or are these strictly used when testing during deployment of things such as triggers?
I need to avoid having any issues arise in the production environment.I sincerely appreciate the help.