Skip to main content

Posts

Showing posts from June, 2012

Force.com REST API getting token with curl

Force REST API usage with curl is really well documented, there are at least two official HowTO's, but both of the assume that you will get your OATH token with Java. Below I've described steps required to get the token and verify your token with curl. 1. Retrieve token curl -v -k https://DOMAIN.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=CONSUMER_KEY" -d "client_secret=CONSUMER_SECRET" -d "username=USERNAME" -d "password=USER_PASSWORDSECURITY_TOKEN" where: DOMAIN - is your salesforce domain (e.g. na9) CONSUMER_KEY, CONSUMER_SECRET - as taken from App Setup -> Develop -> Remote Access USERNAME, USER_PASSWORD, SECURITY_TOKEN - properties for the user that you want to connect with. Note that USER_PASSWORD and SECURITY_TOKEN are concatenated. Note that I used -k parameter in curl which results in the SSL certificate validation skipped (otherwise you need to add it or t

Visualforce - COUNT() vs COUNT_DISTINCT()

Having COUNT_DISTINCT() is a great advantage in apex over standard Salesforce reporting capabilities. Still what you need to remember is that it doesn't return Integer (as COUNT() is doing), but List<AggregateResult> with count stored in the expr0 attribute of the first element of the list. So while the following code is valid: public String getObjectsForSelectedApplication() { return String.valueOf([SELECT COUNT() FROM MyObjects__c WHERE Application__c = :selectedApplication]); } The following code will return a list: public String get UniqueUsersForSelectedApplication() { return String.valueOf([SELECT COUNT_DISTINCT(User__c) FROM MyObjects__c WHERE Application__c = :selectedApplication]); } What you need to do is take the count from the list, for example with the following code: public String getUniqueUsersForSelectedApplication() { List&ltAggregateResult&gt result = [SELECT COUNT_DISTINCT(User

Visualforce - actionSupport for hiding/showing elements of the page

While working on a Visualforce page that would automatically show/hide parts of its content I've stumbled upon problems with actionSupport. So the following code doesn't work (to be precise - the "details" pageBlock is not rerendered upon change in the select element): <apex:pageBlock> <apex:form> <apex:selectList value="{! selectedApplication}" size="1">  <apex:actionSupport event="onchange" reRender="details"/>  <apex:selectOptions value="{! availableApplications}"></apex:selectOptions>               </apex:selectList>  </apex:form>  </apex:pageBlock>  <apex:pageBlock id ="details" title="Details for {! selectedApplication}" rendered="{! NOT(ISNULL(selectedApplication))}">  </apex:pageBlock> After googling a bit I've stumbled upon posts suggesting that this happens if you try to rerender page