New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@vlocode/apex

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vlocode/apex

Salesforce APEX Parser and Grammar

latest
Source
npmnpm
Version
1.32.0
Version published
Weekly downloads
846
-22.17%
Maintainers
1
Weekly downloads
 
Created
Source

CircleCI GitHub top language Bugs Vulnerabilities NPM Version

@vlocode/apex Salesforce APEX Language Parser

Antlr4 based APEX Parser and Grammar. This library uses antlr4ng as runtime library which is a port of the original antlr4 runtime library to TypeScript.

The library exposes the APEX Lexer and APEX parser generated from the .g4 grammar files allowing parsing of APEX source code using Visitor or Listener patterns.

Features

  • Full APEX and SOQL grammar support
  • Extract code structure from APEX source code
  • Identify classes, fields, methods, properties and access modifiers
  • Identify which classes are tested by which test classes

Example: Identifying test classes for a given class

Below code demonstrates how to identify which classes are tested by which test classes. And prints the test classes for a given class name.

import { TestIdentifier } from '@vlocode/apex';

const testIdentifier = container.create(TestIdentifier);
await testIdentifier.loadApexClasses(['path/to/apex/classes']);
const testClasses = testIdentifier.getTestClasses('MyClass');
console.log(testClasses);

Example: Extracting class information from APEX source code

Below code demonstrates how to extract class information from an APEX source fragment and prints the class name, fields and methods as well as their access modifiers.

import { Parser } from '@vlocode/apex';

const sourceCode = `public class Person {
    private String name;
    private Integer age;

    public String nameProperty {
        get { return this.name; }
    }

    public Integer getAge(Integer arg) {
        return this.age;
    }

    public Date getBirthDate() {
        return Date.now();
    }
}`;

const parser = new Parser(sourceCode);
const struct = parser.getCodeStructure();

for (const classInfo of struct.classes) {
    console.log(`Class ${classInfo.name}`);

    console.log(` Fields: ${classInfo.fields.length}`);
    classInfo.fields.forEach((field, i) =>
        console.log(`  ${i + 1}) ${field.name} (${field.access})`)
    );

    console.log(` Methods: ${classInfo.methods.length}`);
    classInfo.methods.forEach((method, i) =>
        console.log(`  ${i + 1}) ${method.name} (${method.access})`)
    );
}

Outputs the following:

Class Person
 Fields: 2
  1) name (private)
  2) age (private)
 Methods: 2
  2) getAge (public)
  3) getBirthDate (public)

Credits

The grammar files in this library are based on the grammar files from the apex-parser NPM library originally maintained by Andrey Gavrikov. The original library is no longer maintained and the grammar files have been updated to work with the latest version of Salesforce and the antlr4ng runtime library.

Keywords

Salesforce

FAQs

Package last updated on 16 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts