npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-vf-remote-actions

v1.0.1

Published

An angular 1.x library for Salesforce that makes it easy to call remote actions on a visualforce page. This should be used only if you host your angular app in a visualforce page.

Downloads

8

Readme

angular-vf-remote-actions

An Angular 1.x module that makes it easy to call Salesforce Remote Actions. This module is only useful if you host your Angular app in a Visualforce page. For more information on Visualforce Remote Actions read the Salesforce Documentation on JavaScript Remoting for Apex Controllers.

Usage

  1. Install via npm
npm install angular-vf-remote-actions --save

or you can download manually and include it in your project.

  1. Reference in your source code
<!-- local development -->
<script src="node_modules/angular-vf-remote-actions/dist/vfrAction.provider.js"></script>

<!-- Visuaforce: assuming you zipped the dist folder into a Static Resource called 'vfrAction' -->
<script src="{! URLFOR( $Resource.vfrAction, 'dist/vfrAction.provider.js' ) }"></script>
  1. Include vfrAction as a dependency in your application module
var app = angular.module('myApp', ['vfrAction']);
  1. Inject VfrAction in your controller
app.controller('myCtrl', function(VfrAction) {

  // create a new remote action.
  // This will call the method 'myRemoteAction' on the page controller 'MyApexController'
  new VfrAction('MyApexController.myRemoteAction')

    // pass some parameters to the remote action
    .invoke('arg1', 'arg2')

    // do something with the results
    .then(function(result){
      console.log(result);
    })

    // handle any errors
    .catch(function(event){
      console.error(event);
    });

});

Logging

This module will log all calls and responses to $log.debug. You can disable this with the following configuration:

app.config(function($logProvider){
  $logProvider.debugEnabled(false);
});

Hosting in Salesforce

You will need a Visualforce page to host your application, and an Apex Controller for your Remote Actions. The best way to reference this module from a Visualforce page is to upload it as a Static Resource.

Reference it in your Visualforce page:

<!-- assuming you zipped the dist folder into a Static Resource called 'vfrAction' -->
<script src="{! URLFOR( $Resource.vfrAction, 'dist/vfrAction.provider.js' ) }"></script>

Create a Remote Action on your Apex Controller:

@RemoteAction
global static Account[] myRemoteAction(String name) {
  return [SELECT Id FROM Account WHERE Name = :name];
}

Examples

Example usage can be found at index.html. If you have cloned this repo, you can run the examples page locally with the following command:

npm start

Configuration

You can set some defaults for your actions by configuring the provider.


// configuration
app.config(function(VfrActionProvider){

  // developer orgs only
  VfrActionProvider.defaultNamespace('gbutt');

  // this controller will be prefixed on all your actions, unless you specify another controller
  VfrActionProvider.defaultController('MyApexController');

  // this configuration will get merged in all your actions.
  // You can override it on a per action basis.
  VfrActionProvider.defaultConfiguration({
    timeout: 10000,
    escape: false
  });


  // You can predefine a unique name and configuration for your remote actions.
  var actions = {};
  actions.myAction = {
    actionName: 'myRemoteAction',
    configuration: {
      escape: true,
      buffer: true
    }
  };
  VfrActionProvider.actions(actions);
});

// usage
app.controller('myCtrl', function(VfrAction) {

  // call a predefined action.
  // This will invoke gbutt.MyApexController.myRemoteAction
  // with the configuration {timeout: 10000, escape: true, buffer: true}
  new VfrAction('myAction').invoke();

  // override the default controller
  new VfrAction('AnotherController.anotherAction').invoke();

  // merge and override the default configuration
  new VfrAction('yetAnotherAction', { escape: true }).invoke();
});

Mocking Remote Actions for Local Development

We provide a handy utility for mocking callouts to Remote Actions at dist/vfrMock.js. See example/mockedVfrActions.js for usage.