You need to sign in to do that
Don't have an account?
Cesar Ramirez Vasquez005391619375684564
Trigger not firing before insert ?? HELP
Hi i have created a trigger that checks before inserting a record of type Factura__c, if the master-relationship field (Empresa_Cliente__c) exist, and if it dont the trigger create a new one with the value contained in the field Empresa_Cliente__c.
The master relationship is between Factura__c (custom object) and Account. But when i try to save a record the trigger doesnt fire and i keep receiving the salesforce validation error (Error: No matches found.) in that field. Any suggestions this is my trigger :
trigger insertAcc on Factura__c (before insert) {
System.debug(Logginglevel.ERROR , ' ::::::: Empresa Cliente :::::::::::::' + trigger.New[0].Empresa_Cliente__c) ;
if(Trigger.isBefore)
{
if(Trigger.isInsert)
{
List<Account> a = [select name, CodigoNAF__c from account where CodigoNAF__c = :trigger.New[0].Empresa_Cliente__c];
System.debug(Logginglevel.ERROR , ' ::::::: List :::::::::::::' + a) ;
if (a == null){
Account acc = new Account();
acc.Name = trigger.New[0].Empresa_Cliente__c;
acc.CodigoNAF__c = trigger.New[0].Empresa_Cliente__c;
insert (acc);
System.debug(Logginglevel.ERROR , ' ::::::: acc :::::::::::::' + acc) ;
}
}
}
}
The trigger is not firing when i try to save a record it just keep throwing me an error in the master-relationship field (Error:Error: No matches found) . Remember the value i put in the field doesnt exist that is the point of the trigger, create a new Account with the value provided in Empresa_Cliente__c and then save the new Factura__c record without errors.
The master relationship is between Factura__c (custom object) and Account. But when i try to save a record the trigger doesnt fire and i keep receiving the salesforce validation error (Error: No matches found.) in that field. Any suggestions this is my trigger :
trigger insertAcc on Factura__c (before insert) {
System.debug(Logginglevel.ERROR , ' ::::::: Empresa Cliente :::::::::::::' + trigger.New[0].Empresa_Cliente__c) ;
if(Trigger.isBefore)
{
if(Trigger.isInsert)
{
List<Account> a = [select name, CodigoNAF__c from account where CodigoNAF__c = :trigger.New[0].Empresa_Cliente__c];
System.debug(Logginglevel.ERROR , ' ::::::: List :::::::::::::' + a) ;
if (a == null){
Account acc = new Account();
acc.Name = trigger.New[0].Empresa_Cliente__c;
acc.CodigoNAF__c = trigger.New[0].Empresa_Cliente__c;
insert (acc);
System.debug(Logginglevel.ERROR , ' ::::::: acc :::::::::::::' + acc) ;
}
}
}
}
The trigger is not firing when i try to save a record it just keep throwing me an error in the master-relationship field (Error:Error: No matches found) . Remember the value i put in the field doesnt exist that is the point of the trigger, create a new Account with the value provided in Empresa_Cliente__c and then save the new Factura__c record without errors.
//if(if (a == null) \
use
if(a.size()==0
you are having master detail relationship between account and factura. but while saving a new record, are you specifying the masterfield correctly? you cannot save a child record without specifying values in master field.
i hope the query should be like below if CodigoNAF__c is not a ID field.
List<Account> a = [select name, CodigoNAF__c from account where id = :trigger.New[0].Empresa_Cliente__c];
:trigger.New[0].Empresa_Cliente__c ---- this field will have ID of relatedAccount.
-- you are checking if this field in account equals :trigger.New[0].Empresa_Cliente__c .
What is the value the field CodigoNAF__ will contain?????