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
Rama Rao MylaRama Rao Myla 

Assign records based on user availability

First  scenario.
Suppose there is a custom object, and we have 4 users. When a first record is created we have to assign the record to user1, second record to user2 and so on ...when the fifth record is created we have to assign to user1 again and iterative.
Second Scenario:
We have to assign the record when the user is available only just like omni channel...how can we implement this using apex. When i Say available it means the user is active in salesforce but he might be on leave not to accept records on that particular day...he might be away from desk which means he is not available to accept the record.
 
Gokula KrishnanGokula Krishnan
Hi Rama,

You need to use trigger for your Custom object. 

1st -> You can Query your custom object and find out latest record created was assign to which user, and from that user you can continue your assigning for the upcoming records. 
And also you need to create a Custom setting to add your User IDs in sequence way. So that, you can pick the User for the next assignment record.

2nd -> To check the user is available or not, you need to create a Available flag(Checkbox) in User Object or in Custom Object where you have set User sequence. That way you can check your User Available and you need to update the user is available or not. 

FYI, Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_customsettings.htm
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm


Thanks!!!