// Get the CustomTargetingService.
CustomTargetingServiceInterface customTargetingService =
dfpServices.get(session, CustomTargetingServiceInterface.class);
// Create a statement to select custom targeting value.
StatementBuilder statementBuilder = new StatementBuilder()
.where("WHERE id = :id")
.orderBy("id ASC")
.limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
.withBindVariableValue("id", customTargetingValueId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get custom targeting values by statement.
CustomTargetingValuePage page = customTargetingService
.getCustomTargetingValuesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (CustomTargetingValue customTargetingValue : page.getResults()) {
System.out.printf("%d) Custom targeting value with ID \"%d\""
+ " will be deleted.\n", i++, customTargetingValue.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of custom targeting values to be deleted: %d\n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.dfp.axis.v201306.DeleteCustomTargetingValues action =
new com.google.api.ads.dfp.axis.v201306.DeleteCustomTargetingValues();
// Perform action.
UpdateResult result = customTargetingService.performCustomTargetingValueAction(
action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf(
"Number of custom targeting values deleted: %d\n", result.getNumChanges());
} else {