+ Start a Discussion
Dovid BDovid 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; 
        
    }
    
}

 

Best Answer chosen by Admin (Salesforce Developers) 
_Prasu__Prasu_

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

_Prasu__Prasu_

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.

This was selected as the best answer
Dovid BDovid B

thanks! That did the trick!

Jerry HongJerry Hong

This the same as for Case

Michael CarrierMichael Carrier
I am very new to code devlopment, so please forgive my ignorence. Would the DML lines be entered into the class or the Visual Force page itself? I have tried to include in my class and call as an extention, but I still cannot get the assigment rule to fire.