[SalesForce] How to change an objects record type after a certain time period? Workflow, Apex, other

I am working on implementing a timed RecordType change in salesforce. I have an object that when created needs to change its RecordType after a certain number of days. The only catch is that if a particular field on the object is filled out then the change should not happen. I am just wondering what would be the best way to go about implementing this. There could potentially be 100,000 of these objects in a worst case scenario and possibly larger.

My initial reaction was to look into the scheduled workflow that would change the record type X number of days after but I am unsure if this workflow will turn off when the criteria changes. My second thought was to use scheduled apex and have a segment of code run every night and change the RecordTypes but I am worried about the scalability of this with large volumes of records.

Does anyone have a recommendation of an apporach to tackle this problem? I would appreciate any input or advice on a direction to take. Thanks

Best Answer

Time based workflow is perfect for this. The workflow turns off automatically when the criteria changes. Scheduled Apex will also work, but isn't needed. Batch Apex would ensure you can scale to large data volumes.

From Help & Training

Time-dependent actions remain in the workflow queue only as long as the workflow rule criteria are still valid. If a record no longer matches the rule criteria, Salesforce removes the time-dependent actions queued for that record.

For example, an opportunity workflow rule may specify:

  • A criteria set to “Opportunity: Status not equals to Closed Won, Closed Lost.”
  • An associated time-dependent action with a time trigger set to seven days before the opportunity close date.

If a record that matches the criteria is created on July 1st and the Close Date is set to July 30th, the time-dependent action is scheduled for July 23rd. However, if the opportunity is set to “Closed Won” or “Closed Lost” before July 23rd, the time-dependent action is automatically removed from the queue.

Related Topic