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
Liz MartinezLiz Martinez 

How to create a list of payment receipts based in two dates

Hi everyone:

I'm new to Salesforce and I'm trying to generate a list of payment receipts, I have the start date and the end date of the contract period, but between these dates I need to generate the payment receipts for every 15 days. 

For example, in a contract from February 7th to April 14th I need to create the receipts for:
- February 22th
- March 7th
- March 21th
- April 4th
- April 14th 

These receipts have to include a field of status (paid or not paid)

My final objective is to generate a report to show the next receipt that the company needs to pay and the last receipt paid

Any help appreciated

Thank you 
binaryLadybinaryLady
Hi Liz, I am imagining that your receipts are records on a custom object called Receipt. From what you are saying I understand that you would want to generate all of the receipts when the contract is created. These receipts would be child objects of the Contract. You could achieve this behavior using the Process Builder which would trigger on contract creation. You will need to use a little formula magic to get the dates right. Learn about Process Builder here: https://help.salesforce.com/HTViewHelpDoc?id=process_overview.htm
Liz MartinezLiz Martinez
Hi binaryLady, in fact I don't have an object Receipt, I only have the object Contract and yes I would want to generate all of the receipts when the contract is created. I will read about Process Builder

Thank you for your answer
Richard Jimenez 9Richard Jimenez 9
Hi Liz,

Two options -
  1. Create a single (i.e. the next) payment receipt automatically as contract is started or one is paid
  2. Mass create payment receipt records for the full contract length
1. Create a single (i.e. the next) payment receipt automatically as contract is started or one is paid. This can be achieved with process builder (configuration), to add a single record when either the contract is started or the latest payment receipt is is paid. By doing this, you only have next unpaid payment receipt records created for your contracts which will conserve your data storage, and you dont need to think about removing redundant reciepts if the contract is cancelled or ended earlier. You could have a formula field to calculate how many receipts you will have and roll-up how many have been paid, you can then calculate the payments outstanding. The downside is that you wont be able to see a schedule of all the unpaid payment receipts in a matrix report for the full length of each contract (because the records will not exist until the latest one is paid).

2. Mass create payment receipt records for the full contract length. This will require some code. Assuming you are using the Contract object and you are using the standard start and end date fields. You can add a custom picklist/number field to store the payment receipt days. Create a 'Payment Receipt' custom object, with a Master-detail field to the Contract Object and add the status field (picklist). You will need a trigger on the Contract object that will manage the payment receipt records (on insert and update). It will require a bit of logic to manage the creation of the payment receipt records (apex code required unfortunatley)

You should also think about what business rules you have to manage the process, e.g.
  1. Can the contract dates or reciept interval days be changed? If they can, then what should happen to any existing unpaid or paid receipts?
  2. If the contract is cancelled should the unpaid reciepts be deleted?
  3. What the maximum length of a contract, what is the maximum number of receipts you could create? Have a rule to stop people accidently putting excessive contract lengths and creating hundreds of records!
  4. Do you need to generate payment receipts for any existing/in flight contracts (i.e. is a datafix requried)
  5. .... I'm sure you can think of more!
Hope that gives you something to think about!

Richard.
binaryLadybinaryLady
Hi Liz, you will want to setup your custom object Receipt as a child/related list of the parent object Contract. Good luck!
Richard Jimenez 9Richard Jimenez 9
Hi Liz,

Quick update - With some process builder cleverness you could get it to fire recursiveley after each receipt is created to then create the next one if the receipt date + 15 < the contract end date and incrementing the receipt date. I'd check if there were any platform and performance limitations in doing it this way first, based on the number of records you think you will create. However, it may be a bit trickier to add it more complex business logic around managing these records - i.e. deleting and recalcuting if dates are changed etc (if thats a requirement).

Good luck!
Richard.