You need to sign in to do that
Don't have an account?
Surbhi Dham 10
Deploying Apex Trigger and class from Developer sandbox to production.
Hi ,
I need some help. i have written an apex class and trigger code which counts the number of attachments on my task object. I need to write a test class so that i can deploy this in my production. i am unable to do so. Kindly help me in writing the test class.
Below is the codes written -
Trigger 1 –
trigger CountAttachment on Attachment (after insert, after update, after delete, after undelete) {
// Contains the IDs of all the parent tasks
Set<Id> parentTaskIdSet = new Set<id>();
if (trigger.new != null)
{
for (Attachment a: trigger.new)
{
parentTaskIdSet.add(a.parentId);
}
}
if (trigger.old != null)
{
for (Attachment a: trigger.old)
{
parentTaskIdSet.add(a.parentId);
}
}
// List of tasks that needs to be updated
List<Task> parentTaskList = [SELECT id, (SELECT id FROM Attachments) FROM Task WHERE id in: parentTaskIdSet];
for (Task t: parentTaskList)
{
t.NumberOfAttachments__c = t.Attachments.size();
}
update parentTaskList;
}
***************************************************************************************************************************************************
Trigger 2 –
trigger UpdateAttachmentCount on Task (after insert, after update) {
if (checkRecursive.runOnce())
{
List<Task> taskList = new List<Task>();
Set<ID> taskIDSet = new Set<ID>();
if (trigger.old != null)
{
for (Task t: trigger.old)
{
taskIDSet.add(t.ID);
}
}
if (trigger.new != null)
{
for (Task t: trigger.new)
{
taskIDSet.add(t.ID);
}
}
// Query for the attachment children of the taskspublic Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if (run){
run = false;
return true;
}
else
{
return run;
}
}
} taskList = [SELECT id, (SELECT id FROM attachments) FROM Task WHERE ID in: taskIDSet];
for (Task t: taskList)
{
t.NumberOfAttachments__c = t.Attachments.size();
}
update taskList;
}
}
**********************************************************************************************************************************************
Class –
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if (run){
run = false;
return true;
}
else
{
return run;
}
}
}
PLEASE HELP. URGENT!!
I need some help. i have written an apex class and trigger code which counts the number of attachments on my task object. I need to write a test class so that i can deploy this in my production. i am unable to do so. Kindly help me in writing the test class.
Below is the codes written -
Trigger 1 –
trigger CountAttachment on Attachment (after insert, after update, after delete, after undelete) {
// Contains the IDs of all the parent tasks
Set<Id> parentTaskIdSet = new Set<id>();
if (trigger.new != null)
{
for (Attachment a: trigger.new)
{
parentTaskIdSet.add(a.parentId);
}
}
if (trigger.old != null)
{
for (Attachment a: trigger.old)
{
parentTaskIdSet.add(a.parentId);
}
}
// List of tasks that needs to be updated
List<Task> parentTaskList = [SELECT id, (SELECT id FROM Attachments) FROM Task WHERE id in: parentTaskIdSet];
for (Task t: parentTaskList)
{
t.NumberOfAttachments__c = t.Attachments.size();
}
update parentTaskList;
}
***************************************************************************************************************************************************
Trigger 2 –
trigger UpdateAttachmentCount on Task (after insert, after update) {
if (checkRecursive.runOnce())
{
List<Task> taskList = new List<Task>();
Set<ID> taskIDSet = new Set<ID>();
if (trigger.old != null)
{
for (Task t: trigger.old)
{
taskIDSet.add(t.ID);
}
}
if (trigger.new != null)
{
for (Task t: trigger.new)
{
taskIDSet.add(t.ID);
}
}
// Query for the attachment children of the taskspublic Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if (run){
run = false;
return true;
}
else
{
return run;
}
}
} taskList = [SELECT id, (SELECT id FROM attachments) FROM Task WHERE ID in: taskIDSet];
for (Task t: taskList)
{
t.NumberOfAttachments__c = t.Attachments.size();
}
update taskList;
}
}
**********************************************************************************************************************************************
Class –
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if (run){
run = false;
return true;
}
else
{
return run;
}
}
}
PLEASE HELP. URGENT!!
I have created a change set to deploy the code from Developer Sandbox to Production but while doing that i need to write a test class as well so that my code works in production.
I am reciving the below error.
Hi Again ,
ok now i understand that there are two triggers and both need test classes for code coverage , am i correct ??