Sunday, 16 January 2022

2 GP Salesforce

 Unlocked packages are best to build your application in modular way


With 2nd GP, Salesforce defines the modular application development.


Note :

Our end goal here is to create a version able, maintainable, installable and upgradable package.


Before we start creating unlocked package, we need to do following -


1.      Enable Dev hub in org.


2.      Enable 2nd generation managed packaging.


3.      Install CLI


Five Key Features of 2GP


1.100% source - driven Package Development.

2.Declarative package Configuration.

3.Flexible version management.

4.Multiple Packages in a single namespace.

5.Package Bundles.



Enhanced Support for @namespaceAccessible Annotation :


The @namespaceAccessible annotation provides enhanced support for accessing interfaces, properties, and abstract classes in second-generation packages.


Features: The @namespaceAccessible annotation improvements include:


The @namespaceAccessible annotation now supports interfaces, properties, and abstract classes

A public or protected variable or method with the @namespaceAccessible annotation must be in a class that is declared as public 

and annotated with @namespaceAccessible

A public or protected inner class with @namespaceAccessible annotation must be enclosed in an outer class that is declared as 

public and annotated with @namespaceAccessible



Note :


The @namespaceAccessible makes public Apex in a package available to other packages that use the same namespace. 

Without this annotation, Apex classes, methods, interfaces, and properties defined in a 2GP package aren’t accessible to the other packages 

with which they share a namespace. Apex that is declared global is always available across all namespaces, and needs no annotation.


You need to explicitly grant access per member.


ex: 


@namespaceAccessible

public with sharing class AuraResult {

    

    @namespaceAccessible    

    public Boolean success = false;

    @namespaceAccessible

    public String message = ''; 


    @namespaceAccessible

    public AuraResult() {


    }


    @namespaceAccessible

    public Boolean getSuccess() {

        return success;

    }


    @namespaceAccessible

    public void setSuccess(Boolean success) {

        this.success = success;

    }


    @namespaceAccessible

    public String getMessage() {

        return message;

    }


    @namespaceAccessible

    public void setMessage(String message) {

        this.message = message;

    }

}


Package Bundles :


1.Allow single-click installation of bundled packages that share a namespace.

2.Be clearly identifiable as a bundle in Setup UI in the subscriber Org.

3.Be flexible enough to allow for entire or partial-bundle push upgrades.


No comments:

Post a Comment