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
Rohit01Rohit01 

Creating an app to be published on appexchange

Hi

 

I am creating an app to be published in appexchange and got a query.

I have an external webservice call (with authentication) from my custom object. I want the webservice URL, username and password to be setup when user try to install the app, how do I achieve that and how do it access those parameters in my apex class.

 

Regards

Rohit

Best Answer chosen by Admin (Salesforce Developers) 
ignatiuz_forceignatiuz_force

Okay, you can either make a custom setting (https://help.salesforce.com/help/doc/en/cs_about.htm) or a custom object with those fields. Then using the post install script you can populate a default set of parameter on install(if there is a test account you want to provide to your customers), or just let them edit the custom setting/custom object data and your apex class will query the fields from that before making the web service call.

All Answers

Rohit01Rohit01

Thanks Mukul

 

But I am new to this post install script. Can you advice or provide some sample code as to how can I create 3 fields (serverURL, username, password) during installation/ configuration of the app and how do i use those 3 parameters in my classes in the app.

ignatiuz_forceignatiuz_force

There is sample code in the link I gave.

Rohit01Rohit01

Yes, there is a sample code but that only gives information as to how you can send email after the installation.

There is no mention as to how I can create and use dynamic fields - serverURL, username and password while making an http call to external webservice from salesforce.

ignatiuz_forceignatiuz_force

By creating the fields, do you mean creating the metadata in the object ? If yes then I dont think there is way.

 

If you are talking about creating a record in an object X that has fields serverURL, username and password then the code is there in the link. The following shows an example of creating an account with name field being "Newco"

global class PostInstallClass implements InstallHandler {
  global void onInstall(InstallContext context) {
    if(context.previousVersion() == null) {
      Account a = new Account(name='Newco');
      insert(a);
      
      Survey__c obj = new Survey__c(name='Client Satisfaction Survey');
      insert obj;
Rohit01Rohit01

Hi Mukul

 

Thanks a lot once again.

 

What I am doing is:

I have created a class where in I am making a call to external webservice. So for, this I have provided a serverURL, username & password. Now I want to publish this app in appexchange and make it available for others. However, I want others to modify the serverURL, username and password. I don't know what is the exact term i should use for these types of variables/ fields but in any other app outside salesforce, these are called configuration parameters or run-time parameters.

ignatiuz_forceignatiuz_force

Okay, you can either make a custom setting (https://help.salesforce.com/help/doc/en/cs_about.htm) or a custom object with those fields. Then using the post install script you can populate a default set of parameter on install(if there is a test account you want to provide to your customers), or just let them edit the custom setting/custom object data and your apex class will query the fields from that before making the web service call.

This was selected as the best answer
Rohit01Rohit01

Thanks Mukul. Custom Setting is the solution for me. That's what I was looking for. Thanks a lot again!!!