I have a custom object called Charter with a lookup relationship with accounts. I have created an apex trigger in opportunity to create Charter records. I am not getting any errors with the trigger but the records are also not created.

Does anyone knows why is this happening or is what I am trying to do even possible?

  • Triggers can create objects. Best to post your code. – Keith C Aug 1 '14 at 15:35
  • sorry, but there is no code. – Christian Deckert Aug 1 '14 at 15:38

Can you post your code?

Anyway here is some pseudo code:

trigger YOURTRIGGER on Opportunity (after insert) // trigger after insert
    List<Charter__c> charters = new List<Charter__c>(); // list of charters
    for(Opportunity o : trigger.new) // for loop
        charters.add(new Charter__c(Account__c = o.AccountId)); // create new record and add the record to a list

    insert charters; // insert new records
  • Thank you Christian and Keith. I managed to make it work. I was missing the insert statement. – Yom130 Aug 1 '14 at 16:06
  • Thank you everyone. I was able to get this going but I have a follow up question. How do I get the ID of the record that was just created? – Yom130 Aug 5 '14 at 14:59

This is the answer related to your question :

trigger Con on Opportunity (after insert) {
        contact con1=new contact();
    for(opportunity o:trigger.new)


            insert con1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.