• Varshitha K
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 21
    Replies
this is my trigger
trigger limitrecordtypes on Evaluation_by_metric__c (before insert,before update) {


if(trigger.isinsert){


list<Evaluation_by_metric__c> recordset=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new)
 {
   //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   system.debug('look '+c.Close_Period__c);
   
   if(c.Quarter__c != null)
   {
    for(Evaluation_by_metric__c cv: recordset)
       {
        if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c)
         {
          c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
         }
   }
 }
  if(c.Month__c != null)
      {
        for(Evaluation_by_metric__c ebm : recordset)
         {
            if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c)
              {
            c.Month__c.adderror('This Recordtype has been created for this Month');
              }
         }
      }
  }
 
 }
 
 
if(trigger.isupdate)
{
  list<Evaluation_by_metric__c> recordset1=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new){
 
    //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   
 Evaluation_by_metric__c oldAsset=trigger.oldMap.get(c.id);
 system.debug('@@@@@@'+oldAsset);
 
     if(oldAsset.Quarter__c !=null){
 
         for(Evaluation_by_metric__c cv: recordset1){
 
             if(cv.Quarter__c == oldAsset.Quarter__c && cv.recordtypeid == oldAsset.recordtypeid && cv.Metric__c==oldAsset.Metric__c){
             
               cv.quarter__c=oldAsset.Quarter__c;
               cv.recordtypeid = oldAsset.recordtypeid;
               cv.Metric__c=oldAsset.Metric__c;
              
               
                 
 }
 else if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c){
 
                 c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
 
 }
 }
 
 
 }
 
 
 
 if(oldAsset.Month__c != null){
 for(Evaluation_by_metric__c ebm: recordset1){
 if(ebm.Month__c == oldAsset.Month__c && ebm.recordtypeid == oldAsset.recordtypeid && ebm.Metric__c==oldAsset.Metric__c){
               ebm.Month__c =oldAsset.Month__c;
               ebm.recordtypeid = oldAsset.recordtypeid;
               ebm.Metric__c=oldAsset.Metric__c;
}
 else if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c){
 
                 c.Month__c.adderror('This Recordtype has been created for this Quarter');
 
 }
}
}
}










}
}

and i got only 13% test coverage for test class
@isTest

private class limitrecordtypesTest{

    
   static testMethod void lim() {
   
   
   Boolean result = false;
   recordtype rec=new recordtype();
   rec.name='Financial evaluation';
  
   Metric__c met1=new  Metric__c(Name='a');
    Metric__c met2=new  Metric__c(Name='b');
    Evaluation_by_metric__c eva1 = new Evaluation_by_metric__c(Metric__c=met1.id,Quarter__c='Q1',recordtype=rec); 
    
   insert eva1;
   
    Evaluation_by_metric__c eva3 = new Evaluation_by_metric__c(Metric__c=met2.id, Month__c='jan',recordtype=rec); 
    
   insert eva3;
   Close_Period__c closePeriod1 = new Close_Period__c(id=eva1.id,Name = 'Test1 Close Period');
     Close_Period__c closePeriod2 = new Close_Period__c(id=eva3.id,Name = 'Test2 Close Period');
        insert closePeriod1;
        insert closePeriod2;
   try{
   
    Evaluation_by_metric__c eva2 = new Evaluation_by_metric__c(Quarter__c='Q1',recordtype=rec); 
    insert eva2;
    }catch(DmlException ex){ result = true;}
      System.assert(result);
   
   
   try{
   
    Evaluation_by_metric__c eva4 = new Evaluation_by_metric__c(Month__c='jan',recordtype=rec); 
    insert eva4;
    }catch(DmlException ex){ result = true;}
      System.assert(result);
      }
      }

