Last active
March 25, 2018 03:57
-
-
Save Woody88/0921abcf290d7d13d93adab210dd2571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This function uses getSObjectRow to get an Account by id number. | |
-- The (Proxy @Account) just tell the function what we are expecting back (of course an Account). | |
-- | |
getAcc :: IO (Either ServantError (SObject Account)) | |
getAcc = do | |
(Right client) <- sfclient | |
getSObjectRow (SObjectId "0016A00000JcdjK") (Proxy @Account) client | |
-- This a helper function for the updateAcc. It just retrieves an account | |
-- and return the account with the sfclient as a tuple. | |
acc :: IO (SObject Account, SFClient) | |
acc = do | |
(Right client) <- sfclient | |
(Right h) <- getSObjectRow (SObjectId "0016A00000JcdjK") (Proxy @Account) client | |
return (h, client) | |
-- If the update succeeds salesforce will just return a status 200 wih no body. | |
-- Hence the reason for NoContent. We use the updateSObjectRow function to uppdate | |
-- the Account that is modified. | |
updateAcc :: IO (Either ServantError NoContent) | |
updateAcc = do | |
(SObject (objId, objData), client) <- acc | |
updateSObjectRow objId (updateName $ sobject objData) client | |
-- Function that changes the name of an account to "NewAccount4" | |
updateName :: Account -> Account | |
updateName acc = acc { name = "NewAccount4" } | |
--- The deleteSObjectRow accepts and Id and we must tell what type of | |
--- SObject this id belongs to. | |
deleteAccount :: IO (Either ServantError NoContent) | |
deleteAccount = do | |
(Right client) <- sfclient | |
deleteSObjectRow (SObjectId "0016A000JcdjK") (Proxy @Account) client | |
----- Display of getAcc Execution ----- | |
λ> (Right account) <- getAcc | |
*AccountExample | |
λ> account | |
SObject (SObjectId "0016A000JcdjKQAR",SObjectData {attributes = SObjectAttr {sobjectType = SObjectType "Account", sobjetUrl = "/services/data/v42.0/sobjects/Account/0016A000JcdjKQAR"}, sobject = Account | |
{name = "NewAccount4"}}) | |
λ> getSData account | |
SObjectData {attributes = SObjectAttr {sobjectType = SObjectType "Account", sobjetUrl = "/services/data/v42.0/sobjects/Account/0016A000JcdjKQAR"}, sobject = Account {name = "NewAccount4"}} | |
*AccountExample | |
λ> sobject . getSData $ account | |
Account {name = "NewAccount4"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment