I was wondering what would be the best way to convert the below code ,which is importing price book entries, so it doesn't hit the governor limits.
for (Integer i = 1; i < csvFileLines.size(); i++) {
PricebookEntry prEnt = new PricebookEntry() ;
String[] csvRecordData = csvFileLines[i].split(',');
String csvName = csvRecordData[0];
ID productID = [SELECT Id from Product2 WHERE Name = :csvName LIMIT 1].Id;
prEnt.Product2 = productID;
priceEntry.add(prEnt);
}
I thought of using a set like the one below, but i am unsure on how to then find the id's based on the variable csvnames from the set.
Set<String> productIDs = new Set<String>();
for (Product2 p : [select Id, Name from Product2 where Name in :csvNames]) {
productIDs.add(p.Id);
productIDs.add(p.Name);
}
All help is appreciated.