Back

How to Deploy Angular App to Salesforce: Developer Insights

6min
1

Hi, I’m Aleksandr Havrylov, a front-end developer at Synebo. I want to share the solution that I came up with during the development of the Angular application for Salesforce, using RemoteActions, StaticResources, and DEV mode, without waiting for the resources to be deployed to Salesforce. This article will show you how to deploy an Angular app to Salesforce without suffering and pain.

Prerequisites / Requirements

You should have basic knowledge and experience in Angular 2+ and Salesforce development. Also, it would be best if you had Salesforce org (version 36.0 and later) for the deployment, evaluation, and validation. The source code is here.

I would recommend using Angular CLI, but this solution will also work for other projects since Gulp works with the project builder. If you do not use the Angular CLI, change the command that builds the project “dev” and “prod” in package.json.

Let’s plunge into this situation. We are in 2018: Elon Musk successfully launched SpaceX; everybody talks about Machine learning, Virtual Reality, Artificial Intelligence. Angular releases the 6th version. Mining and crypto-currencies is common thing. And you would never believe it, but meanwhile, I received a project with the stack of Angular + Salesforce. I’ve found so much stuff on this topic on the Internet. Something from that was good enough and worth of attention, and the rest was a vast mass of rubbish.

My verdict: “Enormous amount of text and a lack of sense is a common denominator.” This was very overwhelming since I thought I could do everything easier. Therefore, I decided to use a minimal set of instruments like Angular and Gulp, which almost every front-end developer is familiar with.

Here is what we get from the Angular+Salesforce stack:   

  • Issue connected with joint development
  • Only God knows how to work in the development mode
  • The build result is not easy to paste in VisualForce page
  • How to use RemoteActions?
  • How to use StaticResources
  • Before deployment on production, we should edit the VisualForce page and so on again and again
  • Done with your code=> built it=> made and archive=> deployed=> probably you should be prepared to change your VisualForce page

Enough! For how long can we endure this?!​

Gulp-jsforce-deploy

We first need a Tula to deploy the project to Salesforce, and during the search, I found this post. I decided to stop at gulp-jsforce-deploy, a plugin for deploying prepared packages to Salesforce using JSforce’s Metadata API. This is exactly what we need – easy-to-use and only 3 relations with a simple script for deployment, which is typical for those who have already worked with MavensMate.

The .env configuration file

To not store our sensitive data explicitly in the repository and keep them in one place, we will create a .env file and add it to .gitignore. All configuration settings will be stored because it will not be nice if this file gets into the repository. Dotenv package itself will help us to receive the data.

2

This is how .env: content looks like. I think this should be clear.

How to use the solution:

  1. Copy gulpfile.js from the repository and paste it to your Angular project. Meanwhile, copy the file salesforce.service.ts and paste it to the service folder. Let’s name it src/services.
  2. Establish all dependencies with the command​ npm install gulp gulp-zip gulp-jsforce-deploy dotenv gulp-rename gulp-replace gulp-file –save-dev
  3. Add commands to package.json “dev”: “ng build && gulp rm && gulp build-dev-package && gulp deploy && ng serve”,  “prod”: “ng build && gulp rm && gulp build-package && gulp deploy”
  4. ng build is the command that collects the project. If you do not use the Angular CLI, replace this build command with your project, and if your project does not go to the dist folder, then you need to fix the paths in gulpfile.js.
  5. Define the necessary variables in the .env file and run it with the command npm run dev or npm run prod

That’s it! Kindly use it.

Further, I am going to explain how this works:

  • Data from the .env file is pulled into the file gulpfile.js
  • Index.html from the dist folder is converted into apex: page
  • The resource file is created with the name from the .env file based on the build of the project
  • *meta.xml files are created for the resources, the page, and the package in general
  • We can deploy 2 kinds of packages to our Salesforce Org, entirely ready for production (command: npm run prod) or for development (command: npm run dev) using local resources instead of static resources on our maiden server. For more about this, see below.

