
Since Summer 14 released this weekend every time I try and clone a product I get the below error message and I don’t understand what its saying? I think something changed with the price book in the new release. Any ideas?
It doesn’t happen when I create a new product and type all the data in manually…very much a pain but it works. The following is the trigger in question I believe
trigger PriceBookEntryUpdate on Product2 (before insert,after insert, before update) {
List<User> userDetails=[Select u.Email, u.Id from User u];
Map<String , Id> userMap= new Map <String,Id>();
for (User user : userDetails){
userMap.put(user.Email,user.Id);
}
if(Trigger.isInsert || Trigger.isUpdate){
if(Trigger.isBefore){
//Before trigger starts
for(Product2 prod : Trigger.new){
if(prod.PME_Text__c!=NULL ){
prod.PME__c=userMap.get(prod.PME_Text__c.trim());
}
if(prod.AE_Text__c!=NULL ){
prod.AE__c=userMap.get(prod.AE_Text__c.trim());
}
if((Trigger.isInsert) &&(prod.Product_Status_Code1__c!='6EOL' && prod.Product_Status_Code1__c!='8INAC')){
prod.IsActive=true;
}
}
}
//After trigger starts-creation of PriceBookEntry Record
if(Trigger.isAfter){
Id StdPrcId=[Select id from PriceBook2 where isStandard=true limit 1].id;
List<PricebookEntry> pbList= new List<PricebookEntry>();
for(Product2 p : Trigger.new){
PricebookEntry pb=new PricebookEntry(Product2Id=p.id,PriceBook2Id=StdPrcId,UnitPrice=(p.unit_Cost_default__C==null?0:p.unit_Cost_default__C),IsActive=true);
pbList.add(pb);
}
try{
insert pbList; } catch(Exception e){system.debug('Error :' +e.getMessage());}
}
}
}