1

I'm not sure what I'm doing wrong, I created a list, I loop through the list with a query and then I add the query id. When I compile I get:

Incompatible element type Id for collection

I tried changing the list to a set, to a map, tried addall(), put(). Nothing is letting me save.

    public void deleteSchedule(Set<Id> revPipeline)
{
    List<Revenue_Pipeline_Schedule__c> scheduleToDelete = new List<Revenue_Pipeline_Schedule__c>();
    for(Revenue_Pipeline_Schedule__c revPipeSchedule : [SELECT Id,
                                                               Revenue_Pipeline__r.Id
                                                         FROM Revenue_Pipeline_Schedule__c
                                                         WHERE Revenue_Pipeline__r.Id In :revPipeline])
    {
        scheduleToDelete.add(revPipeSchedule.Id);
    }
    try{
        delete scheduleToDelete;        
    }   
    catch (DmlException e){
        // womp womp
    }
}
2

Since you have a List<Revenue_Pipeline_Schedule__c>, you should add individual Revenue_Pipeline_Schedule__c elements.

scheduleToDelete.add(revPipelineSchedule);

Although you don't need to iterate the list at all, frankly. Depending on how you want to handle the DmlException, you don't necessarily even need to cache it.

try
{
    delete [/*query*/];
}
catch (DmlException d)
{
    // DON'T LEAVE THIS BLOCK EMPTY
}

Although often, you want to iterate back through the list in the failure case, in which case you can simply assign it directly from the query.

List<MyObject__c> records = [/*query*/];
try
{
    delete records;
}
catch (DmlException d)
{
    // do something
}
| improve this answer | |

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.