1

I have created a dynamically generated grid of records using HTML and Java on the VF page. Now I need to allow editing of the record. For the edit functionality, I have created a javascript function that is being called by setting the onclick attribute of the EditLink to the Javascript function. I have tried to pass the record Id as a parameter to the JS function that does a remote action call to a function in controller that does a SOQL query to search and return the record. From the functionality point of view, the pop up opens but is blank and a VF error of list is empty is displayed. The issue is that the Id is not being passed through to the JS function. The pseudocode is as under:

Setting the Parameter:

//EditLink test
var TestEdit ='';
TestEdit.innerHTML = mapQ[record.AttendeeId].strId;
console.log ("TestEdit: ");
console.log (TestEdit); //This is being returned as blank
//Setting EditLink variable properties
EditLink = document.createElement('a');
EditLink.setAttribute('HREF', "javascript:PopEdit(TestEdit)");
EditLink.setAttribute('onclick', PopEdit(TestEdit));
EditLink.innerHTML = "Edit";

Edit popup

function PopEdit(TestEdit){
console.log ('in PopEdit function the id is:');
console.log (TestEdit); //appearing blank
jQuery("#EditContact").modal();
var UpdateId = Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.ControllerC.UpdateRecord}',
TestEdit,handleUpdateResultresponse);
function handleUpdateResultresponse(result, event){
if (event.status)
{console.log ('The update id is:');
 console.log (UpdateId);
}

The think the issue is that the jQuery statement should be in the if(event.status) clause. However, if that was the case then the Console.log should've displayed the id (please refer statements where it indicates a blank value was returned). Please share what do you think needs to be fixed here. Thanks

4
  • 1
    Please use markdown for all your (properly indented) code. Also show all relevant code + error messages in full / detail, not just some bits you suspect relevant.
    – tobibeer
    Feb 21, 2016 at 14:00
  • 1
    @tobibeer Actually, there are a lot of posts that get closed because OP did not make any effort to figure out which code is relevant. Personally, I'd rather have it not be enough and need to pester OP for more. At least it demonstrates some effort already put in to solve the problem.
    – Adrian Larson
    Feb 21, 2016 at 16:52
  • The snippet(s) should be a Short, Self Contained, Correct (Compilable), Example.
    – Adrian Larson
    Feb 21, 2016 at 16:53
  • @AdrianLarson, I understand. We sure don't want to see excessive code, e.g. css, and what not only to see how irrelevant it all is.
    – tobibeer
    Feb 21, 2016 at 16:54

1 Answer 1

0

You are not passing any parameters through your RemoteAction. Take a look at this JavaScript Remoting Example.

Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.ControllerC.UpdateRecord}',
    TestEdit,handleUpdateResultresponse
);

In the example,

Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.AccountRemoter.getAccount}',
    accountName, 
    function(result, event){
        /*callback*/
    }
);

Notice that the parameters go between the method name and callback. If you had multiple parameters:

Visualforce.remoting.Manager.invokeAction(
    '{!$RemoteAction.AccountRemoter.getAccount}',
    param1, param2, param3, etc,
    function(result, event){
        /*callback*/
    }
);
3
  • Thanks Adrian. It helped me resolve one of the issues. I am getting the "Visualforce Remoting Exception: List has no rows for assignment to SObject "
    – Ng H
    Feb 22, 2016 at 4:27
  • @TWA Glad it helped. I think you should accept this as an answer to your OP and ask a new question where you include your Apex code and that error. You don't have any Apex above so I cannot possibly help you. :) Anyway it is quite distinct from what you needed to fix here.
    – Adrian Larson
    Feb 22, 2016 at 4:31
  • I have selected your answer as the best and have added another question too. Here is the link: salesforce.stackexchange.com/questions/111225/…
    – Ng H
    Feb 22, 2016 at 5:12

You must log in to answer this question.

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