{"id":566,"date":"2017-02-09T11:36:00","date_gmt":"2017-02-09T17:36:00","guid":{"rendered":"https:\/\/blog.felineflock.com\/?p=566"},"modified":"2024-01-01T11:39:02","modified_gmt":"2024-01-01T17:39:02","slug":"how-to-get-a-lead-assigned-to-a-random-person-in-salesforce","status":"publish","type":"post","link":"https:\/\/blog.felineflock.com\/index.php\/2017\/02\/09\/how-to-get-a-lead-assigned-to-a-random-person-in-salesforce\/","title":{"rendered":"How to get a lead assigned to a random person in Salesforce"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"793\" height=\"720\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/dices.jpeg\" alt=\"\" class=\"wp-image-568\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/dices.jpeg 793w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/dices-300x272.jpeg 300w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/dices-768x697.jpeg 768w\" sizes=\"auto, (max-width: 793px) 100vw, 793px\" \/><\/figure>\n\n\n\n<p>There isn&#8217;t a function to get a random number in the context of Salesforce formulas. The only way I know of is to base it on time. Specifically, the seconds part of the time.<\/p>\n\n\n\n<p>If you create a formula with the expression below, you will get a random number (*) between 0 and 59, which is from the seconds of the time that the record was created:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>VALUE( MID( TEXT( CreatedDate ), 18, 2 ) )<\/p>\n<\/blockquote>\n\n\n\n<p><\/p>\n\n\n\n<p>You can apply the MOD function to bring that number down to other ranges.<\/p>\n\n\n\n<p>The expression below will result in a random 0 or 1:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>MOD( VALUE( MID( TEXT( CreatedDate ), 18, 2 ) ), 2 )<\/p>\n<\/blockquote>\n\n\n\n<p><\/p>\n\n\n\n<p>You can then use that formula field to drive a lead assignment rule:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Rule Entries: <\/p>\n\n\n\n<p>if Lead : Random Number EQUALS 1 Assign To User1 <\/p>\n\n\n\n<p>if Lead : Random Number EQUALS 2 Assign To User2 <\/p>\n\n\n\n<p>if Lead : Random Number EQUALS 3 Assign To User3<\/p>\n<\/blockquote>\n\n\n\n<p>And if you want to assign one of 2 values randomically via a workflow field update, then the formula could be written as follows:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>CASE( MOD( VALUE( MID( TEXT( CreatedDate ), 18, 2 ) ), 2 ) , 0, &#8220;First Choice&#8221;, 1, &#8220;Second Choice&#8221;, &#8220;Error&#8221; )<\/p>\n<\/blockquote>\n\n\n\n<p><del>&#8211; &#8211;<\/del><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">(*)&nbsp;<strong>Is it really a random number?<\/strong><\/h3>\n\n\n\n<p>Are we are safe to assume that the second when a person created the record is actually random?<\/p>\n\n\n\n<p>The seconds in the record creation date\/time are not strictly random. If you have an integration process creating these records, then many of them will be created at the same second and you will not be able to use the expression.<\/p>\n\n\n\n<p>The alternative below may be better &#8211; it shifts the source of randomness to the second the record is queried &#8211; but then the problem will be: if you query more than one record at a time, it will generate the same &#8220;random&#8221; number for all records.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>VALUE( MID( TEXT( NOW() ), 18, 2 ) )<\/p>\n<\/blockquote>\n\n\n\n<p>So what to do? You can sum the second from both CreatedDate and NOW() and you will probably get a better number between 0 and 118:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>VALUE( MID( TEXT( NOW() ), 18, 2 ) ) + VALUE( MID( TEXT( CreatedDate ), 18, 2 ) )<\/p>\n<\/blockquote>\n\n\n\n<p>Or even this smaller expression to get a number between 0 and 99. The subtraction of date\/time fields results in a number in the format &lt;number of days>.&lt;fraction of a day> So this formula is taking 2 digits from the fraction as the source of randomness.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>VALUE( MID( TEXT( NOW() &#8211; CreatedDate ), 6, 2 ) )<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>There isn&#8217;t a function to get a random number in the context of Salesforce formulas. The only way I know of is to base it on time. Specifically, the seconds part of the time. If you create a formula with the expression below, you will get a random number (*) between 0 and 59, which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-566","post","type-post","status-publish","format-standard","hentry","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/comments?post=566"}],"version-history":[{"count":2,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/566\/revisions"}],"predecessor-version":[{"id":570,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/566\/revisions\/570"}],"wp:attachment":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media?parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/categories?post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/tags?post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}