You need to sign in to do that
Don't have an account?
Dovid B
assignment rules not firing on lead insert using Sites VF page
I have a contact form written in VF using Sites. However it seems when the lead is inserted, the owner assignment rules are not firing and the owner just remains the website.
I have a number of rules set up in Lead Assignment Rules and would like to use them. Is there something I am missing?
Here's the controller code:
global with sharing class ContactFormController { Lead lead; CampaignMember cmember; String submittedPageURL = 'http://asc-net.force.com/cms__Main?name=contact_confirm'; global Lead getLead() { if(lead == null) lead = new Lead(firstname='First Name...',lastname='Last Name...'); return lead; } global CampaignMember getCmember() { if(cmember == null) cmember = new CampaignMember(status='Responded'); return cmember; } global PageReference save() { //System.debug('Made it to save!'); insert lead; //System.debug('Inserted Lead'); if(cmember.CampaignId != null) { cmember.LeadId = lead.id; insert cmember; //System.debug('Inserted Campaign Member'); } PageReference submittedPage = new PageReference(submittedPageURL); submittedPage.setRedirect(true); //System.debug('Redirecting and we are outta here!'); return submittedPage; } }
You will need to add some extra lines to your code to set the assignment rule.
If you want to assign the default assignment rule following set of lines will help you
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
Lead l = new Lead(company='ABC', lastname='Smith');
l.setOptions(dmo);
insert l;
If you want to apply any specific rule you can use following code
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.assignmentRuleId= '01QD0000000EqAn';
Lead l = new Lead(company='ABC', lastname='Smith');
l.setOptions(dmo);
insert l;
I hope this helps.
All Answers
You will need to add some extra lines to your code to set the assignment rule.
If you want to assign the default assignment rule following set of lines will help you
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
Lead l = new Lead(company='ABC', lastname='Smith');
l.setOptions(dmo);
insert l;
If you want to apply any specific rule you can use following code
Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.assignmentRuleId= '01QD0000000EqAn';
Lead l = new Lead(company='ABC', lastname='Smith');
l.setOptions(dmo);
insert l;
I hope this helps.
thanks! That did the trick!
This the same as for Case