Created
April 16, 2018 23:18
-
-
Save olgaloza/7560cb83054566f6d71e1c2ae1e67274 to your computer and use it in GitHub Desktop.
Final Project - Create sample Stock Items class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class createStockItems { | |
public static void createSampleStockItems(Integer numberOfItems) { | |
//Putting new stock items into a list to bulkify the code | |
List<Stock_Item__c> stockItemsList = new List<Stock_Item__c>(); | |
//Loop through and add stock items: | |
for (Integer i = 0; i < numberOfItems; i++) { | |
System.debug('i = ' + i); | |
Stock_Item__c si = new Stock_Item__c(); | |
si.Item_Name__c = 'Sample Stock Item ' + (i+1); | |
si.Description__c = 'Lorem ipsum dolor sit amet ' + (i+1); | |
si.List_Price__c = (i+1)+(i+1); | |
si.Minimum_Stock_Level__c = 3; | |
si.Stock_on_Hand__c = (i+1)+(i+1); | |
stockItemsList.add(si); | |
} | |
//Inserting all in one action: | |
insert stockItemsList; | |
System.debug('Inserted ' + stockItemsList.size() + ' stock items.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment