function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mathias_KMathias_K 

How to get with a trigger an ID of an Object that is generated by the trigger

Hello, 
i hope you can help me.

I have a trigger on a the Event Object , that creates a Visit Report (Customized Object) after generating a Event. 

At the moment the trigger generate a visit report but i want to write back the id of the generated visit report into the event. 

can i handle this in only one trigger? 

Thx 4 help
Best Answer chosen by Mathias_K
Deepankar ChandaDeepankar Chanda
Hello Mathias,

First I hope you are doing this before insert of Event Object.

To get the id of inserted Visit Report records:
trigger on event Create visitreport__c (before insert){

list<visitreport_c> visitreports = new list<visitreport_c>();

// bulkify business logic start 
...
...
// bulkify business logic end 

insert visitreports;

//but you have to handle it bulk update as well
for(visitreport_c vr:visitreports){
  system.debug('Id:'+vr.id);
   
}


}

I hope it will help you.