Skip to main content

Need assistance in writing a apex trigger to add a list of standard lines to an object

Newbie to salesforce and looking for a way to write a trigger that will create 11 line items for when a field is update. Object is credit request and when this is saved would like multiple credit lines to be added which is also an object. Below is a rough start, but looking for guidance. Picture attached showing what I would like to see after the request is saved and line items automatically created.

trigger TestCreditLinesAdd on Credit_Request__c(after insert){
List < Credit_Lines__c > creditlines = new List < Credit_Lines__c > ();
for (Credit_Request__c cr: trigger.new) {
    creditlines.add(new Credit_Lines__c(.Quantity__c = 0.001));
}
insert creditlines;}

[![enter image description here][1]][1]
Chris
  • 33
  • 7