Jun 14, 2011

Visualforce Code Generator

We know how much important role visualforce plays in our application. There are many instance where we need to create a visualforce page and apex class. Salesforce provides powerful tools like workflows, approvals, validation etc. from which we can implement our business functionalities with just button clicks.


Now I was having a requirement where I need to create many visualforce pages, some are custom and some are cloning native page with native layouts with some small changes. This just clicked me to create a tool from which we can create a visualforce page code with just clicking buttons. Yes!! Visualforce page code with button click.


This saved a lot of time, as I do not need to write any thing to create a heavy visualforce page and amazingly it is done just using button clicks.


Install the package : https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Pqos


Just append "/apex/vfgenerator__codegenerator" in URL.


Now let me jump into the explanation what exactly I have done. A simple UI will be displayed, where user can select the desired type of page, object name, record type, email field.






Object Name : Valid object API name (include namespace if any)
Record Type : Record type Id of object selected in Object Name
Type of Page :


  1. Edit : Code will be generated for the edit page of the object (according to "record type" layout if selected any).
  2. Detail : Code will be generated for the detail page of the object (according to "record type" layout if selected any)
  3. Custom Detail : Code will be generated for detail page according to the fields selected from UI
  4. Custom Edit : Code will be generated for edit page according to the fields selected from UI
In the above screen I have selected "Edit" as the type of page and "Account" in object, also provided my email. When I click "Generate Code" it displays like this :


Just copy the code and paste it in new visualforce page. Why I have given my email id because when you paste the code in visualforce page it will loose all the formatting and will display in one single line, but code sent on email will come with formatting. So we can copy the generated code from email also. Now when you hit the newly created visualforce page it will display all fields in edit mode which are displayed on native edit page. Isn't that good?

Now lets try creating some custom visualforce page. Select "Custom Edit" in "Type of Page" and "Account" in "Object Name". It will display a section "Select Fields". Click on "Display Fields", it will display all fields which are up datable by present user.



Select some fields and click on  "Generate Code". Again copy paste the code in your visualforce page, it will display selected fields in edit mode.

Now heavy visualforce pages are created with just button clicks.

Package provided is managed because the tool is under testing and I would like to have feedback from you. Once it is free from all bugs I will provide the code.


Declaration: You may find similar post related to "Visualforce Code Generator". The end result may be similar but there is a considerable difference in the approaches being followed here. So I, hereby declare that my project is entirely my own creation and has not been copied from any other person/organization's words or idea. Please feel free to drop me an email at "arora.salesforce@gmail.com" if there is any disagreement.

Cheers

