• Partha S 13
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi All,
I need help in writing test class for trigger. I have written but its giving only 65%. Please help me.
trigger test1 on obj1__c (after insert, after update)
{
if(trigger.isAfter&& (trigger.isinsert || trigger.isUpdate))
{
    test3.method1(Trigger.New);
}
}
 
public class test3
{
    public static void method1(List<Obj1__c> o1)
    {
        map<string, obj1__c> ObjMap = new map<string, obj1__c>();
    
    for(obj1__c obj: o1)
    {
        if (obj.Shared_Field__c != Null)
        {
            ObjMap.put(obj.Shared_Field__c, obj);
        }
    }
    
    List<obj2__c> obj2l = [SELECT Id, Shared_Field__c, F1__c,f2__c 
                        FROM obj2__c WHERE Shared_Field__c IN :ObjMap.KeySet()];
    List<obj2__c> obj2list = new List<obj2__c>();
    
    for(obj2__c c: obj2l)
    {
        obj1__c obj = ObjMap.get(c.Shared_Field__c);
        c.f1__c = obj.f1__c;
        c.f2__c = obj.f2__c;
        
        obj2list.add(c);
    }
    
    if(obj2list.size() > 0)
    {
        update obj2list;
    }
    }
    
}

Thanks in Advance

 
Hi All,
I need help in writing test class for trigger. I have written but its giving only 65%. Please help me.
trigger test1 on obj1__c (after insert, after update)
{
if(trigger.isAfter&& (trigger.isinsert || trigger.isUpdate))
{
    test3.method1(Trigger.New);
}
}
 
public class test3
{
    public static void method1(List<Obj1__c> o1)
    {
        map<string, obj1__c> ObjMap = new map<string, obj1__c>();
    
    for(obj1__c obj: o1)
    {
        if (obj.Shared_Field__c != Null)
        {
            ObjMap.put(obj.Shared_Field__c, obj);
        }
    }
    
    List<obj2__c> obj2l = [SELECT Id, Shared_Field__c, F1__c,f2__c 
                        FROM obj2__c WHERE Shared_Field__c IN :ObjMap.KeySet()];
    List<obj2__c> obj2list = new List<obj2__c>();
    
    for(obj2__c c: obj2l)
    {
        obj1__c obj = ObjMap.get(c.Shared_Field__c);
        c.f1__c = obj.f1__c;
        c.f2__c = obj.f2__c;
        
        obj2list.add(c);
    }
    
    if(obj2list.size() > 0)
    {
        update obj2list;
    }
    }
    
}

Thanks in Advance