Problem in calling Apex function

  • 1
  • Problem
  • Updated 2 years ago
  • In Progress
  • (Edited)
I have created one Row Action in Table  and calling apex function from snippet. But it is not able to call the Apex function. Weird thing is that i am not getting error after clicking row action icon.

Can somebody help to resolve it?


Class - 
public with sharing class MyApexController{
    public static List<SObject> getUnReadAlerts(Id alertId){
        // Logic
       return List<SObject>;
    }
}



Page - 

<apex:page docType="html-5.0" readOnly="true"
    standardController="SObject" extensions="MyApexController">
<skuid:page page="skuidPage"/>
</apex:page>


Snippet - 

var $ = skuid.$,
args = arguments[0],
item = args.item,
list = args.list,
model = args.model;
    
var currentUserModel = skuid.model.getModel( 'NewModel' );
var alertRecord = currentUserModel.getFirstRow();
var alertId = currentUserModel.getFieldValue( alertRecord, 'Id' ) ;
currentUserModel.abandonAllRows();
alert('Point1');
var myUnReadAlerts = MyApexController.getUnReadAlerts(alertId);
currentUserModel.adoptRows(myUnReadAlerts);
alert('Point2');


I am able to get the first alert , but not second. 
Photo of Sumeet Sangle

Sumeet Sangle

  • 452 Points 250 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb
HI Sumeet, it looks like you might need to add the @RemoteAction annotation to your apex class, so that its exposed to javascript in the page - as per this post: https://community.skuid.com/skuid/top...

so your apex class becomes:

public with sharing class MyApexController{

@RemoteAction
public static List getUnReadAlerts(Id alertId){
// Logic
return List;
}
}

This also assumes you've got your skuid page deployed in visualforce using the skuid:page method, which it looks like you do. Hope that works for you.
Photo of Sumeet Sangle

Sumeet Sangle

  • 452 Points 250 badge 2x thumb
Thanks for quick help Greg!

But still my controller is not getting called and getting undefined in following variable.

var myUnReadAlerts = MyApexController.getUnReadAlerts(alertId);

Alert(
myUnReadAlerts) ---> Undefined

Do you have any clue on this?
Photo of Sumeet Sangle

Sumeet Sangle

  • 452 Points 250 badge 2x thumb
Hi Greg, 

Now i am able to call the apex method , but my model is not getting updated.

currentUserModel.abandonAllRows(); -- it is not updating model
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb
That looks like it should work. Have you done a console.log() before and after to confirm whether its changed?

ie

console.log('Model length before = '+currentUserModel.length);
currentUserModel.abandonAllRows();
console.log('Model length after = '+currentUserModel.length);

The other method you might want to try is currentUserModel.emptyData(); as outlined here https://community.skuid.com/skuid/top...