• Flashheart
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hi all, 

 

am new to Sfdc / apex - so forgive the naivety - I've scoured the boards and other material but cant see how/whether the following can be done.

 

Can a trigger be added to an object (Bookings) to create a record in another object (Expense) as a "after insert" trigger
where there is also a "before insert" trigger active ?

 

I have 3 custom objects:

 

Bookings - the capture of a hotel reservation details with a related contact record, payments etc. etc.
Expense - to capture the associated costs of all bookings
Materials - a reference table of materials used for the hotel

 

The first trigger is an "after insert" trigger on Bookings that needs to create a corresponding record in Expense object

 

The second trigger is a "before insert" trigger that does 2 things:

1. takes output of a numeric formula field: Expense.total_nights__c (for example here lets call this "p")

2. Applies (p) * each record type in Materials where Materials.Service__c = Booking

 

Firstly is this possible?, secondly, forgive my naivety but is there any reference code available that does this (or something similar)  or would anyone be brave enought to suggest what this needs to look like?

 

I've had a go and am continually trying but stumblingn in the dark so thought it a good idea to post for help here

 

thanks!