• Kevin Akermanis
  • 50 Points
  • Member since 2015
  • Principal Solution Engineer
  • Salesforce.com

  • Chatter
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 6
why we should use the validations for restricting the users based on thier profile name not based on their profile id ?
why we should use the validations for restricting the users based on thier profile name not based on their profile id ?

apex:page controller="TwitterListApi" 
<br/><br/> <h1>
Please Press the button to get the List of Twitter Account Users</h1><br/><br/> 
apex:commandLink value="Submit" action="{!Submit}" target="_blank" styleClass="btn"/


apex:page controller="TwitterListApi" showHeader="false" sidebar="false" action="{!generatecsv}" contentType="application/octet-stream#Twitter_Acoount Information.csv">User Name, Name, Location, Mobile
    apex:repeat value="{!Generate}"
       {!screenname}, {!username}, {!location}, {!mobile}
Apex Code:

public class TwitterListApi
    public String oAuthConsumerKey = 'BlsoC839h5czptk6oHyyAgTGq';
    public String oAuthConsumerSecret = 'iAF4rc2AFEOP1h9rNVx4ZM8B86GXo4IGPcl2DN67iiMi6mdxnu';
    public String oAuthUrl = 'https://api.twitter.com/oauth2/token';
    public String oAuthUrl_1 = 'https://api.twitter.com/1.1/users/lookup.json?screen_name=';
    public String username{get;set;}
    public String location{get;set;}
    public String mobile{get;set;}
    public String screenname{get;set;}
    public String stoken;
    public List<Companies> list_com;
    public pageReference Submit()
        pageReference pageRef= new pageReference('/apex/GenerateListApi');
        return pageRef;
    public pageReference generatecsv()
         String name;
         List<username__c> list_user;
            list_user=[select name__c from username__c];
        catch (System.QueryException e)
            system.debug('Error in generatecsv method for list_user query** '+e);
        for (username__c user:list_user)
           if (name==null)
              String url=EncodingUtil.urlEncode(user.name__c,'UTF-8');
               String url=EncodingUtil.urlEncode(user.name__c,'UTF-8');
        system.debug('name** '+name);
        //Encode them
        String keyencoded = EncodingUtil.urlEncode(oAuthConsumerKey, 'UTF-8');
        String secretkeyencoded = EncodingUtil.urlEncode(oAuthConsumerSecret, 'UTF-8');

        //Create Final Key String
        String sFinal = keyencoded + ':' + secretkeyencoded;
        //Convert to Blob
        Blob headerValue = Blob.valueOf(sFinal);
        system.debug('headerValue** '+headerValue);

        //Build Request
        HttpRequest req = new HttpRequest();

        //Add Auth Header
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        system.debug('authorizationHeader** '+authorizationHeader);

        //You need to add this to the request - proved easy to miss in instructions...

        //Make request
        Http http = new Http();
        HTTPResponse res = http.send(req);
        system.debug('Body_1** '+res.getBody());           
        //String stoken;
        //Parse JSON for Bearer Token
        JSONParser parser = JSON.createParser(res.getBody());
        while (parser.nextToken() != null) {
        if (parser.getCurrentToken() == JSONToken.FIELD_NAME && parser.getText() == 'access_token'){
        stoken = parser.getText();
        catch(System.CalloutException e)
            system.debug('Error_1** '+e.getMessage());
    HttpRequest req2 = new HttpRequest();
    //I actually store the endpoint in the same custom setting and build dynamically, but for purposes of demo:
        req2.setEndpoint(oAuthUrl_1 + name);

    //Call Bearer token Method
    //Note - unless invalidated, I believe you can store this and keep using it indefinitely, but again, to demo concept
    String authorizationHeader_1 = 'Bearer ' + stoken;
    req2.setHeader('Authorization', authorizationHeader_1);
    system.debug('authorizationHeader_1** '+ authorizationHeader_1);

    HTTPResponse res = http.send(req2);
    String sBody = res.getBody();
    system.debug('Body_2** ' + sBody);
    boolean success=true;
    JSONParser parser=JSON.createparser(res.getBody());
    while (parser.nextToken()!=null)
        if(parser.getCurrentToken()== JSONToken.START_OBJECT)
            while (parser.nextToken()!=null)
                if((parser.getCurrentToken()==JSONToken.FIELD_NAME) && (parser.getText()=='screen_name'))
                    system.debug('screenname** '+screenname);
                if((parser.getCurrentToken()==JSONToken.FIELD_NAME) && (parser.getText()=='name')) 
                    system.debug('username** '+username);
                integer i = 0;
                if((parser.getCurrentToken()==JSONToken.FIELD_NAME) && (parser.getText()=='location'))
                    location = '"'+location+'"';
                    system.debug('location** '+location );
                if (success)
                    if ((parser.getCurrentToken()==JSONToken.FIELD_NAME) && (parser.getText()=='description'))
                        system.debug('mobile** '+mobile);
                        List<Companies> list_com=new List<Companies>();
                        Companies com=new Companies(screenname, username, location, mobile);
                        system.debug('com** '+com);
                        system.debug('list_com-1** '+list_com);
    catch(System.CalloutException e)
        system.debug('Error_2** '+e.getMessage());
        return null;
    public List<Companies> getGenerate()
        system.debug('list_com** '+list_com);
        return list_com;
    public class Companies

        String screenname;
        String username;
        String location;
        String mobile;
        public  Companies(String screename, String username, String location, String mobile)

Q1 I am getting null in list_com in a method  getGenerate().

Please solve my query?
This may be a stretch but I'm hoping for someone to help me write a trigger.

We have a lookup field on accounts that filters on related contacts.  Based on a series of conditions being met when a record is edited, we'd like to insert into that field the Contact ID for the related contact with title = Owner.

Conditions to be met are:
Steps_to_Close__c = "Enrolled" - picklist field
Number_of_clients__c = 0 - number field
Franchise_Association__c = Null or "HCA" - picklist field

Field to update:
PM__c to be equal to the contact ID for the related contact whose title = "Owner.

Hoping someone can help a guy with not many resources....


I'm using svg and use tags in a lightning component. I get the error:
Failed to save undefined: No COMPONENT named markup://use found

For the code: 
<svg aria-hidden="true" class="icon icon--large icon-standard-user">
                  			<use xlink:href="assets/icons/standard-sprite/svg/symbols.svg#user" />

What am I doing wrong here?


I am suffering with Salesforce apex LimitException issue. I am fetching thousands of records from few objects and putting it into the collection like Map. Now I have a requirement to generate JSON for same records which will be used for mobile devices to download data from salesforce.
When I tried to serialize those records by using System.JSON.Serialize() method; it is generating a huge JSON string and I am getting System.LimitException error because there will be more memory required than available space.
I tried to catch that issue using try/catch block but here is a reference available which says that System.LimitException can’t be caught by Catch block.
Referral URL: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_exception_methods.htm
I know that we can check heap size limit through Limits.getHeapSize() method. But is there any work around so that I can handle this issue from apex side.
A code sample or some reference in this regard would be highly appreciated.
Thanks in advanced.