so,plz help me with the code.
I have the following trigger.
trigger limitrecordtypes on Evaluation_by_metric__c (before insert,before update) {


if(trigger.isinsert){


list<Evaluation_by_metric__c> recordset=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new)
 {
   //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   system.debug('look '+c.Close_Period__c);
   
   if(c.Quarter__c != null)
   {
    for(Evaluation_by_metric__c cv: recordset)
       {
        if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c)
         {
          c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
         }
   }
 }
  if(c.Month__c != null)
      {
        for(Evaluation_by_metric__c ebm : recordset)
         {
            if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c)
              {
            c.Month__c.adderror('This Recordtype has been created for this Month');
              }
         }
      }
  }
 
 }
 
 
if(trigger.isupdate)
{
  list<Evaluation_by_metric__c> recordset1=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new){
 
    //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   
 Evaluation_by_metric__c oldAsset=trigger.oldMap.get(c.id);
 system.debug('@@@@@@'+oldAsset);
 
     if(oldAsset.Quarter__c !=null){
 
         for(Evaluation_by_metric__c cv: recordset1){
 
             if(cv.Quarter__c == oldAsset.Quarter__c && cv.recordtypeid == oldAsset.recordtypeid && cv.Metric__c==oldAsset.Metric__c){
             
               cv.quarter__c=oldAsset.Quarter__c;
               cv.recordtypeid = oldAsset.recordtypeid;
               cv.Metric__c=oldAsset.Metric__c;
              
               
                 
 }
 else if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c){
 
                 c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
 
 }
 }
 
 
 }
 
 
 
 if(oldAsset.Month__c != null){
 for(Evaluation_by_metric__c ebm: recordset1){
 if(ebm.Month__c == oldAsset.Month__c && ebm.recordtypeid == oldAsset.recordtypeid && ebm.Metric__c==oldAsset.Metric__c){
               ebm.Month__c =oldAsset.Month__c;
               ebm.recordtypeid = oldAsset.recordtypeid;
               ebm.Metric__c=oldAsset.Metric__c;
}
 else if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c){
 
                 c.Month__c.adderror('This Recordtype has been created for this Quarter');
 
 }
}
}
}










}
}
Can you plzz write the test class code for this trigger?
Thanks in advance.
I have the following trigger.
 
trigger limitrecordtypes on Evaluation_by_metric__c (before insert,before update) {


if(trigger.isinsert){


list<Evaluation_by_metric__c> recordset=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new)
 {
   //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   system.debug('look '+c.Close_Period__c);
   
   if(c.Quarter__c != null)
   {
    for(Evaluation_by_metric__c cv: recordset)
       {
        if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c)
         {
          c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
         }
   }
 }
  if(c.Month__c != null)
      {
        for(Evaluation_by_metric__c ebm : recordset)
         {
            if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c)
              {
            c.Month__c.adderror('This Recordtype has been created for this Month');
              }
         }
      }
  }
 
 }
 
 
if(trigger.isupdate)
{
  list<Evaluation_by_metric__c> recordset1=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new){
 
    //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   
 Evaluation_by_metric__c oldAsset=trigger.oldMap.get(c.id);
 system.debug('@@@@@@'+oldAsset);
 
     if(oldAsset.Quarter__c !=null){
 
         for(Evaluation_by_metric__c cv: recordset1){
 
             if(cv.Quarter__c == oldAsset.Quarter__c && cv.recordtypeid == oldAsset.recordtypeid && cv.Metric__c==oldAsset.Metric__c){
             
               cv.quarter__c=oldAsset.Quarter__c;
               cv.recordtypeid = oldAsset.recordtypeid;
               cv.Metric__c=oldAsset.Metric__c;
              
               
                 
 }
 else if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c){
 
                 c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
 
 }
 }
 
 
 }
 
 
 
 if(oldAsset.Month__c != null){
 for(Evaluation_by_metric__c ebm: recordset1){
 if(ebm.Month__c == oldAsset.Month__c && ebm.recordtypeid == oldAsset.recordtypeid && ebm.Metric__c==oldAsset.Metric__c){
               ebm.Month__c =oldAsset.Month__c;
               ebm.recordtypeid = oldAsset.recordtypeid;
               ebm.Metric__c=oldAsset.Metric__c;
}
 else if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c){
 
                 c.Month__c.adderror('This Recordtype has been created for this Quarter');
 
 }
}
}
}










}
}

