You need to sign in to do that
Don't have an account?
Sergio Ruiz Barrios 5
Help with a Trigger
Hi All,
I need to create a trigger that flags a checkbox when two fields of different objects have the same value:
I have two objects with a field a want to map:
OBJECT: Radio_Taxi__c----> FIELD: Radio_Taxi_Trip_ID__c
OBJECT: Gastos__c----> FIELD: ID_Radio_Taxi__c
We always create a new Gasto record before a new Radio Taxi Record.
I need to set to TRUE a field (Gasto_creado_en_SF__c) in Radio Taxi Object every time a new Radio Taxi record is created and the Radio_Taxi_Trip_ID__c and ID_Radio_Taxi__c fields have the same value.
Thanks!!!
I need to create a trigger that flags a checkbox when two fields of different objects have the same value:
I have two objects with a field a want to map:
OBJECT: Radio_Taxi__c----> FIELD: Radio_Taxi_Trip_ID__c
OBJECT: Gastos__c----> FIELD: ID_Radio_Taxi__c
We always create a new Gasto record before a new Radio Taxi Record.
I need to set to TRUE a field (Gasto_creado_en_SF__c) in Radio Taxi Object every time a new Radio Taxi record is created and the Radio_Taxi_Trip_ID__c and ID_Radio_Taxi__c fields have the same value.
Thanks!!!
All Answers
trigger on Radio_Taxi__c
{
set<Id> setRadioTxi = new set<id>();
list<Gastos__c> lstGasto = list<Gastos__c>();
for(Radio_Taxi__c obj : trigger.new)
setRadioTxi.add(obj.Radio_Taxi__c);
for(Gastos__c objGas: [select id, ID_Radio_Taxi__c from Gastos__c where ID_Radio_Taxi__c=false and ID_Radio_Taxi__c!=Null and ID_Radio_Taxi__c In : setRadioTxi])
{
objGas.ID_Radio_Taxi__c=true;
lstGasto.add(objGas);
}
if(lstGasto.size()>0)
update lstGasto;
}
Please note above code is not compiled or tested.
I will suggest to check recursive trigger if you habe trigger on Gastos object also.
Please mark answer as best if it helped ny way.
trigger RADIOTAXI on Radio_Taxi__c (after insert)
{
set<Id> setRadioTxi = new set<id>();
List<Gastos__c> lstGasto = List<Gastos__c>();
for(Radio_Taxi__c obj : trigger.new)
setRadioTxi.add(obj.Radio_Taxi__c);
for(Gastos__c objGas: [select id, ID_Radio_Taxi__c from Gastos__c where ID_Radio_Taxi__c=false and ID_Radio_Taxi__c!=Null and ID_Radio_Taxi__c In : setRadioTxi])
{
objGas.ID_Radio_Taxi__c=true;
lstGasto.add(objGas);
}
if(lstGasto.size()>0)
update lstGasto;
}
List<Gastos__c> lstGasto = List<Gastos__c>();
with
List<Gastos__c> lstGasto = new List<Gastos__c>();
Error: Compile Error: Invalid field Radio_Taxi__c for SObject Radio_Taxi__c at line 6 column 26