Show/Hide Toolbars

The following sample searches for account records where the name contains "2009".

Code Snippet

//for this example, it is assumed that at least one account record that meets the search criterion already exists

protected AccountRepository accountRepository;

public void searchAccounts() throws Exception {

StringFieldCriterion fieldCriterion = new StringFieldCriterion();

fieldCriterion.setComparator(StringComparator.CONTAINS);

LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression();

fieldPathExpression.setSearchKeyPath("name");

fieldCriterion.setFieldPath(fieldPathExpression);

fieldcriterion.getValue().add("2009");

FieldSearchClause searchCriteria = new FieldSearchClause();

searchCriteria.setOperator(LogicOperator.AND);

searchCriteria.getCriteria().add(fieldCriterion);

List<Account> accounts = accountRepository.readAccountsByCriteria(searchCriteria, 100, getPropertiesToRead());

}

private List<String> getPropertiesToRead() {

List<String> properties = new List<String>();

properties.add("createdBy");

properties.add("createdOn");

properties.add("modifiedBy");

properties.add("modifiedOn");

properties.add("name");

properties.add("allocated");

properties.add("allocationLimit");

properties.add("used");

properties.add("available");

properties.add("startOn");

properties.add("endOn");

properties.add("expensePercent");

properties.add("invoiceExpensePercent");

properties.add("invoiceTaskPercent");

properties.add("taskPercent");

properties.add("allowExpense");

properties.add("allowTask");

properties.add("allowInvoiceExpense");

properties.add("allowInvoiceTask");

properties.add("accountInvolvedType");

properties.add("accountVendorType");

properties.add("accountProjectType");

properties.add("accountOverdraftType");

properties.add("type");

properties.add("active");

properties.add("autoPost");

properties.add("categories");

properties.add("expenseCategory");

properties.add("taskCategory");

properties.add("projectCategory");

properties.add("invoiceExpenseCategory");

properties.add("invoiceTaskCategory");

properties.add("involved");

properties.add("project");

properties.add("vendor");

properties.add("parentAccount");

return properties;

}