GitHub Actions provides a great way to automate workflow processes and make development and deployment more efficient. Linting is an important part of any software development project to ensure code consistency and maintain uniform standards. In this post, I will explain how to setup a Github Actions workflow lint to automate your linting process.
Setting up a GitHub Actions workflow lint is easy and can help keep your codebase consistent and maintainable.
First, you need to create a workflow file in your project’s root directory. This file should be named .github/workflows/lint.yml and should contain the configuration necessary to run your linting script.
We all know that JavaScript Object Notation (JSON) is a powerful and popular data markup language. It is widely used in web development and API design. But what if you wanted to transform a JSON object’s keys and values to lowercase?
Fortunately, there is a simple way to do this. All you need to do is to loop through the object, retrieving each key and value, and then convert it to lowercase using the JavaScript toLowerCase() method.
But what if you do it in a fancy way using reduce?
test("obj to lowercase", () => {
const obj = {
MyKey1: "MY Value 1",
MyKey2: "MY Value 2",
const result = objToLowerCase(obj);
expect(result["MyKey1"]).toBeDefined();
expect(result["MyKey1"]).toBe("my value 1");
expect(result["MyKey2"]).toBeDefined();
expect(result["MyKey2"]).toBe("my value 2");
});
Prettier is a great tool for making your Node.js code look clean and consistent. It is an easy way to eliminate some of the frustrations associated with coding, such as redundant and messy code formatting. With a few simple steps, you can set up Prettier and get your code looking beautiful.
Overview
Prettier is a code formatter that supports many languages and can be integrated with most of the editors.
Also, you can integrate it with your CI/CD.
That way nobody will be able to merge to the master branch if the code is not well-formatted.
With Prettier you will be able to define your own rules, however default rules are enough at the beginning.
Your rules will be defined in a file called .prettierrc placed in your project’s root.
Let’s see how to install Prettier and then make some configurations.
Jacoco is a tool used to generate detailed reports on code coverage. It is an essential part of a software developer’s toolkit, since it helps determine what portions of a project’s code were actually tested. Jacoco produces HTML reports that display code coverage information in an easy to read format.
Context
After running the Jacoco report generator we can open it and see the coverage results. There are some results the I wanted to know, for example, how many packages contain uncovered classes and how many contain coverage under a given threshold, in this case, I used 60%. So I build a script to count them and print in the browser’s console. So, step into Jacoco’s report tab and paste this script in your browser console to execute it and see the output
Script
const table = document.getElementById("coveragetable");
const row = table.rows;
let uncoveredPackages = 0;
let columnFound = false; // the instructions coverage
let thresholdCoverage = 60;
let packagesUnderThreshold = 0;
let totalPackages = 0;
let i = 0;
while (!columnFound && i < row[0].cells.length) {
// Getting the text of columnName
const str = row[0].cells[i].innerHTML;
if (str.search("Cov.") != -1) {
if (!columnFound) {
// this is the first column with coverage for instructions the next "Cov." column is the one for branches
columnFound = true;
// iterate every row but the head and foot
for (let j = 1; j < row.length - 1; j++) {
const content = row[j].cells[i].innerHTML;
const cov = parseFloat(content);
totalPackages++;
if (cov === 0) {
uncoveredPackages++;
}
if (cov < thresholdCoverage) {
packagesUnderThreshold++;
}
}
}
}
i++;
}
console.log(`total packages: ${totalPackages}`);
console.log(`uncovered packages: ${uncoveredPackages}`);
console.log(`packages under ${thresholdCoverage}%: ${packagesUnderThreshold}`);
PG-Promise is a popular Node.js library for interacting with PostgreSQL databases. Unfortunately, it does not always work with self-signed SSL certificates generated by Postgres. If you’re seeing errors related to self-signed certificates when using PG-Promise, here is how to fix the issue.
If you are using Node.js with some of these packages: pg-promise or pg probably you are facing this issue.
Error: self signed certificate
To fix this issue you have to use the package with the following recommendations
The issue occurrs when we try to use the module this way:
const pgp = require('pg-promise')();
const db = pgp('postgres://john:pass123@localhost:5432/products');
let ssl = null;
if (process.env.NODE_ENV === 'development') {
ssl = {rejectUnauthorized: false};
}
const config = {
host: 'localhost',
port: 5432,
database: 'my-database-name',
user: 'user-name',
password: 'user-password',
max: 30, // use up to 30 connections
ssl:ssl
};
// Or you can use it this way
const config = {
connectionString: 'postgres://john:pass123@localhost:5432/products',
max: 30,
ssl:ssl
};
const db = pgp(config);
Downloading a file from Salesforce using Java is not as difficult as it may seem. With the right tools and knowledge, you can quickly and easily download any type of file from Salesforce via a Rest API. To get started, you’ll need a few software tools and a few lines of code.
Let say we want to download a file stored in Salesforce. Have in mind we said a File and not an Attachment (the old way to deal with files in Salesforce), so we’ll have to deal with ContentDocument, ContentVersion, ContentDocumentLink, etc.
Agenda:
Salesforce security token
Partner API
Salesforce Rest API
Store a file
Implementation
We are going to use force-partner-api dependency to get a session id after login
If we use Maven, our pom.xml will have this dependency
Let’s have some constants to keep our params in one place.
private static final Logger LOG = Logger.getLogger(Main.class.getName());
private static final String USERNAME = "********";
private static final String ACCESS_TOKEN = "********";
private static final String PASSWORD = "********" + ACCESS_TOKEN;
private static final String INSTANCE_URL = "https://********-dev-ed.my.salesforce.com";
private static final String API_VERSION = "51.0";
private static final String SALESFORCE_FILE_ID = "0684W00000AzWoiQAF"; // ContentVersion id private static final String LOCAL_FILE_FULL_NAME = ""/tmp/sf-java.png"";
Important: the ACCESS_TOKEN constant represents the Salesforce security token you get from Settings -> Reset My Security Token
When you access Salesforce from an IP address that isn’t trusted for your company, and you use a desktop client or the API, you need a security token to log in. What’s a security token? It’s a case-sensitive alphanumeric code that’s tied to your password. Whenever your password is reset, your security token is also reset.
After you reset your token, you can’t use your old token in API applications and desktop clients.
The method to get the file (download and save it in our local disk)
Express.js is a fast and minimalist web application framework for Node.js. It provides a simple and robust set of features for building web applications and APIs. With Express.js, you can easily handle HTTP requests, define routes, and manage middleware functions. It is known for its flexibility, scalability, and ease of use, making it a popular choice for developing server-side applications in JavaScript. Express.js also has a vibrant ecosystem with a wide range of plugins and extensions that help developers build web applications quickly and efficiently.
Redirecting all requests from HTTP to HTTPS is an important measure for ensuring website security. If your website runs on Node.js and Express, then you can easily enable this feature with the help of middleware.
When creating web applications in Node.js and Express, it is important that all requests are redirected from an unsecured HTTP connection to a secure HTTPS connection. This will ensure that your website is secure and all data sent over the internet is encrypted.
In this tutorial, we will show you how to redirect all requests from HTTP to HTTPS in Node.js and Express.
It starts by creating a middleware for your Express app that will check for a secure connection and redirect if necessary.
The first step will be to create a method to guess if the HTTP request comes from HTTP or HTTPS (secure or not secure). In some contexts like AWS or Heroku, you will have to ask by the header x-forwarded-proto instead of req.secure.
Have in mind that req.secure will return always false if there is a load balancer that redirects internally through HTTP. So let’s cover both scenarios
/**
* @param req express http request
* @returns true if the http request is secure (comes form https)
*/
function isSecure(req) {
if (req.headers['x-forwarded-proto']) {
return req.headers['x-forwarded-proto'] === 'https';
}
return req.secure;
};
And then add this code in your app.js. Have in mind we are not redirecting to HTTPS if we are in our development or testing environment but you can skip them if you want and redirect them always.
Add this block right after const app = express();. If you add it at the end, probably another declared route will response and our block won’t be executed.
// redirect any page form http to https
app.use((req, res, next) => {
if (process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test' && !isSecure(req)) {
res.redirect(301, `https://${req.headers.host}${req.url}`);
} else {
next();
}
});
Now all requests will be redirected to HTTPS if you access through HTTP regardless the full URL
Are you looking to add a bit of personality and flair to your lightning data table? Conditional cell color gives designers and developers the opportunity to transform their table into something unique and eye-catching.
With conditional cell color, you are able to control the color of a cell and its contents based on the value of a particular item in the table. This means that each cell in a row can have its own distinct color, letting you highlight important information, emphasize data, and make the table look more visually appealing.
Expected result
Salesforce Lightning is a component-based framework for building user interfaces on the Salesforce platform. It provides a modern and efficient way for developers to create and deploy custom user interfaces that can run on any device, including desktops, laptops, tablets, and smartphones.
A Lightning Component is a reusable unit of code that implements a specific feature or functionality. Components can be composed into larger applications and can be easily reused and customized to meet different business needs. They are written in Aura, a proprietary JavaScript-based language, and use the Lightning Data Service to communicate with the Salesforce server.
Lightning Components provide a number of benefits, including faster performance, improved user experience, and greater customization options compared to traditional Salesforce user interfaces. They are an essential part of the Salesforce Lightning platform and are widely used by organizations to build custom applications and extend the functionality of the Salesforce platform.
Lightning data tables allow users to customize the colors of cells in a table based on the values of the cell using conditional formatting. This is a powerful tool for quickly identifying trends and outliers in data sets. With Lightning data tables, Salesforce developers can set color thresholds to automatically color cells according to whether their value is above/below a certain value or between two values. This feature is especially useful for displaying numerical values such as sales data, which often need to be highlighted at a glance so that users can quickly identify areas for improvement.
Let say you want to highlight a cell in a Lightning data table (lightning:datatable) when a specific value is invalid. In our example, we want to display those invalid emails in red.
Salesforce content management allows users to store information such as documents, images, audio, and video files in their Salesforce org. On occasion, users may require to quickly and easily download certain content items from the Salesforce org using their own custom code.
Node-fetch is a popular Node.js library used by developers to create applications with the help of middleware, through a programming interface. Node-fetch is especially suitable for downloading Salesforce ContentVersion files.
Let’s download a file (ContentVersion) from Salesforce using node-fetch
Deleting an Apex trigger using SFDX CLI can be easily carried out in a few simple steps. Follow these steps to delete an Apex trigger using SFDX CLI:
To check the list of triggers currently present in your project, run the command:
sfdx force:apex:trigger:list
If you have an Apex trigger in Salesforce that you want to delete, you can use the SFDX CLI to do so. Here are the steps to delete an Apex trigger in your Salesforce org using the SFDX CLI.