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
acnetacnet 

Campaign Member Mass Task Creator 1.1

Hi,

 

I have installed the Campaign Member Mass Task Creator 1.1 app from the AppExchange and the functionality works well apart from when using the filter criteria, to filter the returned results.

 

We only want to filter on Member Status (i.e. Sent / Responded) and Type (Lead / Contact or Both), however within the Apex Code this is using other criteria e.g. Zip, Post Code and therefore returning inaccurate results.

 

Does anyone know how I can disable this or amend the code so it only searches purely based on whether this is a lead, contact (or both), and the member status??

 

Many thanks in advance.

guest1231231guest1231231

Not knowing what the business requirements for this are, I think you may be able to accomplish this by using campaign member workflow rules and avoid the maintenance required with apex code.   If you need to access contact/lead fields that are not currently in the campaign member object you can always create a custom campaign member formula field that returns those values.

 

Salesforce.com usually recommends we use their built in functionality first before writing apex.

acnetacnet

Basically within the Apex Class "CampaignMemberFollowUpController", it uses filter criteria to support campaigns where there are over 1000 campaign members.

 

The only criteria that we want to use is the type (I.e. Lead, Contact or Both) and the member status (i.e. Sent, Responded etc). However, when we currently use the filter, this brings back incomplete results as it evaluates lead/contact fields such as Zip, Employees etc and we do not always have these fields populated because at this stage they may be unknown.

 

Therefore, what I want the application to do is only filter on 'Type' and 'Member Status'. Is this possible and how would I achieve this...?

 

Thanks in advance

 

 

 

