Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 99242ec

Browse files
author
Pat Patterson
committed
Added upsert
1 parent a3aaa85 commit 99242ec

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Background
88

99
Due to the [same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy), JavaScript running in Visualforce pages may not use [XmlHttpRequest](http://en.wikipedia.org/wiki/XMLHttpRequest) to directly invoke the REST API, since Visualforce pages have hostnames of the form abc.na1.visual.force.com, and the REST API endpoints are of the form na1.salesforce.com.
1010

11-
The RemoteTK Visualforce Custom Component (comprising RemoteTK.component and RemoteTKController.cls) provides an abstraction very similar to the REST API, implemented via `@RemoteAction` methods in the component's controller. The advantage of this mechanism is that no API calls are consumed. A disadvantage is that upsert is not currently implemented.
11+
The RemoteTK Visualforce Custom Component (comprising RemoteTK.component and RemoteTKController.cls) provides an abstraction very similar to the REST API, implemented via `@RemoteAction` methods in the component's controller. The advantage of this mechanism is that no API calls are consumed.
1212

1313
Alternatively, the ForceTK JavaScript library works around the same origin restriction by using the [AJAX Proxy](http://www.salesforce.com/us/developer/docs/ajax/Content/sforce_api_ajax_queryresultiterator.htm#ajax_proxy) to give full access to the REST API. Since the AJAX proxy is present on all
1414
Visualforce hosts with an endpoint of the form https://abc.na1.visual.force.com/services/proxy, our Visualforce-hosted JavaScript can invoke it, passing the desired resource URL in an HTTP header. A drawback here is that using the REST API, even from a Visualforce page, consumes API calls.

RemoteTK.component

+4-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ if (remotetk.Client === undefined) {
8383
* Creates a new record of the given type.
8484
* @param objtype object type; e.g. "Account"
8585
* @param fields an object containing initial field names and values for
86-
* the record, e.g. {:Name "salesforce.com", :TickerSymbol
86+
* the record, e.g. {Name: "salesforce.com", TickerSymbol:
8787
* "CRM"}
8888
* @param callback function to which response will be passed
8989
* @param [error=null] function to which jqXHR will be passed in case of error
@@ -113,34 +113,32 @@ if (remotetk.Client === undefined) {
113113
});
114114
}
115115

116-
/* NOT YET IMPLEMENTED!!!
116+
/*
117117
* Upsert - creates or updates record of the given type, based on the
118118
* given external Id.
119119
* @param objtype object type; e.g. "Account"
120120
* @param externalIdField external ID field name; e.g. "accountMaster__c"
121121
* @param externalId the record's external ID value
122122
* @param fields an object containing field names and values for
123-
* the record, e.g. {:Name "salesforce.com", :TickerSymbol
123+
* the record, e.g. {Name: "salesforce.com", TickerSymbol:
124124
* "CRM"}
125125
* @param callback function to which response will be passed
126126
* @param [error=null] function to which jqXHR will be passed in case of error
127127
*/
128-
/*
129128
remotetk.Client.prototype.upsert = function(objtype, externalIdField, externalId, fields, callback, error) {
130129
Visualforce.remoting.Manager.invokeAction('$RemoteAction.RemoteTKController.upser', objtype, externalIdField, externalId, JSON.stringify(fields), function(result){
131130
handleResult(result, callback, error, true);
132131
}, {
133132
escape: false
134133
});
135134
}
136-
*/
137135

138136
/*
139137
* Updates field values on a record of the given type.
140138
* @param objtype object type; e.g. "Account"
141139
* @param id the record's object ID
142140
* @param fields an object containing initial field names and values for
143-
* the record, e.g. {:Name "salesforce.com", :TickerSymbol
141+
* the record, e.g. {Name: "salesforce.com", TickerSymbol:
144142
* "CRM"}
145143
* @param callback function to which response will be passed
146144
* @param [error=null] function to which jqXHR will be passed in case of error

RemoteTKController.cls

+1-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public class RemoteTKController {
145145
return JSON.serialize(records[0]);
146146
}
147147

148-
/*
149148
@remoteAction
150149
public static String upser(String objtype, String externalIdField, String externalId, String fields) {
151150
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objtype);
@@ -161,11 +160,10 @@ public class RemoteTKController {
161160

162161
Schema.SObjectField sobjField = targetType.getDescribe().fields.getMap().get(externalIdField);
163162

164-
// Database.Upsert(obj, sobjField); // error - upsert requires a concrete sobject type
163+
Database.Upsert(obj, sobjField);
165164

166165
return null;
167166
}
168-
*/
169167

170168
@remoteAction
171169
public static String updat(String objtype, String id, String fields) {

0 commit comments

Comments
 (0)