0

I insert a record with the following trigger and debug information.

I can't see it on it's tab, but I can get access to it if I take the Bitacora ID and put it directly into my browser.

How can I solve this?

for (Event evento : Trigger.new) {
    Bitacora__c bitacora = new Bitacora__c(Descripcion__c=evento.Description,
                                               FechaHoraFin__c=evento.EndDateTime,
                                               OwnerId=evento.OwnerId,
                                               FechaHoraInicio__c=evento.StartDateTime,
                                               TipoActividad__c=evento.Subject,
                                               IdEvento__c=evento.id);
    system.debug('********** id: ' + bitacora.id);
    system.debug('********** bitacora: ' + bitacora);
    insert bitacora;
}

Debug Log:

11:54:56.144 (144393635)|USER_DEBUG|[13]|DEBUG|********** id: null
11:54:56.144 (144492371)|USER_DEBUG|[14]|DEBUG|********** bitacora: Bitacora__c:{Descripcion__c=null, OwnerId=005F0000003Yzl3IAC, FechaHoraInicio__c=2014-06-06 17:00:00, TipoActividad__c=debug 2, FechaHoraFin__c=2014-06-07 18:00:00, IdEvento__c=00UF000000Ju5A5MAJ}
3
  • 1
    Your record should definitely exist in Salesforce but you need to bulkify your code and remove that ifstatement
    – dphil
    Jun 6, 2014 at 15:30
  • 2
    Do you have a tab for the record? Where are you expecting to see it? What if you take the Bitacora ID and put it directly into your browser?
    – sfdcfox
    Jun 6, 2014 at 16:08
  • Bulkify in this context means removing the insert DML from within the for loop. See developer.salesforce.com/page/Apex_Code_Best_Practices #2.
    – Ray Dehler
    Jun 6, 2014 at 16:10

1 Answer 1

1

1)You are debugging before you insert the record:

 system.debug('********** id: ' + bitacora.id);
    system.debug('********** bitacora: ' + bitacora);
    insert bitacora;

Do this instead:

insert bitacora;
system.debug('********** id: ' + bitacora.id);
system.debug('********** bitacora: ' + bitacora);

2) If I were you I would create a view in the bitacora object where createddate = today and createdby = your this way you can see the record count go up if the trigger successfully inserts a record.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .