function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Fherjam1Fherjam1 

Package Id

Hi All,

 

Are there any way to get the package Id using Apex code?

 

Thanks!

aalbertaalbert

What's the use case? I don't know any of way to do that via Apex. 

Fherjam1Fherjam1

I need the Package Id to activate the license on the LMO, I have all the process but I can't differentiate between the different packages managed by the same lmo.

 

Thanks!

aalbertaalbert

Got it. Each License in the LMA is related to a Package Version (lookup field on the License record). And a Package Version is related to a Package in LMA. Any chance you determine the difference with those related values? 

Fherjam1Fherjam1

No :(, I'm looking for the package Id for that reason, I've not any field to differenciate the licenses.

aalbertaalbert

I must be missing something. Walk me through your flow. Do you know the specific license? Or Lead? And you want to activate/update the license? 

Fherjam1Fherjam1

This flow is like this:

 

A customer installs a package on his org, on that moment a record is generated on the LMO automatically and the license on that moment is a trial, I already implement a payment processor to give the customer the ability to buy the license through the app, when the payment is processed, The processor sends a request to the LMO and automatically activate the license, this process is already working, but if I have two packages on the same org, managed by the same LMO I can't differentiate one from another, this is because the only field I have is the Org Id.

 

Sorry by my English.

 

Thanks again!

aalbertaalbert

That helps. But don't you also know which app or package was purchased. And can't you pass that name to the org where LMO is configured so you can differentiate between the two licenses for the same org id? For example, "OrgID: 000abc" bought "package=ABC". 

Akshay MohanAkshay Mohan
You can get all the installed package versions in your org by using Salesforce DX CLI
Follow the following steps
  1. Set up CLI. (https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)
  2. Auth your org using command sfdx force:auth:web:login (https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_auth.htm#cli_reference_force_auth)
  3. Run the package list command and specify the user ID using -u parameter: sfdx force:package:installed:list -u <target org's user id> (https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_package.htm#cli_reference_install)
Hope this helps