You need to sign in to do that
Don't have an account?
Lead assignment rules help. Apex trigger maybe?
Hi,
We have a 3rd party webserivce that send leads from our site to SF with Lead Owner already assigned based on some coded rules. We now want to add a level of lead assignment above what this can handle, so I wrote a lead assignment rule and have activated it.
The rules seem to be completley ignored as leads are coming in, but work if a lead is edited and saved ticking the "use active assignmnet rules" checkbox. (i.e the lead assignment crieria works, but its not being triggered)
So I thought a trigger to re-run lead assignment directly after a lead has been created would be the only solution, issue is I have no coding experience (aside from one easy update trigger some guys on here helped with!)
Can anyone help? Or if another solution exists that woudl be great too!
Antony
You could use the AssignmentRuleHeader in an Apex trigger, as in this post:
http://salesforce.stackexchange.com/questions/13651/lead-assignment-rule-in-a-trigger
I assume you'll only want to reassign leads that came from your website, so you'll need a way to check that in your trigger. Assuming these leads have a source of "website", and drawing off of the example above, you could write something like
If you're able to modify the code that is sending the leads from your site to Salesforce, you could set the AssignmentRuleHeader from that end as well.
All Answers
You could use the AssignmentRuleHeader in an Apex trigger, as in this post:
http://salesforce.stackexchange.com/questions/13651/lead-assignment-rule-in-a-trigger
I assume you'll only want to reassign leads that came from your website, so you'll need a way to check that in your trigger. Assuming these leads have a source of "website", and drawing off of the example above, you could write something like
If you're able to modify the code that is sending the leads from your site to Salesforce, you could set the AssignmentRuleHeader from that end as well.
Hi Antony,
When dealing with Web to Lead, when you are setting up your Web to Lead form, you can set the value of the field 'Lead Source' to a specific value. (In fact, you can have this field be a hidden field so no one evens sees it.)
Then, you can set up a Lead Assignment Rule which says if the Lead Source field is equal to 'Web', then have the Lead go to the Lead-Open Queue.
See the links below for further info,
http://developer.force.com/cookbook/recipe/running-case-assignment-rules-from-apex
dmo.assignmentRuleHeader.useDefaultRule = true;
http://salesforce.stackexchange.com/questions/13651/lead-assignment-rule-in-a-trigger
Regards,
Ashish
Only work around we'll need to think about is we have multiple Lead Sources coming form the web so will look at another field to match against in your IF statement.
Antony
Thanks for your time!
That shouldn't be a problem. You can check each of the lead sources in the if statement. Before your for loop, create a set of all the lead sources to check for, like so
Then, your if statement would say
This way, your checking that the lead source matches any one of the lead sources that are coming in from the web.
Thanks again for this. Issue we have with this is we hijack the lead source and populate it with UTM codes based on camapigns the marketing team sends out. I then have triggers that update secondary source fields to map these out to campaigns held on SF.
So I tried thinking of another common field all leads would have, the only one I can think of is CreatedBy, all leads are created by our user: Mr Webservice.
So I attempted to adjust your original code to:
trigger LeadAssnTrigger on Lead (after insert) {
List<Lead> ls = new List<Lead>();
for (Lead l : Trigger.new) {
if (l.CreatedByid= '00520000001AOZ1') {
ls.add(new Lead(id = l.id));
}
}
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule = true;
Database.update(ls, dmo);
}
But get the error:
Error: Compile Error: Field is not writeable: Lead.CreatedById at line 5 column 13
Am I missing something? I didnt think I was trying to write to the CreatedByid, just use it to match in the If statement.
Apologies, I really am a novice at Apex.
Antony
Your if statement is using the assignment operator, =, instead of the equality operator, ==. Try updating it to
I would also recommend querying for the record owner, instead of hardcoding the ID. Before your for loop, you would write
Then you can check that l.createdByid == userId in your if statement.
Maybe I shouldn't be trying triggers at all!!
Antony
The basic idea of the test class is to programmatically create a situation where your trigger will run, and then you check that you got the correct results. In your case, you'll need to use the System.runAs() method, so that you can create leads with the web service user and then check that the lead assignment rule was applied to them. So, you could write something along the lines of the following:
I apologize, I made a mistake in the original test that I gave you. After you insert the lead, you need to query for that lead in order to see all of the data in it. Also, your assertion needs to check OwnerId, instead of CreatedById. So, at the end (replacing your current last line), you can write
Let me know if that solves it!
Cheyne,
First of all really no need for your apologies. You have gone beyond amazing by helping us.
This has fixed it. Test passed and trigger now applied to my live SF instance.
After 2 years of SF, I am now finally understanding the benefits of it being open source and am planning on learning Apex properly (I last programmed when VB was just VB!)
Once again a thousand thanks.
Antony
Not a problem, glad I coud help :)
read book summary book summaries (https://www.ctrlplusread.site)
(https://packagespoint.com/isaimini-hd-movies)
I am also a full stack developer, available for help
https://andrewkdinh.com/
https://www.creditfitnesscoach.com/
Thanks to all of you for assisting
https://c-maxi.com/
https://www.cashlootera.com
Detail Rain Gutters (https://detailraingutters.com/)
Thanks for the post
Microbalance Price from DSC (https://www.dscbalances.com/balances-scales/balances/micro-balances)
MTMIS Islamabad (https://packagespoint.com/mtmis-islamabad-online-vehicle-verification-islamabad-html/)
https://prizebonddraw.pk/
Cats and Dogs Care (http://www.pawcitivity.com/)
At PAMA Shield our goal is to keep your personal space or business sanitized and disinfected. (https://pamashield.com/)
Make money online ( https://verifyanswers.com/what-is-the-best-way-to-earn-money-online/ )
Friendship Quotes ( https://clearqueries.com/friendship-memory-quotes/ )
سيارات للبيع (https://yalla.deals/)
Buy Carry on Travel Bags Online for Man and Women in the UK (https://carryoncollection.com/)
Trickyzilla (https://trickyzilla.com/" target="_blank)
Don't forget to check: (WhyPayFull (https://whypayfull.in/))
Flipkart fake or not fake answers (https://www.whypayfull.in/flipkart-fake-or-not-fake-quiz-answers/)
https://www.whypayfull.in/flipkart-fake-or-not-fake-quiz-answers/
You must some other content as well here Hindi Me tricks (http://hindimetricks.net/) | One Group Links (https://www.onegrouplinks.com/)
(on-18th-august-1945-who-was-reported-to (https://www.indiaawale.com/2020/08/on-18th-august-1945-who-was-reported-to.html))
https://prayaglite.com/prem-mandir-vrindavan-updates/
if you search amazon Quiz let me know (https://99hadi.in/)
if you looking Amazon Quiz Answers (https://99hadi.in/) let me know
The answer is already given by cheyne.
I hope the above code (https://earningkart.in/airtel-puk-code/) will work for you!
Best Regards,
Abhishek
I am very happy to learn the merchandise and having the ability to talk about my own thoughts onto it. I would like to make utilize of this possibility to express that I love this web site. It's a fantastic resource of advice for those jobs. Thank You much better.
thanx admin
it helped me in solving my query Visit too (https://www.karntricks.com/)
jio mobile number check code (https://allussdcodes.com/jio-mobile-number-check/)
jio ussd codes list (https://allussdcodes.com/jio-ussd-codes-lists/)
Berkey's purifications (https://www.purewater4life.com.au/) systems set the standard in gravity water filters around the world Join us to transform your water into the best tasting and purest drinking water possible.
Free Shipping within Australia
1500 Prize Bond List (https://allresult.pk/1500-draw-result/)
Friends anybody wants to get free Amazon prizes by answering the Today's Amazon quiz answers (https://www.mrtechsonu.com/todays-amazon-quiz-answers/)
I am giving u the link for more detail
Also Read this article (https://booksinhindi.com/)
https://bestmicrowavechoice.com/best-microwave-under-100/
GK Quiz (https://www.info.fastread.in/article/gk-quiz-daily/) Affiliate Marketing (https://www.info.fastread.in/what-is-affiliate-marketing-how-to-make-money-with-it/)
great article. also check this article too -
Amazon Super value Days (https://slashdeals.in/buy/amazon-super-value-days-upto-off-sbi-card-dis-Hm8u7)
lipkart tv home appliances sale (https://slashdeals.in/buy/flipkart-tv-home-appliances-monsoon-dhamaka-s-Ir8DC)
Flipkart super saver days (https://slashdeals.in/buy/flipkart-super-saver-days-XhLDj)
Amazon Mobile Saving days (https://slashdeals.in/buy/amazon-mobile-saving-days-dqAoB)
Flipkart Big Saving Days (https://slashdeals.in/buy/flipkart-big-saving-days-sale-dsxLU)
Amazon Literacy Day Quiz (https://indiafine.in/amazon-literacy-day-quiz-answers/)
All Amazon Quiz Answers For https://indiafine.in/
Please visit https://www.techwithkp.com/ for tech & travel related articles.
https://bit.ly/3tTkNee
@isTest
private class TestLeadAssignmentTrigger {
static testMethod void testLeadAssignmentTrigger() {
//This is the web service user that you will insert the lead as
User u = [SELECT Id FROM User WHERE username='webserivceuser'];
//Create the lead sObject
Lead l = new Lead(
LastName='Test'
);
//Insert the lead as the web service user
System.runAs(u) {
insert l;
}
//This is the user that you expect the lead inserted above to be assigned to
User checkUser = [SELECT Id FROM User WHERE username='newuser'];
//Check that the lead was actually reassigned
System.assertEquals(checkUser.Id, l.CreatedById);
}
}
Daily Amazon Quiz Answers Today
Best Gynecologist in jabalpur (https://digiqure.com/app/doctors/search/city/jabalpur/speciality/gynaecologist)
hair transplant in ujjain (https://www.drsoniyahairtransplant.com/)
Teleclinics (https://digiqure.com/teleclinics)
that really helps me a lot. Thanks for all the responses. DigiQure E-Clinic (https://saksham.health/)
Thanks for the answer.
Check amazon quiz answers here. https://bestjobsalert.co.in
Because there are so many different brands currently available, it can be difficult to select the most suitable one. And for this reason, we have published this article.
We have listed some of the leading and Best Chimney brands in India (https://www.kitchenproducts360.com/best-chimney-brands-in-india/). We have tried our best to provide you with all the information that you need to select the best chimney for your cooking space.
wound up here about uttarakhand history and culture
And I do have a couple of questions for you if you tend not
to mind
Take a look at my web-site: <a href="https://ghughuti.org/about-uttarakhand/" rel="dofollow ugc">history of Uttarakhand</a>
wound up here about uttarakhand history and culture
And I do have a couple of questions for you if you tend not
to mind
Take a look at my web-site:
And I do have a couple of questions for you if you tend not
to mind visit the site and to https://ghughuti.org/about-uttarakhand