63 comments:

  1. This looks fantastic Ankit! Hope to use it soon, will let you know how i get on with it.

    Mitz.Chauhan@gmail.com

    ReplyDelete
  2. Just install the package on your organization :

    https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Pqos

    And use http://......../apex/vfgenerator__codegenerator in URL.

    Let me know if you face any problem.

    ReplyDelete
    Replies
    1. Really its Amazing and saves lot of time.

      Delete
    2. hello ankit i installed and appended but package not found error i am getting

      Delete
    3. hi ankit i didnt find that code genrator option in my account plz tell me the step..i install package ..

      Delete
  3. Great job dude....keep up the great work....really cool

    ReplyDelete
  4. Amazed by the thought u have put in to create this tool....It will definitely help a lot of guys....If you are planning to extend it to custom controllers and need help....u can ping me and i can help you out if its a lot of burden on you. Anyways good luck....

    ReplyDelete
  5. Thank you so much, this is appreciable !! Just waiting for the feedbacks/suggestions from all. After implementing all I will distribute the code too, so a particular can do changes accordingly.

    If you have any ideas related to this do mail me or add me, would love to have a chat with you over this.

    arora.salesforce@gmail.com

    ReplyDelete
  6. This is extremely good thought.. Hope salesforce listens and implements some thing big based out of this.

    I am also thinking to create some plugin on top of Force.com Eclipse IDE. But doing directly using Apex is great.

    Can you share the code for us or make it open source project in Google Code so everyone can contribute?

    My idea is to create a plugin in Eclipse where users can drag and drop fields and components to create Visual Force page. Just like JSF, GWT or any other editors out there in market.

    Great Ankit.

    ReplyDelete
  7. Thank you so much !! I am also looking forward if salesforce can implement this kind of thing where we can create visualforce pages and apex classes with just button clicks or drag and drop.

    ReplyDelete
  8. And I will provide the the code as open source once I will have a satisfactory feedback. I just want to make sure that this tool must be error/bug free.

    ReplyDelete
  9. Have you thought about putting the generated Visualforce code in a <textarea> HTML Tag, this will look formatted and should not need the email :-)

    ReplyDelete
  10. Great !! But 32K character limit won't be a problem???

    ReplyDelete
  11. Excellent approach! Here I would like to suggest that when I select custom Edit mode then all required fields should be highlighted for easy to use.(Because without selecting required field I would be unable to save record and I have to come back for generating code again by including required fields)

    ReplyDelete
  12. Indeed a good suggestion !! Thanks Sandeep, I will surely consider this.

    ReplyDelete
  13. hey how easy is it to create the plugin to drag and drop components in eclipse....could we achieve....if yes, can someone provide the necessary starting steps....

    ReplyDelete
  14. Very cool! I wonder if it would be possible to use the metadata API to (1) find the record type id from the object name and (2) push the VF page into your org? It would be great if you could automate it so that the 'Generate Code' page did all that and just took you straight to the VF page :-)

    ReplyDelete
  15. Thank you for the awesome suggestions!! I am already working to push the VF page, but fetching record type was no where in my mind.

    Thanks again.

    ReplyDelete
  16. One More thing I would like to share that It would be more easy to use this tool if you provide a dependent picklist(depends on obj) in place of text field for recordtype Id (because it is very lengthy process to fetch recordtype Id by query or by any other way)

    ReplyDelete
  17. Looks Very Good Ankit.
    you Did Good job.

    ReplyDelete
  18. Really cool Ankit !! Great job !!

    ReplyDelete
  19. Really great Ankit, good work. This opens up all kinds of possibilities for speeding up Dev work.

    I can see this becoming the future of development for creating totally customized

    Do you have plans to extend this to creating custom components, such as the "homepage Dashboard" component?

    ReplyDelete
  20. Thanks for the good words Sumsum!! Am working on some extensions with this, coming soon !!!

    ReplyDelete
  21. Great work Ankit. Appreciate this !!

    ReplyDelete
  22. that's awesome dude. I was looking out for apex classes written for a particular standard object. If I need to write the class for "view all accounts page"; where would I get that from. Does your package include apex code for classes too?

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. This is freakin' awesome!!!! You have saved us all SOOOO much time and effort.

    One issue I found. I was getting "Error: Invalid field name for SObject QuoteLineItem" when trying to save the code until I removed subtitle="{!QuoteLineItem.name}" from the

    Great work. Keep it up

    ReplyDelete
    Replies
    1. it cut off the rest of my sentence. I removed subtitle="{!QuoteLineItem.name}" from the apex:sectionHeader and it fixed the issue.

      Delete
  25. Hi i need to search/create accounts and contacts from linkedin into salesforce..... and display it in Visual Force. Any Idea of how to implement this

    ReplyDelete
  26. i have created a search visual force page,all records are displayed there.so I want to send email to those records which are present .Because we cant use workflows here

    ReplyDelete
  27. Cool, it saved a lot time for me. Thanks Ankit.

    ReplyDelete
  28. Aaaaaaaawww maaaaan! This doesn't work with Custom Objects, only Standard Objects.

    ReplyDelete
  29. Fantastic!!! Just what I was looking for. It DOES do custom object, but it's a bit quirky. First choose the Type of Page you want, THEN type the API object name, (mine was Scope__c) then click in the record type box so it refreshes.

    Then click Generate Code.

    One weird thing I had was that I could only install it in my developer org, not my config sandbox. But that's not a huge deal.

    Thank you so very much for this.

    ReplyDelete
  30. Sir ,This is One sound Good .Thanks .But I want to to generate Vf code for Console.How ???

    ReplyDelete
  31. Its really good job
    Thank you so very much
    Thank you so very much for this article

    ReplyDelete
  32. bro its working i am impressed .....................


    thank you so much for sharing this app.

    ReplyDelete
  33. This worked perfectly and was exactly what I needed...especially for one who's very new to Visualforce. Thank you so much!!

    ReplyDelete
    Replies
    1. Try this out : http://forceguru.blogspot.in/2015/03/visualforce-code-generator-coding-via.html

      Might help more :-)

      Delete
  34. Very good tool for beginners...Great Job..Keep continue your good work. Thanks.

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Super Ankit really awesome...Loved the way you did.. Only word the best .. :)

    ReplyDelete
  37. Fantastic One!! How to install it in my Sandbox? i couldn't able to install. For Dev org i am able to install.

    Please suggest!!

    ReplyDelete
  38. Hi Ankit,

    Great Job!

    Though I am seeing this post only now, its a fantastic tool.

    Thanks
    Sunil

    ReplyDelete
  39. Really good one.... Loved it.... Yet to explore more on the same....

    ReplyDelete
  40. You are really amazing ...no words ...I'm keeping my fingers crossed for you...

    ReplyDelete
  41. Hi Ankit,
    Tremendous job, I know you are very busy but If possible please help me out.
    I have successfully extract the page layout detail into JOSN. I did save it into a custom object rich text area field. I looked that JSON.deserialize does not parse this string value even I created proper wrapper classes against this.

    Yes I looked that the whole data having some lists as well like layoutRows and layoutComponents which must be treat as rectangle bracket "[]". But there is no such notation. This might be the reason JSON.deserialize not working.

    I just wanted to know that how did you parse it to generate all nodes inside VF page ?

    Thanks
    Vijay

    ReplyDelete
    Replies
    1. oh! got it you parsed on VF page itself using script, I was looking it through JSON class to make it easy.

      Delete
  42. Hi Ankit,

    Found this tool and thought it was great.

    I just installed the package. But it does not generate the code and no email. I tried Object Name = account, type of page = Edit; generate code section was empty after generate code button is clicked. When I selected custom object I could select my fields, still no code was generated.

    Do you have new version?

    Thanks,

    wyw

    ReplyDelete
    Replies
    1. Try this out : http://forceguru.blogspot.in/2015/03/visualforce-code-generator-coding-via.html

      Delete
  43. Hi Ankit,

    I want code for Send email (in task Activity) custom functionality for custom object in visualforce page.

    Normal send email button in Activity history "To" field having contact and lead objects but i want custom object.

    Can you please tell me some idea.

    Thanks in advance

    ReplyDelete
  44. I have searched your extension on the app exchange and i could not find it ? Could you explain me why ? thanks

    ReplyDelete
    Replies
    1. Try this out : http://forceguru.blogspot.in/2015/03/visualforce-code-generator-coding-via.html

      Delete
  45. All, here is the updated version of this app. Please provide your feedback : http://forceguru.blogspot.in/2015/03/visualforce-code-generator-coding-via.html

    ReplyDelete
  46. Hello Ankit,

    I've installed the app from the app store.
    I've appended the vfgenerator thing in the URL and nothing shows up.

    Could you be specific on it.

    thank you

    ReplyDelete
  47. Hello Ankit,

    Thanks for sharing your knowledge.



    I have try to create dynamic apex page generate.So I have use Tooling API calling.but it give me erorr "Unexpected character ('A' (code 76)): was expecting comma to separate OBJECT"
    I have set Markup Field following this.

    private HttpRequest createHttpRequest(String endpoint, String method)
    {
    HttpRequest req = new HttpRequest();
    endpoint += '';
    req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
    req.setHeader('Content-Type', 'application/json');
    req.setCompressed(true);
    ApexPage ap=new ApexPage();
    ap.ApiVersion=40.00;
    ap.ControllerKey='Account';
    ap.ControllerType='1';
    ap.Markup='';
    ap.MasterLabel='ApexSample5';
    ap.Name='ApexSample5';
    string JApexPage=JSON.serializePretty(ap);
    req.setBody(JApexPage);
    req.setEndpoint(endpoint);
    req.setMethod(method);
    return req;
    }

    If I am write without standardController is working but when I am use standardController="Account" is not working.

    Can you please help me?

    My Email is "heavendev0005@gmail.com"

    ReplyDelete
  48. It's great tutorial. thank you for sharing.
    Regards,
    Web Scraping Service

    ReplyDelete