Oh my god. It's full of code!

Ask Me

Now I’m certainly not saying I’m the end all be all Salesforce/Coldfusion/Web Development guru. I just sort of hack along and figure out things one line at a time. That said, I’ve been doing it for a while and have figured out a fair amount of things. So if you have a question, especially one you think might make a good blog post, shoot it over to me. I’ll do my best to answer it (if I can) and maybe even exploit it and use it as content for my blog 😛 Just shoot me an email Kenji776@gmail.com and include AskKenji in the subject line.

40 responses

  1. Hello,

    I’ve just come across your blog and I think (hope!) you’ll be able to help?

    I’ve just set up a developer account after using salesforce for 2-3 years now. I’m trying to set up a date field on the accounts page which can tell me when the account’s website page was last updated. I believe the coding is “javascript:alert(document.lastModified)” that i need to use but with having so many things to do i can’t work out how to actually set this up, can you help?

    I look very much to hearing back from you

    Thank you


    May 24, 2011 at 11:14 am

    • Hey Hayley, I’d be happy to try and help. So you have a date field set up, and you want to populate that with the last modified date of something else. This is where I got a little bit confused. What exactly are you trying to put in there? It sounds like you want to get the last modified date from a website that is related to the account? So do you have a URL that you want to access and try to find the last modified date of that page, or is there another salesforce object you are attempting to get a date from? Sorry if I’m being dense, it’s early and I haven’t
      had my coffee yet 😉

      May 24, 2011 at 2:50 pm

  2. Thank you, i really appreciate it. I’m right at the beginning so I don’t even have a date field set up yet. We’ve got the URLs on each account and i’d like to have a field where the last modified date is shown on each accounts website……….does that make sense?! You are right with your comment “So do you have a URL that you want to access and try to find the last modified date of that page”
    No problem, i just appreciate the help!

    May 24, 2011 at 2:57 pm

    • Hayley, if I am understanding you correctly, I’m not sure there is really a great way to accomplish what you want. You would essentially need to write an apex trigger that performs a get request using the URL found on the account object, and try to find the text in there that says ‘last modified’ then attempt to parse the data afterwards. Do you control these sites? Cause otherwise there is no guarantee that such data would even exist. I know on files, the operating system does keep track of last modified dates, but I don’t think that data is available when the file is being served via a web server. Also, sorry for the delay, been pretty busy recently, and I didn’t get notified when this comment got posted.

      May 28, 2011 at 7:05 am

      • Hm, the last modified date is available via javascript as you suggested. The tricky part is how to programatically invoke that javascript against a remote host. That’s a bit of a head scratcher. I might have to think on that one for a bit and putz around with a few things.

        May 28, 2011 at 7:08 am

      • One possibility (and this would be very hackish) is to have a visualforce component embedded that has an iframe that loads the requested site, and runs that bit of javascript against the iframe. I don’t know for sure if it would work, but it might be a jumping off spot.

        May 28, 2011 at 7:11 am

  3. Thank you very much for your help. That sounds very complicated, i think i might just leave it. I’m only a beginner at this, it would be handy for our company but never mind. Thank you again for your help

    May 31, 2011 at 2:35 pm

  4. Michael Fitzgerald

    Hey man, I ran across your blog and I was looking to build a calendar. The Download doesn’t appear to work. Insights? Thanks

    January 17, 2012 at 11:44 pm

    • I will be posting the code to my new calendar within the next day or two. It’ll be a fairly simple unmanaged app installable in your org, I’ll also just post just the basic source as well. Hang tight and I’ll have something soon.

      January 18, 2012 at 3:37 pm

    • Ask and you shall receive. Your comment was the kick in the ass I needed to get something deployable. Check my newest blog entry for details.

      January 18, 2012 at 6:14 pm

  5. JIE

    Hi Kenji,

    I have read some articles about Salesforce in your bolg. So I have a question want to ask you, I think maybe you can give me some advices.

    I want to ues jquery.ajax method to invoke the apex class.
    These jquery codes are written in a HTML page not a visualforce page. I have some method to get the access_token based on the OAuth 2.0.
    Then I follow your article (https://iwritecrappycode.wordpress.com/2011/07/08/salesforce-rest-api-musings/) create a apex to listen my request. I use curl to test this class and successful.
    So, I think I can use jquery.ajax do the same thing.

    I post the same question on force.com boards, you can see the detail at there.(http://boards.developerforce.com/t5/Apex-Code-Development/Ues-jquery-ajax-to-invoke-apex-class/td-p/394713)

    Do you have experience on this?

    Thank you!

    February 8, 2012 at 4:07 am

    • Hey there. Just wanted to let you know I’m writing up a blog post on how to do this. It should be ready soon, so check back shortly!

      February 8, 2012 at 4:16 am

      • JIE

        That’s great!
        Looking forward your blog!

        February 8, 2012 at 4:58 am

  6. JIE

    Hi Kenji,

    Do you have experience about use jquery to send a request to an external service in Visualforce page?
    I try to use jquery.ajax to achieve this goal, but so far the code doesn’t works well.
    Have a look with my javascript:

    contentType : ‘application/json’,
    error: function(XMLHttpRequest, textStatus, errorThrown){
    alert(“textStatus : “+textStatus);
    alert(“status : “+XMLHttpRequest.status);

    I receieve the response with error method:
    textStatus : error
    XMLHttpRequest.readyState : 0
    XMLHttpRequest.status : 0

    So, do you have any suggestion about this?

    Thank you!

    April 16, 2012 at 6:45 am

  7. pankaj

    Hi Kenji, How are you ?

    After googling I landed to your blog. After reading some them, i thought you could help me to start with cloudspokes. I have few questions uncleared, please help me out.

    – How to setup cloudspoke development on local machine ?
    – What are the tools can be used for development and testing ?
    – Guidelines to start with cloudspoke.

    Appreciate your help.

    Thank you,

    September 30, 2012 at 6:54 pm

    • Hey pankaj. I think you might be a bit confused. Cloudspokes isn’t a development environment or language. It’s a website that holds programming competitions focused around cloud development. The challenges are all different and require different IDE’s and tools. Some challenges use Ruby, other’s use Node.js, some are straight javascript, the list goes on and on. So there isn’t a one step setup or anything to get started. For local tools I use lots of stuff. Mongoose webserver for javascript apps that require JSON feeds, foreman for testing node.js apps, and of course just my web browser. Other than that all force.com stuff pretty much has to be uploaded and tested in a sandbox. As for the guidelines, check our their FAQ page for more info. Hope this helps.

      October 1, 2012 at 3:05 pm

  8. santosh r

    Hi Kenji,
    After referring all possible web references for my issue, i end up by keeping hopes on you/your blog. We are having a requirement to access local file(desktop) from SFDC Button/Tab/Link. Please help me to implemet this req. Thanks in Advance.

    November 30, 2012 at 5:06 am

  9. karan kumar

    i have problem if you could help. i made a approval process sending an E- mail to the client. I used the salesforce email services. The message is getting correctly send. The other thing i needed was that if the client recieves the mail and replies to the mail in the same window(gmail, yahoomail, etc) as “approved” or “rejected” along with some comment, that should approve the record and the comment get saved in some field on the record. The problem arising is that the mail sent by client through the web browser is entering into the salesforce along with the html tags in the body. i dnt want them. I cant ask my client to write the mail in plain text using botepad and than sending it. what can i do to overcome this problem.

    January 24, 2013 at 5:28 am

  10. jim simpson

    Hi. I saw you worked on a mobile web based silent auction platform. Is that a working product? We’re looking for one for auto dealerships….

    March 30, 2013 at 6:26 pm

    • I did indeed. I won that contest, so I’m not allowed to distribute the code, however cloudspokes may be hosting it in their github repo. You can also contact them about getting rights to use that code.

      March 30, 2013 at 6:29 pm

      • jim simpson

        Thanks Kenji776. We’re not coders or developers here but need such a platform “ready to use”. Any ideas suggestions where to go that can handle that?

        March 30, 2013 at 6:32 pm

      • I would honestly contact cloudspokes about licensing out their existing system. My guess is that they would be happy to help you out. If not, let me know and maybe we can work something out. I am not aware of any other ready to use auction system that is mobile ready but I don’t spend a ton of time researching such things either.

        March 30, 2013 at 6:37 pm

  11. jim simpson

    will do, and thanks…I’ll get back to you if I hit a wall

    March 30, 2013 at 6:38 pm

  12. jim simpson

    Kenji…all Greek to me…no ability to work on this level, but need someone that can to work with us. If anyone is available…do NOT hesitate to give me a shout. Thanks

    March 30, 2013 at 6:47 pm

  13. hey , i want to implement time of calender in visualforce & display the all requested day fields in calender on selected date , how do this ? please would you tell me ?

    August 1, 2013 at 9:02 am

  14. i want to implement time of calender in visualforce & display the all requested day fields in calender on selected date , how do this ? please would you tell me ?

    August 1, 2013 at 9:11 am

  15. Simha

    Hello Kanji,

    This is with respect to Captcha code which you have provided . This was really helpful,but I dont know whats wrong but its not working, I am not able to get how to pass my Save method after the verification . When i try to do so its throwing error “Unknown property ‘testCaptchIController.createOpp” . Below is the code

    https://www.google.com/recaptcha/api/noscript?k= MYKEY


    January 13, 2014 at 10:51 am

  16. Angel

    Hi Kanji,
    I saw your blog and thought it is very helpful. I have a questions regarding sites.com and wondering if you could help me with it? We are trying to add(embed) visualforce pages into sites.com, with the new salesforce updates is this possible?

    Angel Hong

    October 28, 2014 at 5:08 pm

  17. lalit

    hi , your blog i very nice.

    I have a requirement like this could you please help me with this……

    i am working on one requirement which is i have an published article and on that article i have a rich text area field and its name is “content” so what i need is i want to write a rest service that will convert the contents of that article like links,images into base 64 / binary data as in a pdf

    October 31, 2014 at 8:18 am

  18. Anonymous

    Hi Kenji,

    I was developing Controller Extension as how you did on OrchestraCMS Page Template. (Controller extension to cms.CoreController.)

    May I know how can I perform a form submission and redirect back to its current page? I believe we need to crack on cms.CoreController. Any light will help.


    November 14, 2014 at 10:54 am

  19. Invoking a class on a workflow. I have written this by leveraging your code. I am getting an error with your code and mine on the decode when setting the element. See code below. ( elementValue = getDecodedString(reader);)

    global class ProcessWorkFlow implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
    // declare the result variable
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    // declare a string variable to catch our custom debugging messages
    String myErr;
    result.success = true;

    // extract the email body : either the htmlBody or the plainTextBody
    String msgObject = ”;
    String messageBody = ”;
    String messageContent = ”;

    messageBody = email.plainTextBody;
    messageBody = messageBody.trim();

    //Extract just the XML portion of the message
    //messageBody = messageBody.substring(messageBody.indexOf(”),messageBody.indexOf(”)+12);

    msgObject = readXMLelement(messageBody,’objectName’);
    msgObject = msgObject.replaceAll(‘\\D’,”);

    messageContent = readXMLelement(messageBody,’message’);

    if(messageContent.length() > 155)
    messageContent = messageContent.substring(0,155);

    MessageServices__c message = new MessageServices__c(Object__c = msgObject, Message_Content__c=messageContent, Original_Message__c =email.plainTextBody);
    insert message;


    catch(exception e)
    Error_Logging__c log = new Error_Logging__c();
    log.trace__c = e.getTypeName() + ‘\n’ + e.getCause() + ‘\n’ + e.getMessage() + ‘\n’ + e.getLineNumber();
    insert log;

    return result;

    public static String readXMLelement(String xml, String element)
    String elementValue = ‘NOT FOUND’;

    Xmlstreamreader reader = new Xmlstreamreader(xml);
    while (reader.hasNext())
    if (reader.getEventType() == XmlTag.START_ELEMENT && reader.getLocalName() == element)
    elementValue = getDecodedString(reader);
    return elementValue;
    catch(exception e)
    Error_Logging__c log = new Error_Logging__c();
    log.trace__c = e.getTypeName() + ‘\n’ + e.getCause() + ‘\n’ + e.getMessage() + ‘\n’ + xml;
    insert log;

    string err;
    err = e.getTypeName() + ‘\n’ + e.getCause() + ‘\n’ + e.getMessage() + ‘\n’ + xml;
    return err;

    April 21, 2015 at 9:46 pm

    • You can email me using the address above. Please include the error you are getting and any relevant screenshots that might help.

      April 21, 2015 at 9:53 pm

  20. Vaibhav

    Can anyone please provide me with the code to freeze headers in excel export done from a visualforce page. Like freeze panes when the Vf page using content type to export it in excel

    July 16, 2015 at 5:32 pm

  21. Angello Camacho

    Hi, I hope you can help me, I am trying to export a query to an excel file xls, but If the query has many records I get this error “Response size exceeded 15MB organization limit”, do you think you can help me?


    January 4, 2017 at 9:13 pm

    • The best I can suggest is to break your query into a limited number of records, and loop over the result set. Then instead of attempting to write it all in one go, you can write multiple files and concatinate them later. Or perhaps you could write the results to a stored document within salesforce and append each result set? If you get real stuck I might be able to whip up a proof of concept (if it is even viable, I’m not sure).

      January 6, 2017 at 10:11 pm

      • Angello Camacho

        Hi Kenji, thanks for your reply, I think the second option is better but how I can write in the document with apex I don’t know how to open the excel file and then write the results.


        January 6, 2017 at 10:20 pm

  22. Writing an excel file can be as difficult or as easy as you make it. My go to approach is to write a CSV file which excel can usually handle pretty easily. I’ve got a post on creating CSV files. So what I’d do is create a document at the beginning of your process. Then in each batch of your query results update it with your new data.

    Check out

    for info on creating a document.

    Also see my post

    on export query content as a CSV. Instead of writing the content out to a visualforce page, you can just append to your document you create. You might run into heap limit problems, but we can cross that bridge when we come to it.

    January 6, 2017 at 10:38 pm

  23. Hi
    I am making a simple https get cal.
    But getting the following error:
    {“message”:”Session expired or invalid”,”errorCode”:”INVALID_SESSION_ID”}]
    I am using following headers:
    req.setHeader(‘Authorization’,’Bearer ‘+UserInfo.getSessionID());
    req.setHeader(‘Content-Type’, ‘application/json’);

    Please help me

    June 23, 2017 at 7:46 am

  24. Hey Dan,

    I have just come across your awesome solution to Lightning’s DataTable not handling nested objects; your Salesforce Lightning DataTable Query Flattener. I need to display a nested object within a field in a datatable – may I use your solution in a work project?

    Kind regards,
    Jack 🙂

    September 6, 2018 at 1:27 am

  25. sulagna das

    I went through your Data Category Tree View logic. I would however also like to display the related articles in the same tree view as well. Could you please help.

    January 31, 2019 at 11:42 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s