13
votes
Accepted
Get currently installed package version from Apex Class
You can use System.requestVersion, which returns the version of your package. See Version for more details, but I'll also include the snippet from there here:
if (System.requestVersion() == new ...
11
votes
How to give date and time values in request body using postman
Use Pre-request script tab to save the date into a variable:
var current_timestamp = new Date();
postman.setEnvironmentVariable("current_timestamp", current_timestamp.toISOString());
and then use it ...
11
votes
Accepted
Using Metadata API from managed package post-install script
The postinstall context for a managed package is fairly weird. It comes with a laundry list of restrictions:
It can initiate batch, scheduled, and future jobs.
It can’t access Session IDs.
It can ...
9
votes
How to write post installer script apex class for package?
This is the pattern we use:
global class YourInstallHandler implements InstallHandler {
private Version previousVersion;
global void onInstall(InstallContext context) {
if (context....
6
votes
How to write post installer script apex class for package?
Well you have to implement the InstallHandler interface so that after installation the methods defined would work.
https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/...
6
votes
Can a 2GP package include a post install page?
I raised this on the Partner Forums too. I got the following from two of the guys at Salesforce. Firstly Dileep Burki:
The postInstallURL supports the specification of a URL to which the installer is ...
4
votes
Get currently installed package version from Apex Class
Because System.requestVersion (see @sfdcfox's answer) throws an uncatchable exception on a scratch org for package development, you cannot use this code on that scratch org and any unit tests covering ...
4
votes
How to give date and time values in request body using postman
I tried this in the workbench. It successfully created an event record.
I suspect salesforce is expecting a date in a standard format instead of the date(value) format.
{
"Type":"contact call",
...
4
votes
Updating page layout when package installed
Page layouts in a managed package can only be created, not updated. The rationale, is that your subscribers have their own custom fields and may want make adjustments that won't get overwritten by ...
4
votes
Accepted
Restore Post Install Script setting on managed package patch
I found a solution for this by manually editing the package.xml in the metadata folder to add the missing settings before running sfdx force:mdapi:deploy
More precisely:
Run sfdx force:source:...
4
votes
Accepted
Best way to detect that code is running in InstallHandler context?
Just for the record, consensus is an Apex static variable that the InstallHandler implementation sets and other code tests i.e.:
/**
* Referenced by triggers.
*/
public inherited sharing class ...
3
votes
Accepted
Future method is not invoked from PostInstall script
Sending Apex Email doesn't instantaneously sends the email. It actually locks the database, and the email will be sent at the end of the transaction. As email has locked the database it actually an ...
3
votes
Accepted
Managed Package Post Install Script - how to identify special package user?
Simply checking if getUserType = LicenseManager should be sufficient; there's no way for a real user to log in to a LicenseManager type, nor can you create users that have this user type.
3
votes
Accepted
Is there a way to deploy a Lightning App in a managed package that would be visible to all users by default?
This isn't currently possible, as of the Winter '24 release. Salesforce.com has stated that they would like to make this possible in the future by allowing packages to have something similar to a ...
2
votes
Field permission in post install script
I hit the same issue regarding packaging permission sets and standard objects. I use a script that is similar to the answer above, but rather than run it via the post install script, I created a ...
2
votes
Get currently installed package version from Apex Class
We maintain the package version as a constant in some apex class and update that line with CI on every package version creation step.
Also, if you have access to Session Id and Tooling API, it is ...
2
votes
Push VS Upgrade packages
In case of push upgrades there is no way to choose for which users package would be installed, it would trigger 'Admin Only' mode and that's it.
But when upgrading package by directly typing url on ...
2
votes
Accepted
Page Reference getContent method in a batch within a package
Agreed with @sfdcfox about the "x-y problem". Please explain your use case more?
But if the CustomObject ID is what you really need though, there are better ways to do it than screen-scraping.
For ...
2
votes
post install class access modifier
Salesforce docs tends to write examples that use global despite not needing to. From time to time, I've seen this on scheduled classes, batchable classes, queueable classes, etc. You should not ...
2
votes
Trialforce Org derived new instance does not run after Insert triggers?
TrialForce literally clones the data without running all the business logic that may be present. This is done to minimize the amount of time it takes to set up a new trial (and also why there are ...
2
votes
Accepted
Can my app auto-update an installee's security settings to allow them access to my API?
The ideal way for you to package your settings is inside a "Permission Set". That way the end user has the freedom to add the permission set to as many (or as few) users as they prefer.
While you ...
2
votes
Accepted
How to make an External Id field unique in a managed package?
Below is quoted from Salesforce support reply.
As per checking, if you are trying to modify a field added to a
managed package, then you may need us to revert the package to beta in
order to ...
2
votes
Create canvas app using Apex
I think instead of making your users to change Canvas App Url manually, why don't you make a visualforce page that will intake canvas app url from user and create the canvas app on click of a button. ...
2
votes
Create remote site setting on post install script
MetadataService under the hood uses SOAP API and make a callout which needs a remote site settings because it is trying to make a callout from apex. Salesforce released Native APEX metadata API last ...
2
votes
Accepted
Can a Post Install Script be removed from a managed package after being set?
I'll answer in reverse order:
Regarding #2, You can certainly change and/or remove your PostInstallScript from release to release. However, as you know, PostInstallScript classes must be declared ...
2
votes
Accepted
upsert failed, pushtopic with this name already exists
The issue is that the PushTopic name must be unique. Could you please try to generate the random name and then set that as a name in test class context. Sample code to generate random string.
Integer ...
2
votes
Postinstallation Action in Unlocked Package
We had few post deployment steps like yours.
Adding data, use its Id as lookup and add another objects data.
With the advent of SFDX CLI, it got easier.
You can use force:apex:execute if it's a simple ...
2
votes
Visualfoce pages in profile are not added to profile after installation
Packaging Profiles is ... really weird. I think this is what MIX DML was alluding to in their question in the comments.
There's two ways you'll see this behavior on package install, provided you ...
2
votes
Accepted
Clean data From deprecated field in Managed package
If I was doing this I would create two separate releases of the package:
The first:
Removes usages of the field from the package.
Relabels the field as "Deprecated".
Includes a batch or ...
1
vote
Can custom metadata type records be deployed from post-install script?
You should be able to do it and in order to achieve it, there are 2 ways -
Include that code in the post-install class
Run that code through a script in each org's developer console
You can have a ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
postinstall × 127managed-package × 65
apex × 48
package-install × 14
package × 8
scheduled-apex × 7
isv × 7
metadata-api × 6
callout × 6
2gp × 6
install × 6
batch × 5
appexchange × 5
permission-sets × 5
visualforce × 4
unit-test × 4
salesforcedx × 4
permissions × 4
integration × 3
profile × 3
exception × 3
schedulebatch × 3
beta-managed-package × 3
chatter × 2
error × 2