function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Greg-inficienceGreg-inficience 

Standard extension controller: variable input not taken into account

I created a VisualForce Page if order to rapidly create leads from contacts. The purpose is for instance to enable to select all the contacts who attended a webinar and create leads for each of them in just a few clicks.
The page uses an extension controller to the contact standard controller.

In the extension controller, I created a variable called "CampaignToAppendID" which purpose is for the user to input the campaign to which the new leads have to be added.This variable is used in the VisualForce Page as a  droplist so gthat the users can select the campaign. Displaying and populating the droplist works OK. But the variable apparently does not change when the user selects different values for the droplist. The Debug log shows that the setCampaignToAppendID class setter never gets triggered. What I am missing?

 

VisualForce page Code is below:

 

<apex:page standardController="contact" extensions="MassCreateLeadsFromContactsControllerExt" recordSetVar="contacts">
<script>
function confirmCancel() {
var isCancel = confirm("Are you sure you wish to cancel?");
if (isCancel) return true;
return false;
}
</script>

<apex:sectionHeader title="Mass Create Leads from Contacts"></apex:sectionHeader>
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockButtons >
<apex:commandButton value="Create leads" action="{!CreateLeadsFromContacts}" immediate="true"/>
<apex:commandButton value="Cancel" action="{!Cancel}" onclick="return confirmCancel()" immediate="true"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Creation parameters" collapsible="false" columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel for="CampaignToAppendID">Attach resulting leads to campaign:</apex:outputLabel>
<apex:selectlist value="{!CampaignToAppendID}" multiselect="false" size="1" required="True">
<apex:selectOptions value="{!CampaignsToAppend}"/>
</apex:selectlist>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel rendered="!{CampaignAlert}"><h1>Please enter a campaign</h1></apex:outputLabel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection collapsible="false" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel ><h1>Each contact in the list below will be copied to a lead.</h1></apex:outputLabel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Contacts to be processed">
<apex:dataTable value="{!Contacts}" var="TheContact">
<apex:column title="Name" >
<apex:outputText value="{!TheContact.name}"/>
</apex:column>
<apex:column title="Title" >
<apex:outputText value="{!TheContact.Title}"/>
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

and controller code is here:

 

public class MassCreateLeadsFromContactsControllerExt {

string CampaignToAppendID;
public final list<contact> TheContacts;
boolean CampaignAlert = False;

public MassCreateLeadsFromContactsControllerExt(ApexPages.StandardSetController stdController) {
System.LoggingLevel level = LoggingLevel.FINEST;
system.debug ('Starting extension controller');
TheContacts = (list<Contact>)stdController.getrecords();
system.debug ('TheContacts: '+Thecontacts.size());
system.debug ('CampaignAlert: '+CampaignAlert);
if (Thecontacts.size() > 0) {
system.debug ('First Contact: '+TheContacts[0].ID);
} else {
system.debug ('No Contact in list');
}
}

public List<SelectOption> getCampaignsToAppend() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('0','-- No Campaign --'));
for (campaign c : [SELECT id, name FROM campaign where isactive = TRUE order by name]) {
options.add(new SelectOption(c.id,c.name));
}
system.debug('getCampaignsToAppend - Campaigns To Append drop list: '+options.size());
return options;
}

public pagereference CreateLeadsFromContacts() {
if (CampaignToAppendID != '0') {
Campaign TheCampaign = ([SELECT id, name FROM campaign where id = :CampaignToAppendID]);
system.debug ('Campaign to append: '+CampaignToAppendID+' - '+TheCampaign.name);
system.debug ('Nb of leads to create: '+TheContacts.size());
for (contact TheCurrentContact : TheContacts ) {
system.debug ('Contact to process: '+TheCurrentContact.ID);
}
system.debug('END OF PROCESSING');
return page.CLFC_result;
}
else {
CampaignAlert = True;
system.debug('No campaign selected');
system.debug ('CampaignAlert: '+CampaignAlert);
return null;
}
}

public string getCampaignToAppendID() {
if(CampaignToAppendID == null) {
CampaignToAppendID = '0';
}
system.debug('getCampaignToAppend - CampaignToAppendID: '+CampaignToAppendID);
return CampaignToAppendID;
}

public void setCampaignToAppendID(string c) {
CampaignToAppendID = c;
system.debug('setCampaignToAppendID - CampaignToAppendID: '+CampaignToAppendID);
}

public boolean getCampaignAlert() {
if (CampaignAlert == null) {
CampaignAlert = False;
}
system.debug('getCampaignAlert - CampaignAlert: '+CampaignAlert);
return CampaignAlert;
}

public void setCampaignAlert(Boolean b) {
CampaignAlert = b;
system.debug('setCampaignAlert - CampaignAlert: '+CampaignAlert);
}
}

 

 Thanks for your help

 

Message Edited by Greg-inficience on 06-15-2009 02:38 AM
Best Answer chosen by Admin (Salesforce Developers) 
Greg-inficienceGreg-inficience

I finally found out: this happens when the "immediate" attibute is set to true in the commandbutton. When set to false, the setter trigger allright.

 

The doc is unclear, though: is reads:

 

A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.

All Answers

wesnoltewesnolte

Hey

 

I might be grasping at straws here but try changing

 

string CampaignToAppendID;

 

to

 

private string CampaignToAppendID; 

 

 

Greg-inficienceGreg-inficience
Just tried it and it does not change the behavior. The setter is not triggered, as per the debug logs.
Greg-inficienceGreg-inficience

I finally found out: this happens when the "immediate" attibute is set to true in the commandbutton. When set to false, the setter trigger allright.

 

The doc is unclear, though: is reads:

 

A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.

This was selected as the best answer