You may use StaticResourсesThere is the following script in our gulpfile.js:

3

This script adds _VfResource to the window object, now this variable is available globally, and that’s how we can use it. In our SalesforceService, there is a getSFResource method that returns the path to the resources.

4

Here is an example of how you may use it:

some.component.ts

5

Easy!

Now you may use RemoteActions

There is a method callRemote in our service SalesforceService for this purpose:

6

The callRemote method in our SalesforceService receives the first parameter with a string containing the Name of the Controller. The name of the Method is the Sampling of the RemoteAction. Additionally, there are parameters (you can edit this as you prefer).

successCallback – processing of a successful response from the serverfailedCallback – error handling from the server.

7

Develop / production mode

As I mentioned before, to deploy prepared to the production project within Salesforce, we have to execute command npm run prod. This will create a package with StaticResources and Visualforce page with connected controllers and resources. If we prefer to work on DEV mode, we have to execute a command npm run dev, which will deploy only the Visualforce page on Salesforce with connected controllers, local resources, and launch Dev Server.

To do so, you should indicate the path to the local resources in the file .env in DEV_RESOURCES_URL variable. For instance, if we use Angular CLI, the path to resources by default will be http://localhost:4200 DEV_RESOURCES_URL=http://localhost:4200

Final Thoughts

I could find only one prominent drawback in my solution. You will have to refresh the page every time you make changes. Unfortunately, Livereload doesn’t work, and have a couple of thoughts regarding this, but let’s leave this for another article.

I hope this solution will be helpful for you and help you be more productive without wasting time on project adaptation and the environment for Salesforce. I will be grateful for your comments and healthy criticism. In case you have additional questions or thought, send emails to contact@synebo.io.

