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

Insert multiple records via trigger

I have follwing trigger

trigger USP on OpportunityLineItem (after insert) {

 List<Task> task = new List<Task>();
    List<OpportunityLineItem> newOpportunityLineItem = new List<OpportunityLineItem>();
    for (Integer i = 0; i <; i++) 
                            if ([i].Quantity > 0)

                task.add(new Task(           
                                                      WhatId =[i].OpportunityId,
                                                     OwnerId =[i].Ocid__c,
                                                     Subject='new task'+[i].Product_Name__c,
                                                     ReminderDAteTime = System.Now()

    insert task;


 What it does is that when new product is added to opportunity it creates a task to our support team to insure they follow up on the product and publish it, it  is working fine however, what i need is


when a product is entered with multiple quantities for example 2 or 3  etc.

i want to created that number of tasks one for each product, not sure how it is possible without forcing our sales reps to enter one line item for every product but it would be nearly impossible to do


any help greatly appreciated