You need to sign in to do that
Don't have an account?

How to test this trigger? is giving me unexpected token: @
This is a "trigger" that doesn't allow duplicate values of the field Pre_Impreso 003_001 _c
I tried to test this trigger but isn't allowing me to save because of the @isTest
error: unexpected token: @
Also I changed the version of the trigger but still doesn't work
my trigger test (I don't know why isn't recognizing the @isTest)
trigger MensajeValorDuplicado on Factura__c (before insert, before update) { Map<Decimal, Factura__c> facMap = new Map<Decimal, Factura__c>(); For (Factura__c facturarecoleta : System.Trigger.new) { If ((facturarecoleta.Pre_impreso_003_001__c != null) && (System.Trigger.isInsert)){ facMap.put(facturarecoleta.Pre_impreso_003_001__c, facturarecoleta); } } For (Factura__c facturarecoleta : [SELECT Id, Name, Sucursal__c, Pre_impreso_003_001__c FROM Factura__c WHERE Pre_impreso_003_001__c IN :facMap.KeySet()]){ If (facturarecoleta.Sucursal__c=='Maker Recoleta'){ Factura__c newFactura = facMap.get(facturarecoleta.Pre_impreso_003_001__c); newFactura.addError('El #Pre-Impreso(003-001) ingresado ya fue utilizado en la Factura', false); } } }
I tried to test this trigger but isn't allowing me to save because of the @isTest
error: unexpected token: @
Also I changed the version of the trigger but still doesn't work
my trigger test (I don't know why isn't recognizing the @isTest)
@isTest private class MensajeValorDuplicadoTest { static testMethod void TestMensajeValorDuplicado() { Test.startTest(); Map<Decimal, Factura__c> facMap = new Map<Decimal, Factura__c>(); Factura__c facturas = new Factura__c(); //insert factura; For (Factura__c factura: [Select ID, Name, Pre_Impreso_003_001__c, Sucursal__c, Caja__c From Factura__c WHERE Pre_impreso_003_001__c IN :facMap.KeySet()]){ System.debug('factura name' + factura.Name); System.assertEquals('factura name',factura.name); System.debug(555555 + factura.Pre_Impreso_003_001__c); System.assertEquals(55555,factura.Pre_Impreso_003_001__c); System.debug('Caja 1' + factura.Caja__c); System.assertEquals('Caja 1',factura.Caja__c); System.debug('Maker Centro' + factura.Sucursal__c); System.assertEquals('Maker Centro',factura.Sucursal__c); } Test.stopTest(); } }
so my test has to be inside my trigger?
or inside what class?
if it is like this, is giving me an error: Only static top-level class methods can be test methods
74% normal without a test, then I created the test with apex class, I put both to deploy but still I got 74% of coverage code. So maybe, I am connecting wrong the trigger with his apex test class.