New Version of ForceJS: A JavaScript Library for using the Salesforce APIs in ECMAScript 6 Apps

ForceJS is a micro-library that makes it easy to work with the Salesforce REST APIs in client-side JavaScript applications. I started the project a couple of years ago focusing on three key requirements:

  • Lightweight with no dependencies
  • Include an implementation of the OAuth User Agent workflow
  • Abstract differences between browser-based and Cordova-based application development to allow you to run an app in the browser and on device without code or configuration changes

These characteristics are still core to ForceJS, but a lot of things have changed in the JavaScript world in the last 2 years. Modern JavaScript applications are now built with ECMAScript 6 (aka ECMAScript 2015) and beyond. The current version of modern frameworks (such as React, Angular 2, and Ionic 2) are also built on top of ECMAScript Next.

To seamlessly support modern application development workflows, and naturally integrate with modern frameworks, I pushed a new and rearchitected version of ForceJS built on top of ECMAScript 6. The new version has the following characteristics:

  • Modular architecture. Currently includes two modules: forcejs/oauth and forcejs/data
  • Loaded as ECMAScript 6 modules
        import OAuth from 'forcejs/oauth';
        import Service from 'forcejs/data';
        
  • Works naturally with modern JavaScript frameworks: React, Angular 2, Ionic 2, etc.
  • Uses ECMAScript 6 promises instead of callbacks
  • Supports singleton or named instances to accommodate apps that work with a single or multiple Salesforce instances

GitHub Repo

The new version of ForceJS is available in this GitHub repository

The original ECMAScript 5 version is available in the es5 branch of the repository

Quick Start

Follow the instructions below to set up a project and create a simple JavaScript (ECMAScript 6) application that shows a list of Salesforce contacts:

  1. Create a new directory for your project, navigate (cd) to that directory, and type the following command to initialize a project that uses the npm package manager (accept all the default values):
        npm init
        
  2. Type the following command to install forcejs:
        npm install forcejs --save-dev
        
  3. Type the following command to install the force-server development server:
        npm install force-server --save-dev
        
  4. Type the following command to install Webpack and Babel:
        npm install babel-core babel-loader babel-preset-es2015 webpack --save-dev
        
  5. Using your favorite editor, open package.json and modify the scripts section as follows:
        "scripts": {
            "webpack": "webpack",
            "start": "force-server"
        },
        
  6. In your project’s root directory, create a file named webpack.config.js:
        var path = require('path');
        var webpack = require('webpack');
    
        module.exports = {
            entry: './app.js',
            output: {
                filename: 'app.bundle.js'
            },
            module: {
                loaders: [
                    {
                        test: /\.js$/,
                        loader: 'babel-loader',
                        query: {
                            presets: ['es2015']
                        }
                    }
                ]
            },
            stats: {
                colors: true
            },
            devtool: 'source-map'
        };
        
  7. In your project’s root directory, create a file named index.html:
        <!DOCTYPE html>
        <html>
        <body>
            <h1>Forcejs Quick Start</h1>
            <ul id="contacts"></ul>
            <script src="app.bundle.js"></script>
        </body>
        </html>
        
  8. In your project’s root directory, create a file named app.js:
        import OAuth from 'forcejs/oauth';
        import Service from 'forcejs/data';
    
        let oauth = OAuth.createInstance();
        oauth.login()
            .then(oauthResult => {
                Service.createInstance(oauthResult);
                loadContacts();
            });
    
        let loadContacts = () => {
            let service = Service.getInstance();
            service.query('select id, Name from contact LIMIT 50')
                .then(response => {
                    let contacts = response.records;
                    let html = '';
                    contacts.forEach(contact => html = html + `<li>${contact.Name}</li>`);
                    document.getElementById("contacts").innerHTML = html;
            });
        }
        
  9. On the command line, type the following command to build your project:
        npm run webpack
        
  10. Type the following command to start the app in a browser:
        npm start
        

    Authenticate in the OAuth login window. You should now see a list of contacts.

    You can sign up for a free developer environment here if you don’t already have one.

Feedback

Since this is a new version, I appreciate your feedback on the developer experience. Pull Requests welcome as well.

