1

Is there a way to create a queue for each Id that is being passed to be processed? I am getting errors when mass updating records with GridBuddy.

 trigger Reporting_Data on Forecasting_Data__c(after insert, after update) {

        List<Report_Data__c> data = new List<Report_Data__c>();

        for (Forecasting_Data__c f: Trigger.new) {
            Integer i = Integer.valueOf(f.Fiscal_Year__c);
            Integer rl = Integer.valueOf(f.Related_List_Count__c);
            Date d = Date.newInstance(i, rl + 1, 1);
            if (f.Related_List_Count__c < 12) {
                data.add(new Report_Data__c(Name = f.Name + ' ' + (rl + 1),
                    Forecasting_Data__c = f.Id,
                    Date__c = d));
            }
            insert data;
        }
    }
  • What is the error message that you get? Do you get it for every ID or just some of them? – Jagular Sep 23 '14 at 17:13
0

You don't mention what specific error you're receiving, but I'll take a guess that your error stems from the fact that you've got a DML statement within a for loop.

It appears that your code might just have the insert statement in the wrong location.

trigger Reporting_Data on Forecasting_Data__c(after insert, after update) {

    List<Report_Data__c> data = new List<Report_Data__c>();

    for (Forecasting_Data__c f: Trigger.new) {
        Integer i = Integer.valueOf(f.Fiscal_Year__c);
        Integer rl = Integer.valueOf(f.Related_List_Count__c);
        Date d = Date.newInstance(i, rl + 1, 1);
        if (f.Related_List_Count__c < 12) {
            data.add(new Report_Data__c(Name = f.Name + ' ' + (rl + 1),
                Forecasting_Data__c = f.Id,
                Date__c = d));
        }
        // insert data;
    }

    if (!data.isEmpty()) {
        insert data;
    }
}
| improve this answer | |
  • Feel free to click the "accept" checkmark below the voting arrows on the left of my answer. By the way, welcome to the community! – Mark Pond Sep 23 '14 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.