iterate an object array and create multiple records with the value from it

Viewed 209

I have an Object Array scheduleTable__c, with the below fields: Product | Description | Jan | Feb | Mar | ... right now, it will create one record and filling all the fields accordingly. I would like to change this by creating one record for each month inside the Array. I guess the right way to do so is to create another array by iterating over the current array and insert that value.

Replace my function

@AuraEnabled
    public static List<scheduleTable__c> createPSs(List<scheduleTable__c> psList){
        insert psList;
        return psList;
    }

by that

@AuraEnabled
    public static List<scheduleTable__c> createPSs(List<scheduleTable__c> psList){
        
       String [] arraySC = new List<String>();

        for(Integer i = 2; i < psList.size(); i++){
            arraySC.push(psList[0]);
            arraySC.push(psList[1]);
            arraySC.push(psList[i]);
        }
        insert arraySC;
        return arraySC;
    }

It doesn't seems to like the fact that it is an array of an object and I am creating a String Array... I then replaced the array with this but still not able to make it work...

List<scheduleTable__c> arraySC = new List<scheduleTable__c>();

any help will be appreciated.

0 Answers
Related