title: Apex Trigger with custom objects
body: <p>2 custom objects</p>
  
  <blockquote>
    <p>1.Merchandise <br/>
    2.invoice</p>
  </blockquote>
  
  <p>whenever a new merchandise is created an auto invoice has to be created.As am new to apex,please bear with me.Any one please correct my code.</p>
  
  <p>code:</p>
  
  <pre><code>  trigger createinvoice on Merchandise2__c (after insert,after update) {
  
   list&lt;Invoice2__c&gt;line = new list&lt;Invoice2__c&gt;();
  
   for(Merchandise2__c mer:Trigger.new){
      Invoice2__c li = new  Invoice2__c();
      line =[select id from Invoice2__c ];
      li.name = mer.Name;
      li.Status__c='open';
      li.id = mer.id; 
  
      line.add(li);
   }
  
     insert line;
  }
  </code></pre>