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
Brendon ConleyBrendon Conley 

How do you create a specific number of cases per month?

The use case here is that we utilize writers who need to push a certain amount of content for various clients each month. We're trying to implement cases for the first time so we have some visibility on the status of the work, but there's a lot of clients and there's a LOT of articles that need to be done per client. Each of the clients may be on a different plan, and each plan would be given a specific number of articles to be written. 
  • Check a specific field in an "account" record
  • If the field is one value, the customer needs a certain number of cases opened for them each month with due dates spread out throughout the month. If the field is a different value, they need a different number of cases opened for them each month.
Searches have led me to "timed workflows" but I haven't been able to make headway yet. My company is using Lightning but I'm fairly confident this scenario won't work in it without using the API. I do have access to the classic version. I'd love to be able to do this fully in the SF UI but can code some script if necessary.

How would you approach this?
VamsiVamsi
Hi,

This requires coding and something like below would work for you.

Create a trigger on Account as below 
trigger CreateMultipleCases on Account (After insert,After update) 
{
	 Set<ID> AccountId = new Set<ID>();
   set<ID> UpdateAccountID = new set<ID>();
   for(Account a : trigger.new)
   {
	  if( Trigger.IsAfter && Trigger.IsInsert && a.NumberofLocations__c!= null && a.NumberofLocations__c > 0)
	  {
	     AccountId.add(a.id);
	  }else if(Trigger.IsAfter && Trigger.IsUpdate && a.NumberofLocations__c!= null && a.NumberofLocations__c > 0 && Trigger.oldmap.get(a.id).NumberofLocations__c!=a.NumberofLocations__c) // Here NumberofLocations__c specifies the number of cases that needs to be created. Create a number field on Account to specify the number of cases and replace all NumberofLocations__c with that field.
	  {
		UpdateAccountID.add(a.id);
	  }
   }
   
   if(AccountId.size()>0)
   {
     AccCreateMultipleCases.CreateCase(AccountId);
   }
   
   if(UpdateAccountID.size()>0)
   {
    AccCreateMultipleCases.CreateCase(UpdateAccountID);
   }
}

Create a Apex class as below 
 
public class AccCreateMultipleCases 
{
	public static void CreateCase(set<ID> AccIds)
	{
     list <Case> FinalCaseList = new list<Case>();
      
    for(account acc : [select NumberofLocations__c from Account where ID IN :AccIds])
    {     
           for(Integer i=1;i<=acc.NumberofLocations__c;i++)
           {
               Case ca = new Case(status = 'New',AccountID = acc.Id,Priority = 'High');// you can specify the remaining case fields as required.
               FinalCaseList.add(ca);
           }
    }
	
    List<Database.saveResult> FinalCaseInsertList = Database.insert(FinalCaseList,false);
    }
}

 Hope this helps ...!!!

Note: Above code requires thorough validations ....!!!

Please mark as best answer if the above code helps ...!!!