0

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 enter image description here

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:

enter image description here

11
  • thats the reason I don't like js alert() for debugging. Use console.log('---here---',record.toString()); open browser console and check the result.
    – Ratan Paul
    Mar 16, 2016 at 11:51
  • it display the same: ---here---[object Object]
    – Yelmox
    Mar 16, 2016 at 12:20
  • Can you just remove the tostring() try like this console.log('---here---',record);.. check this is returning JS object or not.
    – Ratan Paul
    Mar 16, 2016 at 12:22
  • Nothing get displayed
    – Yelmox
    Mar 16, 2016 at 12:38
  • what you can see in browser console ?
    – Ratan Paul
    Mar 16, 2016 at 12:39

1 Answer 1

0

I finally got a different approach and get the solution to this tricky salesforce Object. instead of using Javascript Remote Object I used:

`

$(document).ready(function() { sforce.connection.sessionId = "{!$Api.Session_ID}"; //Used for Session out //var queryResult = sforce.connection.query("Select id, Pricebook2Id, Name, UnitPrice, IsActive from PricebookEntry Where Pricebook2Id='01so0000002r3TBAAY' and UnitPrice > 0 and IsActive=TRUE"); var queryResult = sforce.connection.query("Select id, Pricebook2Id, Name, UnitPrice from PricebookEntry Where Pricebook2Id='01so0000002r3TBAAY' and UnitPrice > 0 and IsActive=TRUE"); var records = queryResult.getArray('records'); var table= $('#example').DataTable( { "bPaginate": true, "bLengthChange": false, "bFilter": true, "bInfo": false, "bAutoWidth": true, data: records, columns: [ { data: "Name" }, { data: "UnitPrice" }, { "targets": -1, "data": "null", "defaultContent": "" } ] } ); $('#example tbody').on('click', 'tr', function () { var data = table.row(this).data(); alert( 'You Choose the Product: '+ data["Id"]); } ); } ); var filteredData = table .column( 1 ) .data() .filter( function ( value, index ) { return value > 20 ? true : false; } );


Name UnitPrice

        </tr>
    </thead>
    <tfoot>
        <tr>              
            <th>Name</th>
            <th>UnitPrice</th>
            <th></th>

        </tr>
    </tfoot>
</table>

`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .