+ Start a Discussion
Surbhi Dham 10Surbhi 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!!
Salesforce####Salesforce####
@can you tell me why there are two triggers currently .... ?? tell me for which code is your trigger working i will send the test class to that . reply with working class and trigger
 
Surbhi Dham 10Surbhi Dham 10
First trigger is for the attachment and second is for the task. My code is working in my Developer Sandbox.

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.

User-added image
Salesforce####Salesforce####

Hi Again , 

ok now i understand that there are two triggers and both need test classes for code coverage , am i correct ??
 
Surbhi Dham 10Surbhi Dham 10
Yes Correct.
Surbhi Dham 10Surbhi Dham 10
Can you help here.
Surbhi Dham 10Surbhi Dham 10
Can anyone help here!
Surbhi Dham 10Surbhi Dham 10
Hi, Can anyone help here. This is an URGENT request.