// Get DfpUser from "~/dfp.properties".
DfpUser user = new DfpUser();
// Get the CustomFieldService.
CustomFieldServiceInterface customFieldService =
user.getService(DfpService.V201308.CUSTOM_FIELD_SERVICE);
// Create statement to select only custom fields that apply to line items.
String statementText =
"WHERE entityType = :entityType LIMIT 500";
Statement filterStatement =
new StatementBuilder(statementText)
.putValue("entityType", CustomFieldEntityType.LINE_ITEM.toString())
.toStatement();
// Set defaults for page and offset.
CustomFieldPage page = new CustomFieldPage();
int offset = 0;
int i = 0;
List<Long> customFieldIds = new ArrayList<Long>();
do {
// Create a statement to page through custom fields.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get custom fields by statement.
page = customFieldService.getCustomFieldsByStatement(filterStatement);
if (page.getResults() != null) {
for (CustomField customField : page.getResults()) {
System.out.println(i + ") Custom field with ID \""
+ customField.getId() + "\" and name \"" + customField.getName()