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
SFAdmin5SFAdmin5 

bet you can't figure this one out...Assign Account records EVENLY to 3 users at the end of the day

I need to automatically assign (as record owner) account records at the end of every day (or early in the morning tomorrow) to 3 end users, if the account records created today meet certain criteria.

 

for example.  let's say the record assignment should occur at 1 am tomorrow or right after midnight, if the account was

 

-created today

-of priority (custom field) "high"

-of type="partner". 

 

accounts NOT meeting those criteria should be ignored.

 

so...let's say today 40 records were created today meeting those criteria above. 

 

now what i need, is for those 40 accounts to be distributed as evenly as possible to 3 SF users as record owner

 

obviously, 40/3=13.333 records per user, which is a problem.  

 

i don't think (though I sincerely hope) i can use workflow/timed field updates to do this, because the goal is to EVENLY or as evenly as possible distribute accounts meeting the above criteria to these 3 users.   

 

this automated job needs to occur once a day at the end of the day or early in the morning of the following day.  doesn't matter.  the point is that we need to look at account records created today meeting a few criteria, and auto update the account owner for those records evenly among three users.

 

please.  help.  thanks a lot guys.

sfdcfoxsfdcfox

If I were a betting man, I would calmly say, "You're about to lose a bet."

 

This is actually a rather trivial question. In fact, I have several thoughts on this.

 

Here's some starters:

 

1) Create a custom object or setting. Have this track the number of times an account has been assigned to a user. Load this into the bulk processing class, then process records that meet the critera; increment counters as you go.

2) Create a custom object or setting. Track the last user assigned an account. Proceed with round-robin assignment starting with the user after the last user assigned a record.

3) Choose a random user each day, and proceed in a round-robin style system.

4) Choose a random user to be assigned each account assigned.

 

The random suggestions seem odd, except that you must remember that the law of probability states that all things being equal, a coin will land heads up 50% of the time when flipped, and so it is that a random user in three will come up 33.33...% of the time. But for a small sacrifice of database storage, you can go with options 1 or 2, and achieve perfect assignments; users that are shorted one day will be given more the next, ensuring that accounts are perfectly distributed as time goes on.

 

Now, once you've chosen a method, the only bit left is to write a Batch Apex piece. It should query for all accounts that meet the criteria, implement the option chosen above, and update those records in a random or round-robin manner. Finally, to make the code live, you'd run a small Execute Anonymous bit to schedule the class to run nightly at midnight, or whatever time is convenient for you. It will run within a 1 hour deviation each night (under normal server load).

Julian LeahJulian Leah
I do agree that Choosing the right online sites are crucially important, that’s why after a lot of research I decided on the website betboo (https://betbooyeniadres1.win/), which has been amazing for me and I loved it.
 
hd sdhd sd
UFABETWINS has a user-friendly interface that makes it easy for both new and experienced users to navigate and place bets. The platform is designed to be intuitive and straightforward on ufabet (https://www.ufabetwins.info/), ensuring a smooth and enjoyable betting experience.