function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rsoesemannrsoesemann 

Unable to REST API as an ExtJS4 REST Store

Hy,

 

I am trying to use the ExtJS4 grid widget to display and modify SObjects on a page as shown here:

 

Others like Jeff Trull have published great solutions to this using

Javascript Remoting and a custom Javascript Rest proxy to interact with Salesforce REST API.

 

What I don't like with both solutions is that they are constructed out of hundred lines of (at least for me ;-) hard to maintain lines of Javascript. So I was really happy to find the this tutorial: RESTful Store with GridPanel and RowEditor

 

My problem is that it simply doesn't work with Salesforce.com somewhat non-standard REST API:

 

Problem 1: Parameters from ExtJS go to Salesforce proxy instead to REST API

Due to the Same-Origin Policy thing I am calling the API by using a SalesforceProxy-Endpoint header.

 ...
 proxy: {
	type: 'rest',
	noCache: false,
	url: 'https://' + location.hostname + '/services/proxy',
	headers: {
		'SalesforceProxy-Endpoint': '{!URLFOR('/services')}/apexrest/sobject/{!object}',
		'Authorization': 'OAuth {!GETSESSIONID()}',
		'Accept': 'application/json'
	},
	...

 With this ExtJS is not able to construct correct REST URLs. E.g. When doing an DELETE Id it concats "/{Theid} TO the services/proxy url. Instead I need it as part of my SalesforceProxy-Endpoint url.

 

Problem 2: No standard GET on REST API

 

To get all accounts ExtJS calls  a GET .../Account/ but Salesforce.com expects a non standard /Accounts?query=SELECT Name FROM....

 

Do you have any idea to solve this?

My yet inimplemented idea is to create an adapter REST service with APEX that works like ExtJS expects it an internally calls the Standard REST API...just passing through its results.

JeffTrullJeffTrull

Hi Robert,

 

After looking at the REST Proxy documentation in ExtJS 4.0 I think you may be able to achieve your desired goal by subclassing that proxy and supplying your own buildRequest function.  It looks like that gives you the hook to change the url and supplied parameters as you need them to be.  If it works, it will be cleaner than the DirectProxy hack I did in my own code... in which case, please share :)

 

Cheers,

Jeff

 

rsoesemannrsoesemann

Hy Jeff,

 

thanks for the hint. But I decided not to dig deeper into this ExtJS as a editable Grid thing. This is way to much javascript code for me. I just looked at Apps like Gridbuddy and decided that native Visualforce components are more suitable and have easier to maintain code.

 

Thanks a lot for your help and your great posts.

 

Cheers

R.