fork download
  1. String inputProductName = 'Laptop';
  2.  
  3. List<Product2> products = [SELECT Id, Name FROM Product2 WHERE Name = :inputProductName LIMIT 1];
  4.  
  5. if (!products.isEmpty()) {
  6. Product2 product = products[0];
  7. // Get standard pricebook price
  8. PricebookEntry pbe = [
  9. SELECT UnitPrice
  10. FROM PricebookEntry
  11. WHERE Product2Id = :product.Id AND Pricebook2.IsStandard = true
  12. LIMIT 1
  13. ];
  14. System.debug('Price of product "' + product.Name + '" is: ' + pbe.UnitPrice);
  15. } else {
  16. System.debug('Product with name "' + inputProductName + '" not found.');
  17. }
  18.  
Success #stdin #stdout #stderr 0.02s 10496KB
stdin
Standard input is empty
stdout
Object: String error: did not understand #inputProductName
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
String class(Object)>>doesNotUnderstand: #inputProductName (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:5)
stderr
./prog:3: expected expression
./prog:5: expected expression