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
Sudhir NarayanswamySudhir Narayanswamy 

Pass Record ID from trigger

Hi, 

   How to get the record id from trigger this need to be mapped in another object after that records is inserted. 

   Below is the code written but not able to achive to get return id

   
trigger AssetHPSyncTrg on Asset_Stage__c (Before Insert, Before Update, After Insert) {

list<String> HPEOppId = new list<String>();
list<String> HPESerialNumber = new list<String>();
list<String> OrderStatus = new list<String>();
list<String> Ordertype = new list<String>();
list<String> HPEOrderNumber = new list<String>();
list<String> HPEQuoteNumber = new list<String>();
list<String> PurchaseDate = new list<String>();
list<String> ShipDate = new list<String>();
list<String> SupportStartDate = new list<String>();
list<String> SupportEndDate = new list<String>();
list<String> InstallAddStreet1 = new list<String>();
list<String> InstallAddStreet2 = new list<String>();
list<String> InstallAddCity = new list<String>();
list<String> InstallAddState = new list<String>();
list<String> InstallAddCountry = new list<String>();
list<String> SLA = new list<String>();
list<String> ContactEmail = new list<String>();
list<String> ContactName = new list<String>();
list<String> AstStageID = new list<String>();

 if(trigger.isBefore && trigger.isInsert){
  for (Asset_Stage__c asts :  Trigger.new)
  {
    HPEOppId.add(asts.HPE_Opportunity_ID__c);    
    HPESerialNumber.add(asts.HPE_Serial_Number__c);
    OrderStatus.add(asts.Order_Status__c);
    Ordertype.add(asts.Order_Type__c);
    HPEOrderNumber.add(asts.HPE_Order_Number__c);
    HPEQuoteNumber.add(asts.HPE_Quote_Number__c);
    PurchaseDate.add(asts.Purchase_Date_HPE_Receive_Date__c);
    ShipDate.add(asts.Order_Ship_Date__c);
    SupportStartDate.add(asts.Support_Start_Date__c);
    SupportEndDate.add(asts.Support_End_Date__c);
    InstallAddStreet1.add(asts.Install_Address_Street1__c);
    InstallAddStreet2.add(asts.Install_Address_Street2__c);
    InstallAddCity.add(asts.Install_Address_City__c);
    InstallAddState.add(asts.Install_Address_State__c);
    InstallAddCountry.add(asts.Install_Address_Country__c); 
    SLA.add(asts.SLA_Support_Level__c);       
    ContactEmail.add(asts.End_Customer_Ship_to_Contact_Email__c);
    ContactName.add(asts.End_Customer_Ship_to_Contact_Name__c);
    AstStageID.add(asts.id);
    asts.Status__c = 'New';
  }
  
   if(HPEOppId!=null && !HPEOppId.isEmpty()){
    AssetHPSyncTrgCls.AssetSync(HPEOppId,
                                HPESerialNumber,
                                OrderStatus,
                                Ordertype,
                                HPEOrderNumber,
                                HPEQuoteNumber,
                                ShipDate,
                                PurchaseDate,
                                SupportStartDate,
                                SupportEndDate,
                                InstallAddStreet1,
                                InstallAddStreet2,
                                InstallAddCity,
                                InstallAddState,
                                InstallAddCountry,
                                SLA,
                                ContactEmail,
                                ContactName,
                                AstStageID                                
                                );
   }
   
 }  
  
  
  
  
}

Please suggest. 

Thanks
Sudhir
Asif Ali MAsif Ali M
Hi Sudhir,

in beforeInsert trigger the records are being prepared to save to DB. Record Ids are only available after they are saved to database. If your need is to process the records after they are created then change your if statement to this one
if(trigger.isAfter && trigger.isInsert)