• Surbhi Dham 10
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 30
    Replies
I need help in writing the test class for below trigger and class that i have.

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;
        }
    }
}
 
 


Can anyone help here please
Hi, I am trying to create a formula field using the below.

IF(ISPICKVAL(Type , 'NEW BOM')||ISPICKVAL(Type, 'Customer Query')||ISPICKVAL(Type, 'New Collateral Request')&& Age_Business_Days__c   <=3,1,IF(ISPICKVAL(Type , 'BOM Update')&& Age_Business_Days__c   <=2,1,IF(ISPICKVAL(Type , 'Standard collateral request')||ISPICKVAL(Type, 'Custom Collateral Request')||ISPICKVAL(Type, 'Customer Demo/Presentation')||ISPICKVAL(Type, 'Customer meeting')||ISPICKVAL(Type, 'Meeting with Sales Rep')&&   Age_Business_Days__c   <=1,1,0)))

I am getting an error - Complied formula is too big. Can anyone help here. Thanks
 
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!!
Hi,
Please provide the steps on how to deploy my Apex Trigger and Apex Class from Developer Edition to Production?
Thanks
Hi, I am trying to create a formula field using the below.

IF(ISPICKVAL(Type , 'NEW BOM')||ISPICKVAL(Type, 'Customer Query')||ISPICKVAL(Type, 'New Collateral Request')&& Age_Business_Days__c   <=3,1,IF(ISPICKVAL(Type , 'BOM Update')&& Age_Business_Days__c   <=2,1,IF(ISPICKVAL(Type , 'Standard collateral request')||ISPICKVAL(Type, 'Custom Collateral Request')||ISPICKVAL(Type, 'Customer Demo/Presentation')||ISPICKVAL(Type, 'Customer meeting')||ISPICKVAL(Type, 'Meeting with Sales Rep')&&   Age_Business_Days__c   <=1,1,0)))

I am getting an error - Complied formula is too big. Can anyone help here. Thanks
 
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!!
Hi,
Please provide the steps on how to deploy my Apex Trigger and Apex Class from Developer Edition to Production?
Thanks