Can you plzz write the test class code for this trigger?
Thanks in advance.
I have a work flow and i need to invoke the flow using trigger only.Can you plz explain with the help of an example?
Thanks in advance.
I have this:User-added imageNow,i want this:User-added imageplz explain me with proper code.
I have the above table:User-added image now i want the below table:User-added imageplz explain me proper code.
User-added imageI have created a lookup field  called Metric Board Name for a object named Metrics.Now i need to add the records present in the metric board lookup field,one at a time, to a separate list .How can I do this?
plzz help me,thanks in advance.


















 
I have created a lookup field  called metric board for a object named metrics.Now i need to add the records present in the metric board lookup field,one at a time, to a separate list .How can I do this?
plzz help me,thanks in advance.
I have the following trigger.
trigger limitrecordtypes on Evaluation_by_metric__c (before insert,before update) {


if(trigger.isinsert){


list<Evaluation_by_metric__c> recordset=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new)
 {
   //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   system.debug('look '+c.Close_Period__c);
   
   if(c.Quarter__c != null)
   {
    for(Evaluation_by_metric__c cv: recordset)
       {
        if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c)
         {
          c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
         }
   }
 }
  if(c.Month__c != null)
      {
        for(Evaluation_by_metric__c ebm : recordset)
         {
            if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c)
              {
            c.Month__c.adderror('This Recordtype has been created for this Month');
              }
         }
      }
  }
 
 }
 
 
if(trigger.isupdate)
{
  list<Evaluation_by_metric__c> recordset1=new list<Evaluation_by_metric__c>([select id,recordtypeid,Quarter__c,Metric__c,Month__c from Evaluation_by_metric__c]);


 for(Evaluation_by_metric__c c: trigger.new){
 
    //mapping close period record with evaluation record before insert
   c.Close_Period__c = [select id from Close_Period__c limit 1].id;
   
 Evaluation_by_metric__c oldAsset=trigger.oldMap.get(c.id);
 system.debug('@@@@@@'+oldAsset);
 
     if(oldAsset.Quarter__c !=null){
 
         for(Evaluation_by_metric__c cv: recordset1){
 
             if(cv.Quarter__c == oldAsset.Quarter__c && cv.recordtypeid == oldAsset.recordtypeid && cv.Metric__c==oldAsset.Metric__c){
             
               cv.quarter__c=oldAsset.Quarter__c;
               cv.recordtypeid = oldAsset.recordtypeid;
               cv.Metric__c=oldAsset.Metric__c;
              
               
                 
 }
 else if(cv.Quarter__c == c.Quarter__c && cv.recordtypeid == c.recordtypeid && cv.Metric__c==c.Metric__c){
 
                 c.Quarter__c.adderror('This Recordtype has been created for this Quarter');
 
 }
 }
 
 
 }
 
 
 
 if(oldAsset.Month__c != null){
 for(Evaluation_by_metric__c ebm: recordset1){
 if(ebm.Month__c == oldAsset.Month__c && ebm.recordtypeid == oldAsset.recordtypeid && ebm.Metric__c==oldAsset.Metric__c){
               ebm.Month__c =oldAsset.Month__c;
               ebm.recordtypeid = oldAsset.recordtypeid;
               ebm.Metric__c=oldAsset.Metric__c;
}
 else if(ebm.Month__c == c.Month__c && ebm.recordtypeid == c.recordtypeid && ebm.Metric__c==c.Metric__c){
 
                 c.Month__c.adderror('This Recordtype has been created for this Quarter');
 
 }
}
}
}










}
}
Can you plzz write the test class code for this trigger?
Thanks in advance.
I have this:User-added imageNow,i want this:User-added imageplz explain me with proper code.
User-added imageI have created a lookup field  called Metric Board Name for a object named Metrics.Now i need to add the records present in the metric board lookup field,one at a time, to a separate list .How can I do this?
plzz help me,thanks in advance.