Table of content
How to Deploy Angular App to Salesforce: Developer Insights Prerequisites / Requirements Develop / production mode Final Thoughts
chat Сomments
No comments yet, be the first to leave one!
leave a comment
articles You might be interested in
No image available
How-to Guides and Tutorials
21 Nov 2023
How to Get Listed on Salesforce AppExchange
Pavel Vehera
Pavel Vehera
12min
No image available
Salesforce development
14 Nov 2023
Questions to Ask Your Potential Salesforce Implementation Partner
Pavel Vehera
Pavel Vehera
12min
Cover and internal images for blog post the role of communication in outsourcing teams
Salesforce development
07 Nov 2023
Mastering Communication: Strategies for Collaborating with Salesforce Development Outsourcing Team
Pavel Vehera
Pavel Vehera
13min
No image available
Salesforce development
31 Oct 2023
Tips For Choosing the Right Salesforce Consulting Partner
Pavel Vehera
Pavel Vehera
11min
1 (1)
Salesforce development
24 Oct 2023
How to Build an App for Salesforce AppExchange
Pavel Vehera
Pavel Vehera
14min
12
23 Aug 2023
How to Get the Most Out of Salesforce Reporting and Dashboards?
Sergii
Sergii
13 min
11
09 May 2023
How Do Slack and Salesforce Work Together?
Sergii
Sergii
13 min
10
05 Apr 2023
Salesforce Einstein, or How AI Betters Your CRM?
Alina
Alina
23 min
9
12 Jul 2023
Migration to Salesforce & Data Migration
Sergii
Sergii
14 min
8
28 Jun 2023
How Can Salesforce Experience Cloud Help Your Business?
Sergii
Sergii
35 min
7
14 Jun 2023
Salesforce Developer Career
Alina
Alina
24 min
6
21 May 2023
Everything You Need to Know About Sales Cloud
Sergii
Sergii
39 min
5
17 May 2023
Project Manager Career With Salesforce
Alina
Alina
26 min
4
03 May 2023
What Is Flow, and Why Is Everyone So Obsessed With It?
Sergii
Sergii
17 min
3
19 Apr 2023
Salesforce Admin Career
Sergii
Sergii
30 min
2
05 Apr 2023
How to Kick-Start Career With Salesforce?
Alina
Alina
24 min
1
28 Aug 2023
Salesforce Products
Sergii
Sergii
28 min
No image available
22 Mar 2023
Intro to Salesforce Nerds Podcast
Alina
Alina
4 min
Neurodivergent side of Salesforce
06 Sep 2023
Neurodivergent Side of Salesforce with Paul Ginsberg
Alina
Alina
56 min
36
02 Aug 2023
Salesforce Implementation: Main Challenges and Best Practices
Alina
Alina
13min
Salesforce Nerds are Taking a Break
07 Sep 2023
Salesforce Nerds are Taking a Break
Alina
Alina
3 min
35
17 Jul 2023
What is Salesforce Experience Cloud, and What You Get From It?
Alina
Alina
10min
1
20 Jul 2023
CI/CD: Transforming Salesforce Development with DevOps
Alina
Alina
16min
33
31 May 2023
How and Why to Use Salesforce for Nonprofits?
Alina
Alina
6min
1
27 Apr 2023
Salesforce Sales Cloud from A to Z
Alina
Alina
6min
image (1)
30 Jul 2023
All Whats and Whys of Ecommerce Automation With the Power of Salesforce
Alina
Alina
4 min
1
30 Mar 2023
Salesforce Licenses: How to Understand and Choose?
Alina
Alina
6min
1
27 Apr 2023
Main Benefits of Classic to Lightning Migration
Alina
Alina
4min
1
14 May 2023
What is Salesforce Flow, and Why Do You Need It?
Alina
Alina
4min
1
19 Jan 2023
15 Types of Salesforce Clouds
Alina
Alina
5min
1
06 Dec 2022
5 Examples of the Best CRM for Nonprofit Organizations
Alina
Alina
5min
1
04 Nov 2022
What Is Hybrid Work, And How to Make It Work?
Alina
Alina
5min
1
05 Aug 2022
Salesforce Security in Plain Words
Alina
Alina
7min
1
08 Apr 2022
We Help Ukrainians Take the Salesforce Developer Course
Kristina
Kristina
4min
1
10 Mar 2022
21 Best Nonprofit Software Tools to Enhance Your Work
Kristina
Kristina
16min
1
30 Aug 2022
What is Beneficial in CRM for Nonprofits?
Kristina
Kristina
7min
1
25 Jan 2023
CMS Hub: The Guide to Managing Your Website
Kristina
Kristina
10min
1
10 Aug 2021
How to Find the Best Company for Developing Your Org in Salesforce
Synebo
Synebo
3min
1
17 Mar 2023
What is Salesforce Product Development Outsourcer (PDO)?
Synebo
Synebo
4min
1
28 Jul 2018
3 Steps for Salesforce App Development Lifecycle
Synebo
Synebo
4min
1
16 Apr 2018
How to Deploy Angular App to Salesforce: Developer Insights
Synebo
Synebo
6min
1
29 May 2018
How to Start Salesforce Career with Salesforce Certification
Synebo
Synebo
5min
1
05 Apr 2018
How to Send Emails via Outlook API from your Salesforce Org
Synebo
Synebo
3min
1
29 Mar 2019
4 Reasons Why You Shouldn’t Be Afraid of Outsourcing Software Development
Synebo
Synebo
4min
1
18 Feb 2022
The Anatomy of Dynamic Programming [with Codes and Memes]
Synebo
Synebo
11min
1
16 Feb 2018
6 Examples of UI/UX Design Mistakes and How to Avoid Them
Synebo
Synebo
6min
1
24 Oct 2022
Social Media CRM, or How to Get Closer to Your Customers
Alina
Alina
4min
1
21 Feb 2022
Commerce Cloud B2B vs. B2C. What Is the Difference?
Synebo
Synebo
5min
1
27 Sep 2022
Hows, Whys, and Whats of AI in CRM
Alina
Alina
4min
1
27 Jan 2022
8 Ways to Streamline Your Business with Salesforce Development
Kristina
Kristina
7min