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
Marco_MaltesiMarco_Maltesi 

trigger of creation record

Hi,

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
http://sfdcdownunder.blogspot.jp/2009/02/how-to-write-trigger-in-apex.html

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

the doc is here:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm
HariDineshHariDinesh

Hi

 

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

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_context_variables.htm

 

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) 
         lstjobs.add(jb); 

       }
      upsert lstjobs
}

 

Mark it as Resolved if the reply helps you.