+ Start a Discussion
Stacey McDonaldStacey McDonald 

Editable Contact List filter

I borrowed some apex code to develop a editable related contact on an account visual force page.  I need to limit the related contact list to those not marked as inactive.  What code would need to be added to achieve this result?
 
/*
 * EditableContactListExtension.cls
 *
 * Copyright (c)2013, Michael Welburn.
 * License: MIT
 *
 * Usage:
 *   This is the implementation class where Object specific references
 *   need to be defined. Please see EditableList.cls for more information
 *   on what each method is responsible for.
 *
 *   Required methods:
 *     - EditableContactListExtension(ApexPages.StandardController)
 *     - getChildren()
 *     - initChildRecord()
 *
 */
public with sharing class EditableContactListExtension extends EditableList
{
  // Read the explanation in EditableContactListExtension(ApexPages.StandardController)
  // to see when to uncomment the following line.

  // public Account myAccount {get; private set;}

public ApexPages.StandardController controller {get;set;}

  public EditableContactListExtension(ApexPages.StandardController stdController) 
  {
    super(stdController);
    controller = stdController;

    // If necessary, explicitly query for additional metadata on parent record
    // if you are looking to display things that don't come back with the
    // StandardController. In that case, you will need to replace the "Account.X"
    // references in the Visualforce Page with references to an Account variable
    // that you will need to declare in this class (myAccount.X). I have commented out
    // an example.

    // this.myAccount = [SELECT Id,
    //                            Name,
    //                            Custom_Relationship__r.Name
    //                        FROM Account
    //                        WHERE Id =: stdController.getRecord().Id];
    
    this.childList = [SELECT Id,
                          FirstName,
                          LastName,
                          Studio__c,
                          Type__c,
                          Preferred_Contact_Frequency__c,
                          Date_Last_Contacted__c,
                          Days_Since_Contact__c
                      FROM Contact
                      WHERE AccountId =: mysObject.Id
                      ORDER BY Contact.FirstName ASC];
  }

  /*
   * This method is necessary for reference on the Visualforce page, 
   * in order to reference non-standard fields.
   */
  public List<Contact> getChildren()
  {
    return (List<Contact>)childList;
  }

  public override sObject initChildRecord()
  {
    Contact child = new Contact();
    // Can either use mysObject or acct here
    child.AccountId = mysObject.Id;
    
    return child;
  }

  public PageReference saveAll()
  {
    super.save();
    return controller.save();
  }
}
Thanks in advance!
 
Best Answer chosen by Stacey McDonald
KaranrajKaranraj
Stacey - update the contact query
 
this.childList = [SELECT Id,
                          FirstName,
                          LastName,
                          Studio__c,
                          Type__c,
                          Preferred_Contact_Frequency__c,
                          Date_Last_Contacted__c,
                          Days_Since_Contact__c
                      FROM Contact
                      WHERE AccountId =: mysObject.Id and Inactive__c != True
                      ORDER BY Contact.FirstName ASC];



 

All Answers

ManojjenaManojjena
Hi Stacey,
What is the field Api name in contact to indicate the inactive contact ?

Thanks
Manoj

 
Stacey McDonaldStacey McDonald
It's a custom checkbox field named Inactive__c

Thanks!
KaranrajKaranraj
Stacey - update the contact query
 
this.childList = [SELECT Id,
                          FirstName,
                          LastName,
                          Studio__c,
                          Type__c,
                          Preferred_Contact_Frequency__c,
                          Date_Last_Contacted__c,
                          Days_Since_Contact__c
                      FROM Contact
                      WHERE AccountId =: mysObject.Id and Inactive__c != True
                      ORDER BY Contact.FirstName ASC];



 
This was selected as the best answer
ManojjenaManojjena
Hi Stacey,
Try with below  code and let me know if it helps .
public with sharing class EditableContactListExtension extends EditableList
{
  // Read the explanation in EditableContactListExtension(ApexPages.StandardController)
  // to see when to uncomment the following line.

  // public Account myAccount {get; private set;}

public ApexPages.StandardController controller {get;set;}

  public EditableContactListExtension(ApexPages.StandardController stdController) 
  {
    super(stdController);
    controller = stdController;

    // If necessary, explicitly query for additional metadata on parent record
    // if you are looking to display things that don't come back with the
    // StandardController. In that case, you will need to replace the "Account.X"
    // references in the Visualforce Page with references to an Account variable
    // that you will need to declare in this class (myAccount.X). I have commented out
    // an example.

    // this.myAccount = [SELECT Id,
    //                            Name,
    //                            Custom_Relationship__r.Name
    //                        FROM Account
    //                        WHERE Id =: stdController.getRecord().Id];
    
    this.childList = [SELECT Id,
                          FirstName,
                          LastName,
                          Studio__c,
                          Type__c,
                          Preferred_Contact_Frequency__c,
                          Date_Last_Contacted__c,
                          Days_Since_Contact__c
                      FROM Contact
                      WHERE AccountId =: mysObject.Id AND Inactive__c=false
                      ORDER BY Contact.FirstName ASC];
  }

  /*
   * This method is necessary for reference on the Visualforce page, 
   * in order to reference non-standard fields.
   */
  public List<Contact> getChildren()
  {
    return (List<Contact>)childList;
  }

  public override sObject initChildRecord()
  {
    Contact child = new Contact();
    // Can either use mysObject or acct here
    child.AccountId = mysObject.Id;
    
    return child;
  }

  public PageReference saveAll()
  {
    super.save();
    return controller.save();
  }
}
Thnaks
Manoj
 
Stacey McDonaldStacey McDonald
Both answers work great!  Thanks for the help guys.