function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rafael Sanchez 4Rafael Sanchez 4 

calling PriceBookEntry from Javascript

After reading tons of links, posts and many documents, I decided to ask for help here, hopping some guru can help me with this issue:
 

<!-- Visualforce Remote object component for Products -->
<apex:remoteObjects >
<apex:remoteObjectModel name="PriceBookEntry" jsShorthand="Prod" fields="id, Name, Pricebook2Id, UnitPrice, IsActive">
</apex:remoteObjectModel>
</apex:remoteObjects>

I have done this javascript fuction to display records from PriceBookEntry Object using remoteObject in Javascript:

function fetchPB(){var wh = new SObjectModel.Prod();
    wh.retrieve({
      where:{
            Pricebook2Id : {eq:'01so0000002r3TBAAY'}, 
            IsActive : {eq:true},
            UnitPrice : {gt: 0}
      },
      limit: 5
      },function(err, records){
        if(err) alert(err.message);
        else {
          records.forEach(function(record) {             
            var divCol = $('<div class="row">');
            var p = record.get("Pricebook2Id");
            alert('row => ' + record.toString());
            var detail = $('<p>'+record.get("Name")+'<br/></p>');           
            var link1 = $('<p><br/><input type="check" name="optCheck"></p> ');
            link1.click(function(){              
              $('#inputProduct2').val(record.get("UnitPrice"));
            });
            detail.append(link1);
            h3.append(detail); 
            divCol.append(product);
            divCol.appendTo('#prodRow');
          });
        }
      });      
}

When I execute this function I can see in the developer console of my browser the post action and the data is coming from the server

User-added image
Even I see the data is coming I can't get the object's values, if I display a javascript alert with the object information I can't see values only this:

User-added image

I'm prety sure this answer will be not only a big help for me but for the entire SF comunity.

Thanks in Advance.

Naval Sharma4Naval Sharma4
HI Rafael,

Did you see this in your code?
detail.append(link1);
 h3.append(detail); 
 divCol.append(product);
 divCol.appendTo('#prodRow');

Where is this h3 coming from?
Rafael Sanchez 4Rafael Sanchez 4
Yes, but at that point is now very important, the point is that the alert() does not, display the field with it's value.
noobi devnoobi dev
try console.log(record) instead of the alert - this will print out the object in the dev console ( in chrome - F12) - once you have the object - you can inspect the object and its properties in the developer console
Vikas gupta 24Vikas gupta 24
function fetchPB(){   
    var wh = new SObjectModel.Prod();
    wh.retrieve({
      where:{
            Pricebook2Id : {eq:'01s90000001Cvc2'}, 
            IsActive : {eq:true},
            UnitPrice : {gt: 0}
      },
      limit: 5
      },function(err, records){
        if(err) alert(err.message);
        else {
          records.forEach(function(record) {             
            var divCol = $('<div class="row">');
            var p = record.get("Pricebook2Id");
            alert('row => ' + JSON.stringify(record));
            var detail = $('<p>'+record.get("Name")+'<br/></p>');           
            var link1 = $('<p><br/><input type="check" name="optCheck"></p> ');
            link1.click(function(){              
              $('#inputProduct2').val(record.get("UnitPrice"));
            });
            detail.append(link1);
            h3.append(detail); 
            divCol.append(product);
            divCol.appendTo('#prodRow');
          });
        }
      });      
}

Please use following line in your alert
alert('row => ' + JSON.stringify(record));
Thanks, Vikas