// update V1.1: filter criteria in order to support more than 1000 CMs
    //methods for Filter Status Field
    static Schema.DescribeFieldResult FS = CampaignMember.Status.getDescribe();
    static List<Schema.PicklistEntry> FSP = FS.getPicklistValues();  
    private String startFilterStatus = FSP[0].getValue();

    public List<SelectOption> getFilterStatusItems() {

        List<SelectOption> options = new List<SelectOption>();
        for(Integer i = 0;i < FSP.size();i++ ){
            options.add(new SelectOption(FSP[i].getValue(),FSP[i].getLabel()));
        }
        return options;
    }
    public String selectedFilterStatus {get; set;}
    
    //methods for Filter Type Field
    public List<SelectOption> getFilterTypeItems() {

        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Both','Both'));
        options.add(new SelectOption('Lead','Lead'));
        options.add(new SelectOption('Contact','Contact'));
        return options;
    }
    public String selectedFilterType{get; set;}
    
    // Filter Title, No.Employees and zip code fields
     public String Title {get; set;}
     public Integer EmployeesFrom {get; set;}
     public Integer EmployeesTo {get; set;}
     public String Zip {get; set;}   
     //part strings for query
    private String filterTitle;
    private String filterEmployees;
    private String filterZip;
    
    public void gofilter(){
        //build Title filter string
        //if(Title.length()>0){
        if(Title != null){
             if(selectedFilterType == 'both'){
                filterTitle =' AND (Contact.Title LIKE \''+Title+'%\' OR Lead.Title LIKE \''+Title+'%\')';
            }
            if(selectedFilterType =='Lead'){
                filterTitle =' AND Lead.Title LIKE \''+Title+'%\'';
            }
            if(selectedFilterType =='Contact'){
                filterTitle =' AND Contact.Title LIKE \''+Title+'%\'';
            }
        }else{
            filterTitle =' ';
        }
        //build Zip filter string
        //if(Zip.length()>0){
        if(Zip != null){
             if(selectedFilterType =='Both'){
                filterZip =' AND (Lead.PostalCode LIKE \''+Zip+'%\' OR Contact.MailingPostalCode LIKE \''+Zip+'%\')';
            }
            if(selectedFilterType =='Lead'){
                filterZip =' AND Lead.PostalCode LIKE \''+Zip+'%\'';
            }
            if(selectedFilterType =='Contact'){
                filterZip =' AND Contact.MailingPostalCode LIKE \''+Zip+'%\'';
            }
        }else{
            filterZip =' ';
        }
        //build Employees# filer string
        if(EmployeesFrom != 0 && EmployeesFrom != null){
            if(EmployeesTo != 0 && EmployeesTo != null){
                if(selectedFilterType =='Both'){
                    filterEmployees =' AND ((Contact.Account.NumberOfEmployees < '+EmployeesTo+'  AND  Contact.Account.NumberOfEmployees >'+EmployeesFrom+') OR (Lead.NumberOfEmployees < '+EmployeesTo+' AND Lead.NumberOfEmployees > '+EmployeesFrom+'))';
                }
                if(selectedFilterType =='Lead'){
                    filterEmployees =' AND (Lead.NumberOfEmployees < '+EmployeesTo+' AND Lead.NumberOfEmployees > '+EmployeesFrom+')';
                }
                if(selectedFilterType =='Contact'){
                    filterEmployees =' AND (Contact.Account.NumberOfEmployees < '+EmployeesTo+'  AND  Contact.Account.NumberOfEmployees >'+EmployeesFrom+')';
                }
            }else{
                if(selectedFilterType =='Both'){
                    filterEmployees =' AND (Contact.Account.NumberOfEmployees >'+EmployeesFrom+' OR Lead.NumberOfEmployees > '+EmployeesFrom+')';
                }
                if(selectedFilterType =='Lead'){
                    filterEmployees =' AND Lead.NumberOfEmployees > '+EmployeesFrom;
                }
                if(selectedFilterType =='Contact'){
                    filterEmployees =' AND  Contact.Account.NumberOfEmployees >'+EmployeesFrom;
                }
            }
        }else{
            if(EmployeesTo != 0 && EmployeesTo != null){
                if(selectedFilterType =='Both'){
                    filterEmployees =' AND (Contact.Account.NumberOfEmployees < '+EmployeesTo+' OR Lead.NumberOfEmployees < '+EmployeesTo+')';
                }
                if(selectedFilterType =='Lead'){
                    filterEmployees =' AND Lead.NumberOfEmployees < '+EmployeesTo;
                }
                if(selectedFilterType =='Contact'){
                    filterEmployees =' AND Contact.Account.NumberOfEmployees < '+EmployeesTo;
                }
            }else{
                filterEmployees =' ';
            }
        }
        myquery = selectedFilterType;
        loadCampaignMemberList();
    }


    // dynamic queries
    public List<CampaignMember> queryCM(String querycase){
        //default List
        List<CampaignMember> CMList = new List<CampaignMember>();
        String query;
        if(querycase == 'default'){
            query = 'Select Id, LeadId, Lead.Company, Lead.Email, Lead.FirstName, Lead.LastName, Lead.OwnerId, Lead.Owner.IsActive, Lead.City, ContactId, Contact.Account.Name, Contact.Email, Contact.FirstName, Contact.LastName, Contact.OwnerId, Contact.Owner.IsActive, Contact.MailingCity, Contact.MailingPostalCode, Contact.Account.NumberOfEmployees, Contact.Title, Lead.PostalCode, Lead.NumberOfEmployees, Lead.Title, Status from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+' ORDER BY Status , Contact.LastName limit 1000';
        }
        if(querycase == 'both'){
            query = 'Select Id, LeadId, Lead.Company, Lead.Email, Lead.FirstName, Lead.LastName, Lead.OwnerId, Lead.Owner.IsActive, Lead.City, ContactId, Contact.Account.Name, Contact.Email, Contact.FirstName, Contact.LastName, Contact.OwnerId, Contact.Owner.IsActive, Contact.MailingCity, Contact.MailingPostalCode, Contact.Account.NumberOfEmployees, Contact.Title, Lead.PostalCode, Lead.NumberOfEmployees, Lead.Title, Status from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+filterZip+filterTitle+filterEmployees+' AND Status='+'\''+selectedFilterStatus+'\''+' ORDER BY Lead.LastName , Contact.LastName limit 1000';
        }
        if(querycase == 'Lead'){
            query = 'Select Id, LeadId, ContactId, Lead.Company, Lead.Email, Lead.FirstName, Lead.LastName, Lead.OwnerId, Lead.Owner.IsActive, Lead.City,  Lead.PostalCode, Lead.NumberOfEmployees, Lead.Title, Status from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+' AND ContactId=null'+filterZip+filterTitle+filterEmployees+' AND Status='+'\''+selectedFilterStatus+'\''+' ORDER BY Lead.LastName limit 1000';
        }
        if(querycase == 'Contact'){
            query = 'Select Id, ContactId, LeadId, Contact.Account.Name, Contact.Email, Contact.FirstName, Contact.LastName, Contact.OwnerId, Contact.Owner.IsActive, Contact.MailingCity, Contact.MailingPostalCode, Contact.Account.NumberOfEmployees, Contact.Title, Status from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+' AND LeadId=null'+filterZip+filterTitle+filterEmployees+' AND Status='+'\''+selectedFilterStatus+'\''+' ORDER BY Contact.LastName limit 1000';
        }
        CMList = Database.query(query);
        return CMList;
    }
    public Integer countCMresults(String querycase){
        Integer queryCount = 0;
        String query;
        if(querycase =='default'){
            query = 'Select count() from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\' limit 2000';
        }
        if(querycase =='both'){
            query = 'Select count() from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+filterZip+filterTitle+filterEmployees+' AND Status='+'\''+selectedFilterStatus+'\' limit 2000';
        }
        if(querycase =='Lead'){
            query = 'Select count() from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+' AND ContactId=null'+filterZip+filterTitle+filterEmployees+' AND Status='+'\''+selectedFilterStatus+'\' limit 2000';
        }
        if(querycase =='Contact'){
            query = 'Select count() from CampaignMember WHERE CampaignId ='+'\''+SelectedCampaign+'\''+' AND LeadId=null'+filterZip+filterTitle+filterEmployees+' AND Status='+'\''+selectedFilterStatus+'\''+' limit 2000';
        }
        queryCount = Database.countQuery(query);
        return queryCount;
    }
}