• cmunozhernan
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

Hello! I have been trying to do a Test Method for the following Trigger but everything I do doesn't seem to work. Please help me in any way you can. Here is my Trigger:

 

trigger duplicamant on Mantenimiento_Gastos__c(before insert){
    for(Mantenimiento_Gastos__c c : Trigger.new)
        {
Mantenimiento_Gastos__c[] contacts=[Select id,Propiedad__c from Mantenimiento_Gastos__c Where Propiedad__c=:c.Propiedad__c];
            if (contacts.size()>0) 
             {
            c.Propiedad__c.addError('The number is already registered!');
              }
          }
}

I have tried the following Test Method but it is giving me an error and I think it is because of the id, I don't seem to find a way for it not to give me an error. Please help me!

 

@isTest
class testmantenimiento{

static testmethod void testmantenimiento(){

Integer size = 1;
List<Mantenimiento_Gastos__c> opp = new List<Mantenimiento_Gastos__c>();
for (Integer i = 0; i < size; i++)  {
   Mantenimiento_Gastos__c o = new Mantenimiento_Gastos__c();
   o.Propiedad__c = 'a0IQ0000000o962';
   opp.add(o);
}
insert opp;  
}
}



Hello! I have been trying to do a Test Method for the following Trigger but everything I do doesn't seem to work. Please help me in any way you can. Here is my Trigger:

 

trigger duplicamant on Mantenimiento_Gastos__c(before insert){
    for(Mantenimiento_Gastos__c c : Trigger.new)
        {
Mantenimiento_Gastos__c[] contacts=[Select id,Propiedad__c from Mantenimiento_Gastos__c Where Propiedad__c=:c.Propiedad__c];
            if (contacts.size()>0) 
             {
            c.Propiedad__c.addError('The number is already registered!');
              }
          }
}

I have tried the following Test Method but it is giving me an error and I think it is because of the id, I don't seem to find a way for it not to give me an error. Please help me!

 

@isTest
class testmantenimiento{

static testmethod void testmantenimiento(){

Integer size = 1;
List<Mantenimiento_Gastos__c> opp = new List<Mantenimiento_Gastos__c>();
for (Integer i = 0; i < size; i++)  {
   Mantenimiento_Gastos__c o = new Mantenimiento_Gastos__c();
   o.Propiedad__c = 'a0IQ0000000o962';
   opp.add(o);
}
insert opp;  
}
}