You need to sign in to do that
Don't have an account?
Basil Choudhry
Test For a Trigger when moving into from Sandbox to Production
Hi,
I've just made our first trigger in the sandbox, it's working fine and it's quite simple. But when I try to deploy it I get various errors about test coverage. I understand that these are saying I need to test the code, but after some googling I'm not sure: do I need to add this test to the trigger itself, what does the test need to look like?
This is the trigger:
trigger ChangeOpportunityToProposalSent on Task (after insert) {
ID OppId;
Set<ID> setSTRIDs = new Set<ID>();
for (Task tasks:Trigger.New){
//if (tasks.What.Type== 'Opportunity')
setSTRIDs.add(tasks.WhatId);
Opportunity opp= [SELECT StageName FROM Opportunity WHERE ID IN:setSTRIDs];
if(tasks.Subject=='RE: Your Tailored Proposal'){opp.StageName='Proposal Sent';}
update opp;
}
Any help would be greatly appreciated.
I've just made our first trigger in the sandbox, it's working fine and it's quite simple. But when I try to deploy it I get various errors about test coverage. I understand that these are saying I need to test the code, but after some googling I'm not sure: do I need to add this test to the trigger itself, what does the test need to look like?
This is the trigger:
trigger ChangeOpportunityToProposalSent on Task (after insert) {
ID OppId;
Set<ID> setSTRIDs = new Set<ID>();
for (Task tasks:Trigger.New){
//if (tasks.What.Type== 'Opportunity')
setSTRIDs.add(tasks.WhatId);
Opportunity opp= [SELECT StageName FROM Opportunity WHERE ID IN:setSTRIDs];
if(tasks.Subject=='RE: Your Tailored Proposal'){opp.StageName='Proposal Sent';}
update opp;
}
Any help would be greatly appreciated.
Your updated Trigger:
Test Class of trigger :
If this solves your problem, kindly mark it as the best answer.
Thnaks,
Vatsal
All Answers
To write the test class for this above trigger, do the following:
1)Create an Opportunity
2)Create a Task linked to the Opportunity created at 1 with subject ="RE: Your Tailored Proposal" (with What.Type= 'Opportunity)
3)use system.assert to check the Opportunity status converted to Proposal sent which should happen when this trigger is fired.
sample code:
http://teachmesalesforce.wordpress.com/2011/05/07/how-to-write-a-trigger-test/
https://developer.salesforce.com/blogs/engineering/2013/04/apex-test-code-segregation.html
reference:http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_deploying_ant_deploy.htm
Hope this helps!
Your updated Trigger:
Test Class of trigger :
If this solves your problem, kindly mark it as the best answer.
Thnaks,
Vatsal