Last active
August 10, 2018 21:28
-
-
Save Woody88/72c37a07ecec0de3fc8a8a0b6173f350 to your computer and use it in GitHub Desktop.
Update RFQ using purescript-sforce
This file contains hidden or 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
| module Main where | |
| import Prelude | |
| import Data.Either (either, Either) | |
| import Data.Generic.Rep (class Generic) | |
| import Foreign.Generic (genericDecode, defaultOptions) | |
| import Effect (Effect) | |
| import Effect.Class (liftEffect) | |
| import Effect.Aff (Aff) | |
| import Effect.Console (log, logShow) | |
| import Simple.JSON as JSON | |
| import Salesforce.Connection as SF | |
| import Salesforce.Types | |
| newtype Account = Account | |
| { "Status__c" :: String | |
| , "Id" :: String | |
| } | |
| derive instance newtypeAccount :: Newtype Account _ | |
| derive instance genericAccount :: Generic Account _ | |
| instance jsonAccount :: JSON.ReadForeign Account where | |
| readImpl = genericDecode $ defaultOptions {unwrapSingleConstructors = true} | |
| main :: Effect Unit | |
| main = do | |
| rfq <- rfqData | |
| launchAff_ $ do | |
| eitherCancelled <- cancelRFQ rfq | |
| liftEffect $ either (alert "Failed to save") (reload window) eitherCancelled | |
| cancelRFQ :: forall rfq. rfq -> Aff (Either SF.RequestError SF.RecordResult) | |
| cancelRFQ rfq@{status_check: false} = alert "Cannot cancel" | |
| cancelRFQ rfq = do | |
| sessionId <- getSessionId | |
| conn <- liftEffect $ SF.mkConnection { accessToken: sessionId } | |
| runSalesforceT conn $ do | |
| try $ updateAccount (Account rfq) | |
| updateAccount :: Account -> Salesforce SF.RequestError SF.RecordResult | |
| updateAccount (Account acc) = Conn.update (sobjectName "Account") (Account $ acc {"Status__c" = "Cancelled"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment