You need to sign in to do that
Don't have an account?
linda b
Create Case on parent object in for loop
I would like to write a scheduled Apex class which checks for certain conditions on a custom object, and if they are true, create a case on the master-detail parent object, here is my code so far:
global class CaseGenerator implements Schedulable { global void execute(SchedulableContext ctx) { createInvoiceCase(); } public void createInvoiceCase() { List<Billing_Unit__c> invoiceCases = new List<Billing_Unit__c>(); invoiceCases = [SELECT Id, Contract__r.Id FROM Billing_Unit__c WHERE Invoicing_Date__c = TODAY AND Unlimited__c = TRUE]; for(Billing_Unit__c bgut : invoiceCases) { // create case related to Contract__r.id here Case cseobj = new Case (subject= 'Rechnung erstellen'; Contract__c=Contract__r) (???) } update invoiceCases; } }I don't know how to create the case on the parent object in the for loop, any help/tips would be greatly appreciated! :)
Try this code and let me know if it works for you. Thanks
Niraj
All Answers
Try this code and let me know if it works for you. Thanks
Niraj