Posts

Showing posts with the label Saleforce API

Salesforce OAuth 2.0 "authorize" endpoint doesn't return refresh token

Problem: Salesforce OAuth 2.0 "authorize" ( https://login.salesforce.com/services/oauth2/authorize)  endpoint doesn't return refresh token Solution: The refresh token for the user-agent flow is only issued under one of the following circumstances: The redirect URL uses a custom protocol. The redirect URL is exactly  https://login.salesforce.com/services/oauth2/success , or on Sandbox,  https://test.salesforce.com/services/oauth2/success . The redirect URL uses the http protocol and the host is localhost - e.g.  http://localhost:8080/ References: http://salesforce.stackexchange.com/questions/7554/oauth-api-doesnt-send-refresh-token-with-custom-redirect-uri  https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_authenticate.htm&language=en_US

Sample code to upload a file to chatter feed using REST API

Image
Step 1: Download required files Download the following files from internet httpcomponents-client-4.2.3-bin.zip org.apache.commons.httpclient.jar From the files, I have added following JARS to my project in eclipse.    Screenshot from Ecclipse Step 2: Get Access Token Through Chrome Login to your Salesforce instance and navigate to Setup -> Create -> Apps.  Create a custom app and fill Client ID and CallBack URL (ex: http://www.google.com) in the following URL. Encode the CallBack URL before passing it as a parameter.  https:// <instance_name> .salesforce.com/services/oauth2/authorize?response_type=token&client_id= <Client_ID_Goes_Here> &redirect_uri= <CallBack_URL> Paste this URL in chrome In Developer Tool -> Network select "preserve log upon navigation" Load the page. We see below page. The page will take us to RemoteAccessAuthorizationPage.apexp which inturn will lea...

How to bundle multiple actions as a transaction using Salesforce API?

How to bundle multiple actions as a transaction using Salesforce API? At present, the only way to bundle multiple actions as a transaction in SFDC is to put all of them in an APEX method and make it a web service.  But, the problem one may encounter is with the arguments. The arguments tend to get misinterpreted or overlapped at Salesforce end. For example in the following definition  webService static String upsertData(string s,Id v, Id[] str) ,  if we pass v as null one of the str values is pushed into v variable. This situation is undesirable and results in unwanted results. So we should define a class defining all the argument we want to pass in a method. And use the class as an argument. This worked perfectly for me. Solution: global class xxxxxx{     global class yyyyyyy{         webService Attachment qAttach;      ...