+ Start a Discussion
sf11sf11 

Adding multiple records in a way similar to add campaign members features

Hi folks,

I am new to VF. I am trying to create a VF page very similar to add campaign members functionality where one can select multiple contacts and attach them to campaign in one step.

 

Here is my use case,

1- I have a custom object (myObject__c) and

2- I would like users to click a button on myObject page layout .

3- This button will show a list of account records based on a simple query, with a checkbox (similar to enhanced list)

4- User will select one or more displayed account records by clicking checkbox and will click done.

5- The selected account Ids will be saved in a custom object (RelatedAcct__c).

 

Can we create "add campaign members" like fucntionality using VF page ?

 

Thanks! 

jkucerajkucera

Hmm-to make a button that leverages the custom object related list, I believe you need a list controller which will get the checked people for use in the button.  I'm not sure you can access a custom object list controller where campaign member is the target as campaign members don't have a list controller (ie-list views). 

 

I know you can't create a button in the Campaign Member related list due to this problem, but you might be able to create a button to add to the custom object enhanced lists (easier than creating a whole new VF list).

 

btw-if the goal is to add accounts to campaigns, I just created an app that makes this easier by leveraging 1 primary contact (dummy contact) for each account, which can be used for segmentation.  Let me know and I can pass it along.

 

 

sf11sf11

Thanks John for the reply.

 

My goal is to attach multiple accounts in one step to one custom object (myObject__c) record. Basically, I am looking for a functionality very similar to add campaign members feature but not for campaign object. My objects which I am trying to relate are custom object and the account object. 

jkucerajkucera

Check out StandardSetController in the apex guide on how to make the list controller.  In your VF page, you can set the page action to the desired method.  

 

http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

Here's a good example of how to create a button that runs visualforce.  You'd add the list controller details to this example to extend it to a list view.

 

http://sfdc.arrowpointe.com/2009/01/08/invoke-apex-from-a-custom-button-using-a-visualforce-page/

dlimierodlimiero

I'd be interested in the app you mentioned that adds accounts to campaigns.

 

You can email me at dlimiero AT stadia DOT cc

civiccivic

Hi,

 

I need to add subscription members to a campaign and as the subscription is a custom object salesforce do not give an button to add to campaign on custom reports,

can you send me the app which will give me something to work on at my email address thesale.2009@gmail.com

I appreciate ur help in advance. 

Fiona QuickFiona Quick
@civic I have that exact same use case, did you ever get an answer?
cdunwoodiecdunwoodie
I am looking to acheive the same result. I have a button which I've added to my Custom Object which then grabs all of the selected records and displays those selected records. The next step is what i'm having trouble with and that is grabbing the list of campaigns - showing that list and then being able to add the custom object records ContactIds to the campaign as members.

I feel as though if I could only get this list of campaigs to show here, that I'd be able to grab the informatiom I need to write the code to add them.

Here is my controller:
 
public with sharing class MerchantLeadController {
    private final Merchant_Lead__c merchantLead;
    private final Campaign campaignsList;

    public MerchantLeadController(ApexPages.StandardSetController controller) {

        //merchantLead = [SELECT Id, Name, Contact__c FROM Merchant_Lead__c
        //WHERE Id = :ApexPages.currentPage().getParameters().get('id')];

        List<Merchant_Lead__c> mlId = (List<Merchant_Lead__c>) controller.getSelected();
        List<Merchant_Lead__c> merchantLead = [SELECT id, Contact__c FROM Merchant_Lead__c WHERE id IN :mlId];

        List<Campaign> campaignsList = [SELECT Name FROM Campaign WHERE IsActive = true];

    }

    public Merchant_Lead__c getMerchantLead() {
        return merchantLead;
    }

    public Campaign getCampaign() {
        return campaignsList;
    }

    public PageReference save() {
        update merchantLead;
        return null;
    }
}

I'm not 100% clear on how to structure it to get what im looking for....I can reference the !campaign in my Visualforce page but the contents of the query are not showing.  Here is my VF page:
 
<apex:page standardController="Merchant_Lead__c" tabStyle="Merchant_Lead__c" recordSetVar="Merchant_Lead__c" Extensions="MerchantLeadController" >
    <style>
        #col1,#col2{width:100%;display:inline-block;valign:top;}
    </style>
    <apex:form >
        <div id="col1">
            <apex:pageblock title="Campaign List Management">
                <apex:pageblockSection title="Merchant Leads">
                   <apex:pageBlockTable value="{!Merchant_Lead__c}" var="a">
                      <apex:column value="{!a.name}"/>
                    </apex:pageBlockTable>
                </apex:pageblockSection>
                <apex:pageblockSection title="Campaigns">
                   <apex:pageBlockTable value="{!Campaign}" var="b">
                      <apex:column value="{!b.name}"/>
                    </apex:pageBlockTable>
                </apex:pageblockSection>
                <apex:pageblockButtons >
                    <apex:commandButton value="Save"/>
                </apex:pageblockButtons>
            </apex:pageblock>
        </div>
        <!--<div id="col2">
            <apex:pageblock title="">
                Show Current Campaigns and their stats?
            </apex:pageblock>
        </div>-->       
    </apex:form>
</apex:page>

User-added image