+ Start a Discussion

trigger of creation record


I haven't written an Apex trigger before, so I'm looking for an example of a trigger that will create a record.

I've got a 2 objects : Mission , Project  

Each time a mission or a projet is created or modificated , I'd like to create a record in my custom object  Jobs.

millions thanks!!!

Jia HuJia Hu
check the post:
How to write a trigger in Apex

if you want to insert some records, use "insert" instead,

the doc is here:



Trigger is at object level.

If you want to write trigger on 2 objects then you have to write 2 triggers separately for each object.

First go through the documentation provide by SF about Triggers so that you will have get some idea about triggers

Find the below link




And find the below code which will be guide to write trigger might be helpful to know the Body and how write trigger.

I have written on Mission Object(not tested). You do the same for Project Object


trigger TR_task on Mission (before insert) 
    set<id> lsttasks = new set<id>();
    List<Mission> lstMission = new set<Mission>();
    List<jobs> lstjobs = new list<jobs>();
    lstMission = Trigger.new()
     For(Mission mis :lstMission )
        jobs jb = new jobs(name = mis.name,......like as you reqired) 

      upsert lstjobs


Mark it as Resolved if the reply helps you.