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
Cloud_BKCloud_BK 

First Trigger

Hi All,

 

I am a noobie when it comes to triggers and I am trying to write my first one.

 

Here is the scenario:

 

I have a custom object called Registrants__c which has a lookup field to the standard SF object of product.

 

I would like to populate the Course_Price__c field on the Registrants object with the list price for the selected product.  I believe I need to call the "Price_Book_Entry" object but am unsure of how to procede.

 

Also, I would like this to occur after insert and after update.

 

Any help would be much appreciated, thanks!

 

Brian

Cloud_BKCloud_BK

Here is what I have started.  Appologies for any obvious errors

 

trigger AutoPopulateCoursePrice on cld_Registrants__c (after insert, after update) {

List<PricebookEntry> pb = new List<PricebookEntry>() ;
pb = [Select Product2Id From PricebookEntry] ;

List<PricebookEntry> cp = new List<PricebookEntry>() ;
cp = [Select UnitPrice From PricebookEntry] ;


//This is the part I am not sure of: I want the Unit Price "cp" to be populated in the Course_Selected__c field.//
if(pb = Course_Selected__c){
upsert cp;
}

}