Skip to content

Instantly share code, notes, and snippets.

@dcarroll
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcarroll/9610037 to your computer and use it in GitHub Desktop.
Save dcarroll/9610037 to your computer and use it in GitHub Desktop.
public class CreateMerchandiseData {
public static void ClearMerchandiseDataBatch() {
String query = 'SELECT Id,CreatedDate FROM Merchandise__c ' +
'WHERE Id NOT IN (SELECT Merchandise__c FROM Line_Item__c)';
CleanUpRecords c = new CleanUpRecords(query);
Database.executeBatch(c);
}
public static void GenerateMerchandiseData() {
// Create Warehouse if one does not exist
Warehouse__c w;
List<Warehouse__c> warehouse = [SELECT ID from Warehouse__c];
if(warehouse.size() == 1 || warehouse.size() == 0) {
w = new Warehouse__c(
Name='Warehouse 1',
City__c='San Francisco',
Location__Latitude__s=37.7833,
Location__Longitude__s=122.4167);
insert w;
} else {
w = warehouse[0];
}
Merchandise__c[] ml = new List<Merchandise__c>();
for (Integer i=0;i<250;i++) {
Merchandise__c m = new Merchandise__c(
Name='Merchandise ' + i,
Price__c=2,
Quantity__c=100,
Warehouse__c = w.Id);
ml.add(m);
}
insert ml;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment