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 

Extension controller with list: issue when campaign members

Hi all,

 

I created a VF page that is an extension controller for contacts. It is called from a contact view and the purpose is to enable people to create leads from a full list of contacts without having to go through an export/import.

 

If I create a contact view with criteria such as "Name starts with 'M'", and click the button, it works fine.

 

If I create a contact view using a "Filter By Campaign" criteria, I Get a error message: 

LastName, title FROM Contact WHERE ((CampaignId = '70180000000F7kn')) ^ ERROR at Row:1:Column:78 No such column 'CampaignId' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

 

Meaning that the controller does not receive the list of contacts but the criteria from the view. How Can I handle this?

 

Thanks in advance for your help.

 

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>:smileywink: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