Visualforce displaying information erratically following conversion to person accounts - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Seyi MadariolaSeyi Madariola 

Visualforce displaying information erratically following conversion to person accounts

Hi all, 

I'm relatively new to Visualforce so please be gentle...

I've recently created a public facing website based on Force.com. The website acts like a directory displaying information from my Salesforce org. The functionality is as follows:
  1. Website visitors are able to search the directory based on certain criteria
  2. Website users are able to add their name and email address to my Salesforce org to be added to our mailing list (using web-to-lead)
  3. Webiste visitors are able to add their company information using a web-to-lead form to feature in the directory, upon conversion the company infomration should feature on the website
Point 3, above, worked fine until I enabled Person Accounts in my Salesforce org to enable me to use web-to-lead without requesting 'company name'. However, now when you first browse to the directory page all accounts are visible, but once a search is carried out the accounts added after I enabled Person Accounts disappear.

I'm not sure what the problem is and hope I've articulated it well enough for somebody to help. 

Thanks in advance.

The controller has been added below for your information:

public with sharing class TableExampleController {

    public String getViewIndustryName() {
        return null;
    }

    // account and selection set/variables
    private list<AccountSubClass> AccountList {get; set;}
    private set<Id> AccountSelectedSet;
    public Integer AccountSelectedCount {get; set;}
    public String SelectedOneAccount {get; set;}
 
    // selection and filter 
    public list<String> AlphaList {get; set;}
    public String AlphaFilter {get; set;}
    public String SearchName {get; set;}
    public String SearchBillingAddress {get; set;}
    
    public String SearchIndustry {get; set;} 
    public String CompanyDescription {get; set;}
    
    public String IndustryName = '%';
    //public String CompanyDescription = '%';
    public String likestr = '%';
    
    
    private String SaveSearchName;
    private String SaveSearchBillingAddress;
    
    private String SaveSearchIndustry; 
    
    private String viewIndustryName = 'Industry';
    //private String viewCompanyDescription = 'CompanyDescription';
    
    
    private String QueryAccount;
 
    // display sort and number
    public String RecPerPage {get; set;}
    public list<SelectOption> RecPerPageOption {get; set;}  
    public String SortFieldSave;
    
    private static final List<SelectOption>
    
        VIEW_INDUSTRY = new SelectOption[] {
        new SelectOption('0', 'All Industries'),
        new SelectOption('Art & Culture', 'Art & Culture'),
           new SelectOption('Banking', 'Banking'),
        new SelectOption('Barbers & Hairdressers', 'Barbers & Hairdressers'),
        new SelectOption('Bars & Restaurants', 'Bars & Restaurants'),
        new SelectOption('Beauty', 'Beauty'),
        new SelectOption('Building & Construction', 'Building & Construction'),
        new SelectOption('Car Sales, Repairs & Servicing', 'Car Sales, Repairs & Servicing'),
        new SelectOption('Caterers', 'Caterers'),
        new SelectOption('Chemist / Pharmacy', 'Chemist / Pharmacy'),
        new SelectOption('Communications', 'Communications'),
        new SelectOption('Consulting', 'Consulting'),
        new SelectOption('Education & Training', 'Education & Training'),
        new SelectOption('Electronics', 'Electronics'),
        new SelectOption('Entertainment', 'Entertainment'),
        new SelectOption('Environment', 'Environment'),
        new SelectOption('Fashion & Accessories', 'Fashion & Accessories'),
        new SelectOption('Finance', 'Finance'),
        new SelectOption('Food & Beverage', 'Food & Beverage'),
        new SelectOption('Health & Fitness', 'Health & Fitness'),
        new SelectOption('Hospitality', 'Hospitality'),
        new SelectOption('Insurance', 'Insurance'),
        new SelectOption('Media', 'Media'),
        new SelectOption('Mentors & Coaches', 'Mentors & Coaches'),
        new SelectOption('Not For Profit', 'Not For Profit'),
        new SelectOption('Property - Sales, Lettings & Management', 'Property - Sales, Lettings & Management'),
        new SelectOption('Recreation', 'Recreation'),
        new SelectOption('Religion_Spirituality', 'Religion & Spirituality'),
        new SelectOption('Retail', 'Retail'),
        new SelectOption('Shipping', 'Shipping'),
        new SelectOption('Technology', 'Technology'),
        new SelectOption('Telecommunications', 'Telecommunications'),
        new SelectOption('Tradesperson', 'Tradesperson'),
        new SelectOption('Transportation', 'Transportation'),
        new SelectOption('Utlities', 'Utilities'),
        new SelectOption('Other', 'Other')
        };
     
    public List<SelectOption> getIndustryViewNames(){
    return VIEW_INDUSTRY;
    }
    
    public void setViewIndustryName(String viewIndustryName){ 
        this.viewIndustryName = viewIndustryName;
        }
        
   public String getIndustryName(){
       return viewIndustryName;
       }
 
 
     
     
    /***
    * TableExampleController - Constructor initialization
    ***/
    public TableExampleController(){
        AccountList = new list<AccountSubClass>();
        AccountSelectedSet = new set<Id>();
 
        //records for page initialization
        RecPerPageOption = new list<SelectOption>();
        RecPerPageOption.add(new SelectOption('10','10'));
        RecPerPageOption.add(new SelectOption('25','25'));
        RecPerPageOption.add(new SelectOption('50','50'));
        RecPerPageOption.add(new SelectOption('100','100'));
        RecPerPageOption.add(new SelectOption('200','200'));
        RecPerPage = '10'; //default records per page
 
        // initialization alpha list
        AlphaList = new list<String> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Other', 'All'};
            SortFieldSave = SortField;
 
        // alpha filter, use page parameter or set default to all
        if (apexpages.currentpage().getparameters().get('alpha') == null) {
            AlphaFilter = 'All';
        } else {
            AlphaFilter = apexpages.currentpage().getparameters().get('alpha');
        }
 
        // list generation
        BuildQuery();  
    }
 
    /***
    * StdSetControllerAccount - paging through the Account list
    ***/ 
    public ApexPages.StandardSetController StdSetControllerAccount {
        get {
            if(StdSetControllerAccount == null) {
                StdSetControllerAccount = new ApexPages.StandardSetController(Database.getQueryLocator(QueryAccount));
                // sets the number of records in each page set
                StdSetControllerAccount.setPageSize(Integer.valueOf(RecPerPage));
            }
            return StdSetControllerAccount;
        }
        set;
    }
 
    /***
    * getCurrentAccountList - return an Account list for the table
    ***/  
    public list<AccountSubClass> getCurrentAccountList() {
        UpdateAccountSelectedSet();
 
        AccountList = new list<AccountSubClass>();
        for (Account a : (list<Account>)StdSetControllerAccount.getRecords()) {
            AccountList.add(new AccountSubClass(a, AccountSelectedSet.contains(a.Id)));
        }
        return AccountList;
    }
 
    /***
    * UpdateAccountSelectedSet - add/remove accounts from the selected account id list
    ***/
    public void UpdateAccountSelectedSet(){
        for(AccountSubClass a : AccountList ){
            if(a.aCheckBox == true) {
                AccountSelectedSet.add(a.aAccount.Id);
            } else {
                if(AccountSelectedSet.contains(a.aAccount.Id)) {
                    AccountSelectedSet.remove(a.aAccount.Id);
                }
            }
        }  
        AccountSelectedCount = AccountSelectedSet.size();
    }
 
    /***
    * ClearAccountSelectedSet - remove selected accounts and initialize counter
    ***/
    public PageReference ClearAll(){
        AccountList.clear();
        AccountSelectedSet.clear();
        AccountSelectedCount = 0;
        SearchName = '';
        SearchBillingAddress = '';
        
       SearchIndustry = '';
        
        SaveSearchName = '';
        SaveSearchBillingAddress = '';
        
        SaveSearchIndustry = '';
        
        AlphaFilter = 'All';
 
        BuildQuery();
 
        return null;
    }
 
    /***
    * SearchAccount - set search criteria fields and refresh Account table
    ***/
    public PageReference SearchAccount() {
        SaveSearchName = SearchName;
        SaveSearchBillingAddress = SearchBillingAddress;
        
      SaveSearchIndustry = SaveSearchIndustry;
 
        BuildQuery();
 
        return null;
    }
 
    /***
    * BuildQuery - build query command for list selection change
    ***/
    public void BuildQuery() {
        StdSetControllerAccount = null;
        String QueryWhere = '';
 
        if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
            AlphaFilter = 'All';
        }
 
        QueryAccount = 'SELECT Id, Name, BillingStreet, BillingPostalCode, BillingCountry, BillingCity, phone, Industry, Website, Company_Description__c ' +
            ' FROM Account'; 
 
        if (AlphaFilter == 'Other') {
            QueryWhere = BuildWhere(QueryWhere, '(' + String.escapeSingleQuotes(SortField) + ' < \'A\' OR ' + 
                                    String.escapeSingleQuotes(SortField) + ' > \'Z\') AND (NOT ' + 
                                    String.escapeSingleQuotes(SortField) + ' LIKE \'Z%\') ');
        } else if (AlphaFilter != 'All') {
            QueryWhere = BuildWhere(QueryWhere, '(' + String.escapeSingleQuotes(SortField) + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
        }
 
        if (SaveSearchName != null) {
            QueryWhere = BuildWhere(QueryWhere, ' (Name LIKE \'%' + String.escapeSingleQuotes(SaveSearchName) + '%\')');
        }
        if (SaveSearchBillingAddress != null) {
            QueryWhere = BuildWhere(QueryWhere, '((BillingStreet LIKE \'%' + String.escapeSingleQuotes(SaveSearchBillingAddress) + '%\') or' +
                                    ' (BillingCity LIKE \'%' + String.escapeSingleQuotes(SaveSearchBillingAddress) + '%\') or' +
                                   /*' (BillingState LIKE \'%' + String.escapeSingleQuotes(SaveSearchBillingAddress) + '%\') or' + */
                                    ' (BillingPostalCode LIKE \'%' + String.escapeSingleQuotes(SaveSearchBillingAddress) + '%\') or' +
                                    ' (BillingCountry LIKE \'%' + String.escapeSingleQuotes(SaveSearchBillingAddress) + '%\'))');
        }
 
        
         if (viewIndustryName != '0') {
         QueryWhere = BuildWhere(QueryWhere, ' (Industry LIKE \'%'+ String.escapeSingleQuotes(viewIndustryName) + '%\')');
         }
 
 
       // if (SaveSearchIndustry != null) {
        //   QueryWhere = BuildWhere(QueryWhere, ' (Industry LIKE \'%' + String.escapeSingleQuotes(SaveSearchIndustry) + '%\')');
       // }
 
 
        QueryAccount += QueryWhere;
        QueryAccount += ' ORDER BY ' + String.escapeSingleQuotes(SortField) + ' ' + String.escapeSingleQuotes(SortDirection) + ' LIMIT 10000';
 
        system.debug('QueryAccount:' + QueryAccount);
    }
 
    /***
    * BuildWhere - build soql string for where criteria 
    ***/
    public String BuildWhere(String QW, String Cond) {
        if (QW == '') {
            return ' WHERE ' + Cond;
        } else {
            return QW + ' AND ' + Cond;
        }
    }
 
    /***
    * SortDirection - return sort direction. Default ascending(asc)
    ***/
    public String SortDirection {
        get { if (SortDirection == null) {  SortDirection = 'asc'; } return SortDirection;  }
        set;
    }
 
    /***
    * SortField - return sort by field. Default to Name
    ***/
    public String SortField {
        get { if (SortField == null) {SortField = 'Name'; } return SortField;  }
        set; 
    }
 
    /***
    * SortToggle - toggles the sorting of query from asc<-->desc
    ***/
    public void SortToggle() {
        SortDirection = SortDirection.equals('asc') ? 'desc NULLS LAST' : 'asc';
        // reset alpha filter and sort sequence when sorted field is changed
        if (SortFieldSave != SortField) {
            SortDirection = 'asc';
            AlphaFilter = 'All';
            SortFieldSave = SortField;
        }
        // run the query again
        BuildQuery();
    }
 
Jeff MayJeff May
This Answers Community is focused on configuration and design questions. Programmatic questions are best submitted to the developer forums at https://developer.salesforce.com where the forums and participants are geared toward programming troubleshooting and support.