• jordy moliere
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hello,

I created a VF Page to create new leads, the new lead must be related to an existing Campaign. On the VF Page I want to show the Campaign description. I created a VF Page:
 
<apex:page showheader="false" sidebar="false" standardStylesheets="false" controller="CreateLead" tabStyle="Lead">
  <apex:form>
				  <apex:outputText value="{!Campaign.Description}" escape="false" />
						<apex:pageMessages id="msgs"/>
						<apex:inputfield value="{!Lead.LastName}" html-placeholder="Achternaam" styleClass="store w-full border bg-gray-100 hover:bg-gray-200 focus:bg-gray-200 outline-none px-3 py-2"/>
						<apex:outputtext value=""></apex:outputtext>
						...
						<apex:inputfield value="{!Lead.Email}" html-placeholder="Email adres" styleClass="store w-full border bg-gray-100 hover:bg-gray-200 focus:bg-gray-200 outline-none px-3 py-2"/>
						<apex:outputtext value=""></apex:outputtext>
      <apex:commandButton rerender="msgs" action="{! save }" value="Save"/>
  </apex:form>
</apex:page>
And an Apex page to get the Campaign description and to save the Lead and set a relation with the Campaign:
 
public class CreateLead {


    public Lead getLead() {
        return lead;
    }
    
				public Lead lead {get;set;}

				public CreateLead (){
								lead = new Lead();
				}
    
    public PageReference save() {
	    insert lead;

        CampaignMember member = new CampaignMember(
            LeadId = lead.Id,
            CampaignId = '7011r00000'
        );
        insert member; 

        return null;
    }

    private Campaign campaign;

   	public Campaign getCampaign() {
        
        if (campaign == null){                     
	        campaign = [select Name, Description from Campaign where
            id = '7011r00000'];       
        }
        return campaign;
    }


}



This works fine, however I hardcoded the Campaign Id in the Apex class. I want to be able to reuse the Apex class so I want to make the Campaign Id variable. 

How can I pass a Campaign Id from the VF Page to the Apex class when the page is loaded. I found solutions with an additional form on the VF Page that can be used to set the Campaign Id. I would like to define it in the VF Page and make it available in the Apex class when a user loads the page.

Thank you for your help!
  • February 08, 2020
  • Like
  • 0
Hi,

I am using the below formulas in Process Builder.

Salesforce automatically updates "Preferred Phone" picklist depending on which phone number field has a number in it.  So, if the MobilePhone is populated it updates the Preferred phone with Mobile.  If the HomePhone is populated it updates the Preferred phone with Home.  If the WorkPhone is populated it update the Preferred Phone with Work. 

1. Detect Change in Phone Field: Criteria Formula
OR(AND(ISNEW(),OR(NOT(ISBLANK([Contact].HomePhone)), NOT(ISBLANK([Contact].MobilePhone)), NOT(ISBLANK([Contact].npe01__WorkPhone__c)))), 
        ISCHANGED([Contact].HomePhone),
        ISCHANGED([Contact].MobilePhone),
        ISCHANGED([Contact].npe01__WorkPhone__c))

2.  Set Preferred Phone Field: Immediate Action
CASE(
    IF(ISBLANK([Contact].MobilePhone), '0', '1') +
    IF(ISBLANK([Contact].HomePhone),       '0', '1') +
    IF(ISBLANK([Contact].npe01__WorkPhone__c), '0', '1'),
    '100', 'Mobile',
    '010', 'Home',
    '001', 'Work',
NULL
)

This works great. The problem I now need to resolved is that if two or more phones are populated the user is required to select which is the Preferred Phone.

Thanks.