Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for the Actions API #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 66 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ API.

ForceJS is similar to [ForceTK](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit), but has no jQuery dependency and comes with an AngularJS version ([ForceNG](https://github.com/ccoenraets/forceng)).

The main target for ForceJS are applications running on your own server (Heroku or elsewhere) and Cordova/Mobile SDK applications.
The main target for ForceJS are applications running on your own server (Heroku or elsewhere) and Cordova/Mobile SDK applications.

## Browser and Cordova without Code Changes

Expand Down Expand Up @@ -88,7 +88,7 @@ To create and run a minimalistic sample app using ForceJS:
force-server
```

This starts the ForceServer server on port 8200 and loads your sample app in your default browser. After authenticating against your developer org, you should see a list of contacts.
This starts the ForceServer server on port 8200 and loads your sample app in your default browser. After authenticating against your developer org, you should see a list of contacts.

> Starting in the Spring 15 release, some Salesforce REST APIs (like Chatter and sobjects) support CORS. To allow an app to make direct REST calls against your org, register the app domain in Setup: Administer > Security Controls > CORS.

Expand Down Expand Up @@ -162,7 +162,7 @@ To run the same application in Cordova:
cordova build ios
```

Run the project. For example, for iOS, open the project (platforms/ios/contactforce.xcodeproj) in Xcode and run it in the emulator or on your iOS device. After authenticating against your developer org, you should see a list of contacts.
Run the project. For example, for iOS, open the project (platforms/ios/contactforce.xcodeproj) in Xcode and run it in the emulator or on your iOS device. After authenticating against your developer org, you should see a list of contacts.

> Note that you didn't change any code to run the app in Cordova. When running in Cordova, ForceJS automatically uses the Salesforce Mobile SDK OAuth plugin, and invokes REST services without using a proxy because the webview used in Cordova is not subject to the same cross domain policy restrictions.

Expand Down Expand Up @@ -423,7 +423,7 @@ Parameters:

*Default*: GET

- **contentType**
- **contentType**

The request content type.

Expand Down Expand Up @@ -477,7 +477,7 @@ Example:
force.chatter({path: "/users/me"},
function(result) {
console.log(result)
),
},
function(error) {
console.log(error);
});
Expand All @@ -495,7 +495,66 @@ Parameters:

*Default*: GET

- **contentType**
- **contentType**

The request content type.


- **params**

An object that will be turned into a query string appended to the request URL

- **data**

An object representing data to be sent as the body of the request.

### actions()

A convenience function to use the Actions API

Example:

```
force.actions({
method: 'POST',
contentType: 'application/json',
path: '/custom/apex/SomeClassWithInvocableMethod',
data: {inputs: [{"your": "data"}]}
},
function(result) {
console.log(result)
},
function(error) {
console.log(error);
});
```
force.actions({
method: 'POST',
contentType: 'application/json',
path: '/standard/emailSimple',
data: {"inputs":[{"emailAddresses":"[email protected]", "emailSubject":"test", "emailBody": "Test"}]}]}
},
function(result) {
console.log(result)
},
function(error) {
console.log(error);
});
```

Parameters:

- **path**

The path of the Actions API service to invoke

- **method**

The HTTP method to execute: GET, POST, PUT, DELETE, PATCH

*Default*: GET

- **contentType**

The request content type.

Expand Down Expand Up @@ -523,7 +582,7 @@ ForceJS was built based on the following requirements:
- Full OAuth workflow
- Browser and Cordova-based execution without code or configuration changes

Depending on your own requirements, you should also consider the following libraries:
Depending on your own requirements, you should also consider the following libraries:

- [ForceTK](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit): Proven toolkit for Salesforce REST APIs. Leverages jQuery.
- [NForce](https://github.com/kevinohara80/nforce): node.js REST API wrapper for force.com, database.com, and salesforce.com.
Expand Down
40 changes: 35 additions & 5 deletions force.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var force = (function () {

// The force.com API version to use.
// To override default, pass apiVersion in init(props)
apiVersion = 'v33.0',
apiVersion = 'v35.0',

// Keep track of OAuth data (access_token, refresh_token, and instance_url)
oauth,
Expand Down Expand Up @@ -432,10 +432,10 @@ var force = (function () {
);

}

/**
* Convenience function to retrieve an attachment
* @param id
* @param id
* @param successHandler
* @param errorHandler
*/
Expand Down Expand Up @@ -464,7 +464,7 @@ var force = (function () {
errorHandler
);
}


/**
* Convenience function to create a new record
Expand Down Expand Up @@ -609,6 +609,35 @@ var force = (function () {

}

/**
* Convenience function to invoke the Actions API
* @param params
* @param successHandler
* @param errorHandler
*/
function actions(params, successHandler, errorHandler) {

var base = "/services/data/" + apiVersion + "/actions";

if (!params || !params.path) {
errorHandler("You must specify a path for the request");
return;
}

if (params.path.charAt(0) !== "/") {
params.path = "/" + params.path;
}

if (params.path.search(/^\/(standard|custom)/) === -1) {
errorHandler("The Action path must point to either a standard or custom action");
return;
}

params.path = base + params.path;

request(params, successHandler, errorHandler);
}

// The public API
return {
init: init,
Expand All @@ -624,10 +653,11 @@ var force = (function () {
retrieve: retrieve,
apexrest: apexrest,
chatter: chatter,
actions: actions,
discardToken: discardToken,
oauthCallback: oauthCallback,
getPickListValues: getPickListValues,
getAttachment: getAttachment
};

}());
}());