You need to sign in to do that
Don't have an account?
Alisa Zhurova
Why this code not add records in object PricebookEntry?
trigger UpdatePrice on Product2 (after insert) { list<PricebookEntry> pblist=new list<PricebookEntry>(); PricebookEntry pr=new PricebookEntry(); for(Product2 ps:trigger.new){ if(ps.isActive==false){ pr.Product2Id = ps.id; pr.Pricebook2Id = '01s5g00000JO516AAD'; pr.isActive = true; Integer len = 5; final String chars = '123456789'; String randStr = ''; while(randStr.length()<len){ Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length()); randStr += chars.substring(idx,idx+1); } pr.UnitPrice = Integer.valueOf(randStr); } } pblist.add(pr); insert pblist; system.debug('***'+pr); }