+ Start a Discussion

Button that creates X number of records based on a variable.

Here's my 'problem' -


I'm not new to programming, but I'm quite new to Salesforce and Apex. My programming experience lies mainly in C++ and VB.


I'd like to create a custom button to replace the standard 'Save' button for a custom object. I have an object that is used as a schedule, each record of this object type is one shift, on one day, for one employee. With over 100 employees, there are a lot of shifts to enter. I find that it will save a LOT of time if users can enter multiple shifts at once, and I see an opportunity for this when the only thing that changes between two shifts is the date by an increment of one day. Lots of employees work in the same department at the same hours, 5 days in a row.


Ideally the button would make these almost identical shifts easier to enter. I'll create a field where the user can enter how many consecutive days the shift will be happening and they'll enter the start date. The default for the field for consecutive days will always "1", so that unless changed, a single record will be created. If the user enters 5, I want 5 total records to be created, the first will start on the "start date" and each record thereafter will start one day later.


Example: Start Date = 10/1/10

Consecutive Days: 3


Should create three records, all the other fields on the record the same, and the dates being 10/1/10, 10/2/10 and 10/3/10.


Like I said, I'm really knew to Salesforce and Apex, so something somewhat detailed would be great. Thanks!



I think you could use Triggers, so you could make an "After Insert" (Your main record) you should read the values and insert the other records.


Check this http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_triggers.htm


Hope It will help you