Module

Salesforce.RemoteAction

Package
purescript-sforce-remote-action
Repository
Woody88/purescript-sforce-remote-action

#Visualforce Source

data Visualforce

Data type which holds remote action visualforce object and config details

Constructors

#JSVisualforce Source

data JSVisualforce :: Type

Represents Salesforce's Visualforce remote action object.

#ApexController Source

type ApexController = String

Name of apex controller including namespace (fully qualified remote action name) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_namespaces.htm

#ApexControllerArgs Source

#VisualforceConfProp Source

type VisualforceConfProp = (buffer :: Boolean, escape :: Boolean, timeout :: Int)

Configuration data structure details based on Visualforce Developer Guide https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_configuring_request.htm

#ErrorMsg Source

#ErrorTrace Source

#RemoteActionError Source

#RemoteAction Source

class RemoteAction act (ctrl :: Symbol) args res | act -> ctrl args res

Credit to Robert Porter (robertdp github name) who came up with this approach. This type class represents a RemoteAction that has types for an action, controller, arguments, and result. The controller name is a Symbol not String The action type is a regular data type that one can define which will give meaning to the action. Based on Robert's approach based on the action type we can determine what controller should be called, what are the args that this controller accepts, and also what type of result it returns. Example:

data GetPCMRecords = GetPCMRecords

instance remoteActionGetPCMRecords :: RemoteAction GetPCMRecords "PCMController.getRecords" args result

args and result should be concrete types with Encode and Decode instance respectively.

#getVisualforce Source

getVisualforce :: Record VisualforceConfProp -> Maybe Visualforce

Returns a Visualforce type with configs provided

#callApex Source

callApex :: Visualforce -> ApexController -> ApexControllerArgs -> Aff (Either RemoteActionError Foreign)

Function which performs requests using Visuaforce (JS Object) created by Salesforce platform

#invokeAction Source

invokeAction :: forall act ctrl args res m. RemoteAction act ctrl args res => MonadReader Visualforce m => MonadAff m => MonadError RemoteActionError m => IsSymbol ctrl => Encode args => Decode res => act -> args -> m res

Function that invoke the action defined by referring to contraints which holds details about the correct controller to invoke. Example:

data PCMRequests = ..

data CreatePCMRequests = CreatePCMRequests

instance remoteActionCreatePCMs :: RemoteAction CreatePCMRequests "PCMMassController.createRecords" PCMRequests Unit

createPCMRequest :: Visualforce -> PCMRequests -> Aff (Either RemoteActionError Unit)
createPCMRequest vf rec =  runReaderT (runExceptT $ invokeAction CreatePCMRequests rec) vf