70 Responses to New Version of ForceJS: A JavaScript Library for using the Salesforce APIs in ECMAScript 6 Apps

  1. Sören G. February 21, 2017 at 5:02 am #

    Hello Christophe,

    thanks for this tutorial. I was able to follow all the steps until step 9 where I get the following error message during build. Thanks for your help on this.

    > forcejsdemo@1.0.0 webpack /Users/xxx/forceJsDemo
    > webpack

    (node:90242) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
    parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
    Hash: f23a18b275d83dbc8a15
    Version: webpack 2.2.1
    Time: 639ms
    Asset Size Chunks Chunk Names
    app.bundle.js 9.96 kB 0 [emitted] main
    app.bundle.js.map 15.6 kB 0 [emitted] main
    [0] ./~/forcejs/oauth/index.js 5.07 kB {0} [built]
    [1] (webpack)/buildin/module.js 521 bytes {0} [built]
    [2] ./app.js 886 bytes {0} [built]

    ERROR in ./app.js
    Module not found: Error: Can’t resolve ‘forcejs/data’ in ‘/Users/xxx/forceJsDemo’
    @ ./app.js 7:12-35

    npm ERR! Darwin 16.3.0
    npm ERR! argv “/usr/local/bin/node” “/usr/local/bin/npm” “run” “webpack”
    npm ERR! node v6.9.5
    npm ERR! npm v4.2.0
    npm ERR! code ELIFECYCLE
    npm ERR! errno 2
    npm ERR! forcejsdemo@1.0.0 webpack: `webpack`
    npm ERR! Exit status 2

    • Drew March 13, 2017 at 12:48 am #

      change line 2 of app.js to read:
      import Service from ‘forcejs/data-service’;
      the api of this package changed.

      has anyone gotten the oauth login window to appear when running `npm start` in the last step?

  2. Aadhya Krishna March 16, 2017 at 8:11 am #

    Hey! I love your blog post. Its a very relevant and important topic and I think

    you’ve explained multiple aspects very well. Thanks for the information.

  3. Oktay Seo May 24, 2017 at 4:34 pm #

    Bindallı çarıkları ; her modelde olmayıp sadece bazı modeller için tasarlanıp genellikle kişinin isteğine göre kombin edilmektedir. Rahatını düşünen gelin adayları için düztaban olup ucunda tüm kıyafetle uyumlu bir ponpon ve üzerinde desenler vardır. Bindallı çarıklarının renkleri ise altın sarısı zemine kırmızı desenler veya kırmızı zemine altın sarısı desenler şeklinde hazırlanmaktadır.
    Bindallı kaftan modelleri için bağdat kaftan ile iletişime geçebilirsiniz.

    http://bagdatkaftan.com/

  4. Oktay Seo May 31, 2017 at 4:34 pm #

    Kaftan fiyatları işçiliğe ve işlemelere göre farklılık göstermektedir. Özellikle son zamanlarda bir çok kişi çoğunlukla kiralık kaftan fiyatları hakkında bilgi sahibi olmak istemektedir. Bunu nedeni ise bir gün giyildikten sonra daha çok anı olarak saklanmasıdır.

    http://bagdatkaftan.com/kaftan-fiyatlari/

  5. Oktay Seo June 19, 2017 at 2:17 pm #

    Kaftan modelleri Günümüzde kına gecelerinin dışında gece hayatı için kullanılan kaftan ceketler de oldukça iddialı parçalar olarak gözümüze çarpmakta. Özellikle şık takımları tamamlayan bu parça bütün moda takipçilerinin göz bebeğidir. Kaftan ceketlerin günlük hayatta kullanılır hale gelmesi gerek vücut hatlarına olan uyumuyla gerekse rahatlığıyla onları tercih edilir hale getiriyor.

    http://bagdatkaftan.com/kaftan-modelleri/

  6. Mark de Valk June 29, 2017 at 11:52 am #

    Hello Christophe, Thanks for your great contribution.

    I am using forcejs in Ionic and use the request method in data-service to call a custom REST Api on Salesforce. I am using query parameters and a JSON body object. Now this is working fine for web (using XMLHttpRequest). But once running in IOS, the implementation for the Request method is using the cordova network plugin. When looking in the code I see at some point that a choice is made between query-parameters and body (obj.data || obj.params).
    Based on this it seems that it is using either params or body. The API does require both params and a body. Do you have any thoughts on this?

    Thanks,

    Mark

  7. Demirhan Panel Çit August 29, 2017 at 7:39 am #

    Panel çit konusunda uzman ekip tecrübesi ile kendinize özel, güzel alanlar yaratın.

    http://www.demirhan.com.tr

  8. Hakan January 20, 2018 at 5:12 am #

    Güvenli ve uygun tel çit imalat yapımı için buyurun

    http://www.orgusan.com/

  9. Hakan January 20, 2018 at 5:13 am #

    very nice sharing thank you follow me

    http://www.orgusan.com/

  10. Hakan January 20, 2018 at 5:13 am #

    very nice sharing thank you follow me yes very nice sharing thank you follow me

    http://www.telorgufiyati.com/

  11. Damny January 26, 2018 at 10:14 am #

    Great post

    latest music here in Nigeria and South Africa

  12. Kanek Panel Çit February 2, 2018 at 4:50 am #

    Panel Çit, Çim Çit imalatçı firma istanbul tuzla ayrıca uygulama ve montaj hizmetleri sağlamaktadır.
    panel çit kanek için http://kanek.com.tr/panel-cit/ sayfasını
    çim çit kanek için http://kanek.com.tr/cim-cit/ sayfasını ziyaret edebilirsiniz.

  13. Ayo Adekola March 12, 2018 at 12:43 pm #

    nice 1 .

  14. Ezekiel Dogara June 9, 2018 at 11:13 am #

    nice one I Love it

  15. Ezekiel Dogara June 9, 2018 at 11:13 am #

    https://www.vibesmp3.com

  16. Ezekiel Dogara June 9, 2018 at 11:14 am #

    nice one

  17. Dinesh Kumar June 11, 2018 at 7:08 am #

    This is very useful information.I really look for this kind of post.visit,Andorid & ios app Development Company for more new ideas. We are thankful for this article.

  18. Dinesh Kumar June 11, 2018 at 7:11 am #

    This article has covered so many
    topics that are helpful for mobile app development, visit Mobile App and Website Development Company for more new
    ideas, we are thankful for this article.

  19. TargbaBenjamin February 7, 2019 at 3:13 pm #

    Great info. https://legacytips.com/cash-app-review-make-mobile-payments-with-cash-app/

  20. TargbaBenjamin February 7, 2019 at 3:13 pm #

    http://www.legacytips.com

  21. Desirebaze Media February 15, 2019 at 11:41 pm #

    Nice
    DOWNLOAD MP3
    Musics
    Mixtapes
    News
    Videos
    Article
    Sports
    Lifestyle
    Album
    Mp3 Download

  22. Serpil ÇİÇEKÇİ June 20, 2019 at 8:34 am #

    Marmaris tekne turu olarak hizmetlerimiz, marmaris efes turu | Dalyan tekne turu | kleopatra plajı | marmaris pamukkale turu gibi ve daha fazla avantajlardan yararlanmak için lütfen bizimle iletişime geçin.

  23. Cakiroglu Nakliyat June 22, 2019 at 2:55 am #

    Çakıroğlu Nakliyat olarak verilen başlıca hizmetlerimiz , Asansörlü nakliyat | Ofis taşımacılığı | Piyano taşımacılığı | Buca evden eve nakliyat | Karşıyaka evden eve nakliyat | İzmir eşya depolama vb. hizmetleri en kaliteli ve profesyonel şekilde müşterilerine sunmaktadır.

  24. Joson Froster August 15, 2019 at 1:08 pm #

    The subject of Philosophy and its subcategories have been widely discussed in both the Western and non-Western world albeit with different focuses. Philosophy includes many different subfields involving investigation into our existence. These subfields include epistemology, ethics, logic, metaphysics, philosophy of science, social and political philosophy, and Metaphilosophy. Epistemology focuses on the study of Knowledge, also known as “Theory of Knowledge”. Ethics involves the study of moral values and rules, Logic; the study of reasoning. Metaphysics is the study of being and knowing also known as the principles of reality. Read more at http://writeacoverletters.com
    One of the first points to be clear about is that a philosophical essay is quite different from an essay in most other subjects. That is because it is neither a research paper nor an exercise in literary self-expression. It is not a report of what various scholars have had to say on a particular topic. It does not present the latest findings of tests or experiments. And it does not present your personal feelings or impressions. Instead, it is a reasoned defense of a thesis.

  25. kiruthika venkatesh August 31, 2019 at 4:25 am #

    Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
    https://www.gangboard.com/big-data-training/data-science-training

  26. Priya Rani October 28, 2019 at 7:02 am #

    I visit your whole blog. Good work admin. This is informative for people. thanks for sharing.
    Call of Duty Modern Warfare 3 Free Download

  27. Antonio Lionader November 11, 2019 at 2:57 pm #

    You started looking for a real college literature lesson homework help online because of some extraordinary sophisticated assignment that is due soon and you have no clue about a way to approach to its completion.
    Let’s first be clear on one thing: you buy at College Homework Help and we give great homework help. College demands it. And you don’t have to be involved if you are uninclined to do so. You can give us the assignment, explain what you will, and leave us to complete the work. However, our methodology is set up so that you can reap enormous benefits from the process itself. From the day you complete the buying process, you will get to choose your professional writer, and e-mail communication begins immediately.

  28. Infomatica Academy January 15, 2020 at 1:09 am #

    It is very helpful post.
    NATA Coaching Classes

  29. naikr1415 January 15, 2020 at 4:45 am #

    Thanks for sharing.
    Career Advisor in Mumbai

  30. Mp3oga Media February 7, 2020 at 5:58 pm #

    Wow For New hit songs

    Album
    hit songs

  31. Mohan Basu February 10, 2020 at 5:15 am #

    Nice article.Python is a very popular language.Check this Python Training
    institute.

  32. Dennis February 29, 2020 at 1:16 pm #

    Forte Premium Crack For the professional musician is everything you NEED. For the amateur musician is everything you WANT. This full-version is the showcase edition in the FORTE 10 line of products and provides high-quality function and operation. The sky’s the limit and the possibilities are endless with FORTE 10 PREMIUM Crack!

  33. gtacheat code March 6, 2020 at 5:06 am #

    The part I find interesting is the more or less complete separation of comments here, keep it up for more updates about this related blog. Visit our website gtacheatcode for latest game’s cheats code and click here for 2020 Sims 4 vampire cheats

  34. ab March 8, 2020 at 8:04 pm #

    Petroyasan CO Is A 30 And One Of Top Iranian Used Oil Recycling Plant Manufacturers , Oil Distillation Plant , Grease , Solvement 402 , Sulfurization ,Waste Engine Oil Distillation Plant Manufacturers And Other

  35. Hồng Nguyễn March 16, 2020 at 5:04 am #

    Things are very open and intensely clear explanation of issues. was truly information. Your website is very beneficial.
    hotmail email login
    gmail login

  36. Sporium March 23, 2020 at 4:43 am #

    vücut geliştirme hakkında püf noktaları bu adreste bulabilirsiniz Fitspor

  37. kal;u rana April 12, 2020 at 7:33 am #

    I read your post and it is good to read, thank you heartily for writing such a post

    Teer Result

  38. Sporium June 24, 2020 at 10:43 am #

    hello today i will tell you about a great site. Gofitday this site has great information about training and wellness. If you care about your sports life, I recommend you to enter and look.

  39. freelicense key August 12, 2020 at 1:47 pm #

    Things are very open and intensely clear explanation of issues. was truly information. Your website is very beneficial.
    photoshop cs6 license key

  40. yuvaraj singh August 14, 2020 at 3:03 am #

    Advanced Scrum Master training
    Advanced Certified Scrum Master (A-CSM) is a certification program offered by Scrum Alliance for aspiring Scrum Masters. Scrum Alliance is a non-profit organization based out of Colorado, the USA which provides education, educational resources and as well as support to Agile and Scrum Practitioners.

  41. raber asroon August 15, 2020 at 3:24 pm #

    Strong and eloquent resumes are the most important features of a professional SEO expert. You need more than luck to succeed in affiliate business. You need more than luck to succeed in affiliate business. Someone who will get you to the first page of Google on time and do it without using black hat SEO techniques. If you are looking for someone who provides SEO services in a completely professional and good way, contact Ismaeil Sahab through this page.
    increase website traffic

  42. yuvaraj singh September 7, 2020 at 6:45 am #

    Great work, Thanks for sharing
    Leanpitch provides online training in Scrum Master during this lockdown period everyone can use it wisely.
    CSM online

  43. yuvaraj singh September 9, 2020 at 3:16 am #

    Helpful content
    Leanpitch provides online training in Advanced Scrum Master during this lockdown period everyone can use it wisely.
    Advanced Scrum Master Training Online

  44. Mohd Sharique October 7, 2020 at 11:18 am #

    amazing post thanks for sharing.

    Big Data Training Institute in Pune
    Hadoop Training in Pune

  45. Mahraja Express October 8, 2020 at 3:41 am #

    Its as though you had an awesome handle on the topic, however you neglected to incorporate your perusers. Maybe you should consider this from more than one point.
    Regards
    Monthly Rashifal Hindi

  46. Mahraja Express October 12, 2020 at 7:13 am #

    Just want to say your article is as astonishing. The clarity in your post is just excellent and i can assume you are an expert on this subject. Well with your permission let me to grab your feed to keep updated with forthcoming post. Thanks for share with us. Regards: Luxury Train Tours

  47. Amlida November 5, 2020 at 4:50 am #

    Excellent post keep it up and share more.

    home cyber security devices

  48. yuvaraj singh November 23, 2020 at 3:05 am #

    Thanks for sharing
    To crack scrum master interview : Scrum Master Interview Questions

  49. yuvaraj singh November 23, 2020 at 4:31 am #

    Great work
    To crack scrum master interview : Scrum Master Interview Questions

  50. mira khan December 13, 2020 at 9:48 am #

    this is the best place
    loaris trojan remover license key from forcrack
    master pdf editor crack from crackred
    sidify music converter crack at keyslog

  51. candy crush saga December 21, 2020 at 11:46 am #

    The new version of ForceJS is very good, thank you very much!
    sudoku 247

  52. yuvaraj singh December 22, 2020 at 2:35 am #

    Thanks for sharing this informative content
    Leanpitch provides online training in Enterprise agile coaching during this lockdown period everyone can use it wisely.
    Enterprise Agile Coaching

  53. yuvaraj singh January 8, 2021 at 12:51 am #

    Thanks for sharing this.,
    Leanpitch provides online training in Scrum Master during this lockdown period everyone can use it wisely.
    Join Leanpitch 2 Days CSM Certification Workshop in different cities.

    CSM certification online

    CSM online

    CSM online certification

    Scrum master certification online

    CSM online training

  54. Emma Jackson January 18, 2021 at 2:05 am #

    Bravo!! what an interesting post. Very interesting information. Bearing Price In Pakistan

  55. Alireza Zarei January 18, 2021 at 2:08 am #

    very handy and useful. thanks.
    https://cliniczarei.com/

  56. Ravikumar February 2, 2021 at 7:43 am #

    Thank you for sharing this content, Great work.

    To crack Scrum master interview: Scrum master interview questions

  57. Saket Kumar February 12, 2021 at 6:18 am #

    Great post. Thanks for sharing this

  58. Toby February 13, 2021 at 6:23 am #

    Much obliged for Sharing data.

  59. Aditya February 19, 2021 at 3:36 am #

    Good post thanks for share information.

    AppValley VIP APK
    Cami Elliott
    lola Iolani Momoa
    rolling paper alternatives
    Mp3boo
    free edu email

  60. Aditya February 19, 2021 at 6:50 am #

    very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing

    carboxyl
    utsa blackboard
    linear interpolation
    antiderivative calculator
    anesthesia technician course syllabus
    What are the Scientific Reasons for Choosing Printed Books
    mypaper com
    bds full form

  61. shirawilliam February 23, 2021 at 6:21 am #

    Useful… Uniswap Clone Script

  62. Pravija 123 February 26, 2021 at 11:15 am #

    Thanks for posting the best information and the blog is very informative.python course in Bangalore

  63. mark person March 25, 2021 at 9:40 am #

    Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. pareto chart

css.php