0

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?

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

2 Answers 2

2

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
}
2
  • Thank you Christian and Keith. I managed to make it work. I was missing the insert statement.
    – Yom130
    Aug 1, 2014 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, 2014 at 14:59
1

This is the answer related to your question :

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

        con1.accountid=o.accountid;
        con1.lastname=o.name;

    }
            insert con1;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .