You need to sign in to do that
Don't have an account?
Alex Dorn
Deploying Triggers Help
I am attempting to deploy two fields and two triggers that place the Last Activity Subject into a field I made for leads and opportunities the triggers work perfectly in sandbox, but won't deploy in the production version. I am moving the two triggers along with the two fields the triggers reference. The code coverage listed in sandbox is 0% (0/14) for both I don't know if this is the problem, but they work perfectly and I haven't run into any problems when testing them in sandbox.
Here are the errors:
updateRelatedLead Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
updateRelatedOpportunity Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Deploy Error Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required.
And the two codes:
trigger updateRelatedOpportunity on Task (after insert,after update) {
List<Id> OpportunityIds = new List<Id>();
List<Opportunity> OpportunityList = new List<Opportunity>();
for(Task t :trigger.new)
{
if(t.whatid!=null)
{
Schema.SObjectType tType= t.whatid.getSObjectType();
if(tType == Opportunity.Schema.SObjectType)
{
OpportunityIds.add(t.Whatid);
}
}
}
{
//Querying the related Opportunity based on whatid on Task
Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([select id,Last_Activity_Subject__C from Opportunity where id in:OpportunityIds]);
for(Task t :Trigger.new)
for(Opportunity l : OpportunityMap.Values())
{
l.Last_Activity_Subject__C = t.subject;
OpportunityList.add(l);
}
}
// updating the Opportunity
if(OpportunityList.size()>0)
{
update OpportunityList;
}
}
trigger updateRelatedLead on Task (after insert,after update) {
List<Id> LeadIds = new List<Id>();
List<Lead> LeadList = new List<Lead>();
for(Task t :trigger.new)
{
if(t.whoId!=null)
{
Schema.SObjectType tType= t.whoId.getSObjectType();
if(tType == Lead.Schema.SObjectType)
{
LeadIds.add(t.WhoId);
}
}
}
{
//Querying the related Lead based on whoId on Task
Map<Id,Lead> LeadMap = new Map<Id,Lead>([select id,Last_Activity_Subject__C from Lead where id in:LeadIds]);
for(Task t :Trigger.new)
for(Lead l : LeadMap.Values())
{
l.Last_Activity_Subject__C = t.subject;
LeadList.add(l);
}
}
// updating the Lead
if(LeadList.size()>0)
{
update LeadList;
}
}
Here are the errors:
updateRelatedLead Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
updateRelatedOpportunity Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required
Deploy Error Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required.
And the two codes:
trigger updateRelatedOpportunity on Task (after insert,after update) {
List<Id> OpportunityIds = new List<Id>();
List<Opportunity> OpportunityList = new List<Opportunity>();
for(Task t :trigger.new)
{
if(t.whatid!=null)
{
Schema.SObjectType tType= t.whatid.getSObjectType();
if(tType == Opportunity.Schema.SObjectType)
{
OpportunityIds.add(t.Whatid);
}
}
}
{
//Querying the related Opportunity based on whatid on Task
Map<Id,Opportunity> OpportunityMap = new Map<Id,Opportunity>([select id,Last_Activity_Subject__C from Opportunity where id in:OpportunityIds]);
for(Task t :Trigger.new)
for(Opportunity l : OpportunityMap.Values())
{
l.Last_Activity_Subject__C = t.subject;
OpportunityList.add(l);
}
}
// updating the Opportunity
if(OpportunityList.size()>0)
{
update OpportunityList;
}
}
trigger updateRelatedLead on Task (after insert,after update) {
List<Id> LeadIds = new List<Id>();
List<Lead> LeadList = new List<Lead>();
for(Task t :trigger.new)
{
if(t.whoId!=null)
{
Schema.SObjectType tType= t.whoId.getSObjectType();
if(tType == Lead.Schema.SObjectType)
{
LeadIds.add(t.WhoId);
}
}
}
{
//Querying the related Lead based on whoId on Task
Map<Id,Lead> LeadMap = new Map<Id,Lead>([select id,Last_Activity_Subject__C from Lead where id in:LeadIds]);
for(Task t :Trigger.new)
for(Lead l : LeadMap.Values())
{
l.Last_Activity_Subject__C = t.subject;
LeadList.add(l);
}
}
// updating the Lead
if(LeadList.size()>0)
{
update LeadList;
}
}
Have you written test methods for your trigger? Salesforce won't allow you to deploy code to production if you don't have test coverage
A good article on this:
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods