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
Achilles21Achilles21 

Sending VF Page Field Values to Trigger

Hi All ,

 

I am trying to create an apex trigger in which i have to manipulate some of the values that are being passed by the user on the VF page .

 

The scenario is , I've to book seats on a flight . Now the user will enter Travel Date and a flight no (unique) for object Flight__c . I am trying to fetch values for the no. of booked seats from another object Booking__c on the same date for the same flight that the user has entered . so I've written query in trigger

 

res=(List<Booking__c>)[select b.booked_seats__c from booking__c b where
               b.travel_date__c = flight.travel_date__c AND
               b.flight_no__c = flight.flight_no__c]

 

Here, as you can see I need Flight.travel_Date__c ( that is being passed by the user ) ! But im not being able to find a way .

 

FYI , My Booking and Flight have a look up relationship .

 

Please guide me thrugh this .

 

Let me know if this is perplexing or you need more info.

Best Answer chosen by Admin (Salesforce Developers) 
MiddhaMiddha

One way is to Save the user input in a record and query it back in trigger so that you can use that again.

 

But if you have a same piece of code which has to be called from a trigger and from VF page, you can write it in an APEX class and call those methods from your trigger OR from your VF as and when required, which would be more advisable.