Skip to main content Tableau Conference is happening now. Tune in to activate your data superpowers with Tableau and Agentforce. Watch live on SF+ for exclusive digital content, new product demos, and key insights for data and analytics lovers.
I am currently using following method to get authorization code

⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗

public PageReference sync(){ 

        

        settings = ConstantContactSettings.getData();

        

        PageReference ref = new PageReference(ConstantContactConstants.AUTH_ENDPOINT+

                                             'client_id='+settings.ClientID__c+

                                             '&redirect_uri='+settings.Redirect_URL__c+

                                             '&scope='+ConstantContactConstants.SCOPE+

                                             '&response_type='+ConstantContactConstants.RESPONSE_TYPE);

        

        return ref;

    }

⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗⌗

Issue is it refreshes the page. How can I use HttpGet Callout instead of this approach and how to add query parameters to endpoint URL?
5 answers
  1. Aug 14, 2024, 10:14 PM

    None of the above answers are very good from a security standpoint.    Or even just handling of special characters.   The following is method we use:

     

    /**

    * @description

    * Encode the URL for a GET call

    *

    * @param url base url to call

    * @param bodyMap the paremeters to encode

    * @return the encoded URL

    */

    private static String encodeUrl(String url,Map<String,Object> bodyMap ) {

    List<String> params = new List<String>();

    for(String key : bodyMap.keySet()) {

    String value = String.valueOf(bodyMap.get(key));

    if(String.isNotBlank(value)) {

    params.add(key+'='+EncodingUtil.urlEncode(value,'UTF-8'));

    }

    }

    if(! params.isEmpty()) {

    url += '?'+String.join(params,'&');

    }

    return url;

    }

    This still is not a great answer.  In that it does not handle things like properly appending query arguments if you already have query arguments.  It does not check for duplicate arguments.    Give me 10 minutes and I am sure I can find another half dozen flaws.

     

    Which is why developers should not have to write there own methods to do something this standard.  It should be part of the API.   In fact I still have a hard time believing it isn't, and I haven't just missed it.

Loading
0/9000