+ Start a Discussion
Marco_MaltesiMarco_Maltesi 

trigger,

hello (salut tous le monde),

please can anyone help me, i need to correct this trigger.the idea is to create a new record in the evenement object if a contact is created and have a specif value in a picklist field.

trigger Mytrigger onContact (beforeinsert) {

List<Contact> lstContact = newset<Contact>();

List<Ev_nement__c> lstevents = newlist<Ev_nement__c>();

lstContact = Trigger.new();

 

For(Contactcon :lstContact )

{

if (Contact.Type_contrat__c == 'CDI')

 

Ev_nement__c EV = newEv_nement__c (Contact__c=con.ID,Date_de_cr_ation__c=system.today(),Type__c='Embauche') ;

lstevents.add(Ev);

}

upsertlstjobs;

}

 

 

the error message is that EV don t exists!!!

Suresh RaghuramSuresh Raghuram

write system.debuglog after this statement

Ev_nement__c EV = newEv_nement__c (Contact__c=con.ID,Date_de_cr_ation__c=system.today(),Type__c='Embauche') ;

 

one more thing what is the upsert lstjobs;

 

what is the lstjobs;

I mean u did nt pass any thing to the lstjobs but you are updating it

also make a change as follows and try it

Ev_nement__c Ev = new Ev_nement__c ();

Ev.Contact__c=con.ID;

Ev.Date_de_cr_ation__c=system.today();

Ev.Type__c='Embauche' ;

lstevents.add(Ev);

 

If this answer your question make this as a solution





Marco_MaltesiMarco_Maltesi

hi,

i try this code but there is an error ; "varaible does not exists 'EV.Contact__c' 

trigger

Mytrigger onContact (beforeinsert) {

List<Contact> lstContact = newset<Contact>();

List<Ev_nement__c> lstevents = newlist<Ev_nement__c>();

lstContact = Trigger.new();

 

For(Contactcon :lstContact )

{

if (Contact.Type_contrat__c == 'CDI')

 

       Ev_nement__c EV = newEv_nement__c();

       EV.Contact__c = con.ID;

       EV.Date_de_cr_ation__c=system.today();

       EV.Type__c='Embauche';

       lstevents.add(EV);

        {System.debug();}

       upsertlstevents;

}

}

 

 

Thanks a lot for your help!!!

Suresh RaghuramSuresh Raghuram

hi Marco I think we are not getting the values into the

lstContact = Trigger.new System.debug("***************MyValues of Contact" +lstContact);

 

Goto the debug logs and open the log file and check can u able to collect the values in the lstContact I think we can get some idea from that

 

Any way you can change your code like this.

 

trigger Mytrigger on Contact (beforeinsert) {

 

List<Ev_nement__c> lstevents = newlist<Ev_nement__c>();

//lstContact = Trigger.new();

 

For(Contact con : Trigger. New )

{

if (con.Type_contrat__c == 'CDI')

 

       Ev_nement__c EV = new Ev_nement__c();

       EV.Contact__c = con.ID;

       EV.Date_de_cr_ation__c=system.today();

       EV.Type__c='Embauche';

       lstevents.add(EV);

       

       upsert lstevents;

}

}

 

Ev.Contact__c might be a look up on event so check how to update a lookup field

If you have any problem post it iam always eager to help u