• Michael Carrier
  • NEWBIE
  • 10 Points
  • Member since 2016
  • 24 Hour Fitness

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hello All,
I am very new to writing code and am having a hard time getting assignment rules to fire once a lead is entered into a visualforce page. I ahve found a few examples out there where folks suggest DML code, however I am not sure if I can put on the Visual Force page or if I should create a seperate class (or if I should create a trigger to fire after the lead is created). Salesfroce suggested I create a class and gave me the following code:
public Lead sample {get; set;}
    public AssignLeadsUsingAssignmentRules(ApexPages.StandardController controller) 
               {
        sample = new Lead();        
    }
   public void LeadAssign()     {             
        Database.DMLOptions dmo = new Database.DMLOptions();             
        dmo.assignmentRuleHeader.assignmentRuleId= '01Q0m0000006EH9';                     
        sample.setOptions(dmo); 
        insert sample; 
    } 
Below is my Visual Force page:
<apex:page standardController="Lead" showHeader="false" sidebar="true" extensions="AssignLeadsUsingAssignmentRules">
<apex:form >
     <apex:pageBlock title="Lead Information">
       <apex:pageBlockSection >
           <apex:pageBlockSection >
           <apex:inputField value="{!Lead.Lead_Referred_By__c}" required="True"/> 
           <apex:inputField value="{!Lead.Club2__c}" required="True"/>
           <apex:inputField value="{!Lead.company}" required="True"/>
           <apex:inputField value="{!Lead.NumberOfEmployees}" required="True"/>
           <apex:inputField value="{!Lead.FirstName}" required="True"/>
           <apex:inputField value="{!Lead.LastName}" required="True"/>
           <apex:inputField value="{!Lead.Phone}" required="True"/>
           <apex:inputField value="{!Lead.Email}" required="False"/>
           <apex:inputField value="{!Lead.Title}" required="True"/>
           <apex:inputField value="{!Lead.Additional_Comments__c}"/>
           </apex:pageBlockSection>
       </apex:pageBlockSection>  
            <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
                </apex:pageBlockButtons>
</apex:pageBlock>
 </apex:form>
</apex:page>

My issue is that the CLub2__c field is used to dirive a Territory filed on the lead, the assignemnt rules fires off of the Territory field. Any code, tips , suggestions, prayers are greatly appreciated.
We created a button to update pricing on our opportunity, and it works, however if there is existing pricing the button will throw an unexpected number error. Is there somthing I can add to the beginning of the code to clear out the fields before it updates? Any help would be greatly appreciated. Here is the code below:

{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")}
var opptyObj = "{!Opportunity.Market_and_Package__c}";
if(opptyObj === "Basic-B"){
  var oppToUpdate = new sforce.SObject("Opportunity");
oppToUpdate.id = "{!Opportunity.Id}";
 oppToUpdate.pricefield1__c = 29.99;
sforce.connection.update([oppToUpdate]);
    window.location.reload();
} else
{
 alert("Pricing Not available for Opp");
}
Hello All,
I am very new to writing code and am having a hard time getting assignment rules to fire once a lead is entered into a visualforce page. I ahve found a few examples out there where folks suggest DML code, however I am not sure if I can put on the Visual Force page or if I should create a seperate class (or if I should create a trigger to fire after the lead is created). Salesfroce suggested I create a class and gave me the following code:
public Lead sample {get; set;}
    public AssignLeadsUsingAssignmentRules(ApexPages.StandardController controller) 
               {
        sample = new Lead();        
    }
   public void LeadAssign()     {             
        Database.DMLOptions dmo = new Database.DMLOptions();             
        dmo.assignmentRuleHeader.assignmentRuleId= '01Q0m0000006EH9';                     
        sample.setOptions(dmo); 
        insert sample; 
    } 
Below is my Visual Force page:
<apex:page standardController="Lead" showHeader="false" sidebar="true" extensions="AssignLeadsUsingAssignmentRules">
<apex:form >
     <apex:pageBlock title="Lead Information">
       <apex:pageBlockSection >
           <apex:pageBlockSection >
           <apex:inputField value="{!Lead.Lead_Referred_By__c}" required="True"/> 
           <apex:inputField value="{!Lead.Club2__c}" required="True"/>
           <apex:inputField value="{!Lead.company}" required="True"/>
           <apex:inputField value="{!Lead.NumberOfEmployees}" required="True"/>
           <apex:inputField value="{!Lead.FirstName}" required="True"/>
           <apex:inputField value="{!Lead.LastName}" required="True"/>
           <apex:inputField value="{!Lead.Phone}" required="True"/>
           <apex:inputField value="{!Lead.Email}" required="False"/>
           <apex:inputField value="{!Lead.Title}" required="True"/>
           <apex:inputField value="{!Lead.Additional_Comments__c}"/>
           </apex:pageBlockSection>
       </apex:pageBlockSection>  
            <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save"/>
                </apex:pageBlockButtons>
</apex:pageBlock>
 </apex:form>
</apex:page>

My issue is that the CLub2__c field is used to dirive a Territory filed on the lead, the assignemnt rules fires off of the Territory field. Any code, tips , suggestions, prayers are greatly appreciated.
By using Process Builder can we update records in child object?

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; 
        
    }
    
}