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

Oppurtunity Trigger

I'm trying to write a trigger for an oppurtunity. I want to create a new custom object record (that will include some information from that oppurtunity) every time a new oppurtunity is created.
The problem is that I don't know how to refer to the current oppertunity fields...
What I wrote till now is:
trigger try_trigger on Opportunity (after update) {
Class_Registration__c ClassReg = new Class_Registration__c (

insert ClassReg;

 where I wrote XXXXXXXX I want to put a field from the oppertunity that invoked the trigger. Is it possible?
Thanks for your help,
Yeah, sure this is possible.

See the documentation here.

Please check out the documentation.

Here is what you are to do.  Since you want the trigger to create the object on creation of the oppty, you should use the after insert event, not after update.  Triggers are bulk, meaning that you need to iterate over a set as shown below in the for loop. is the set of new records, in your case opptys.

trigger try_trigger on Opportunity(after insert) {
for (Opportunity o : {
        // Iterate over each sObject
        Class_Registration__c ClassReg = new Class_Registration__c 
         ( Registration_Notes__c=o.Name);