Is there a way a method can be triggered or run during a salesforce package installation process? - salesforce

I would want to do this to run post installation setup process like adding custom data that is required for the application to run.
One option I am aware of is to Write Installation and Setup instructions for users. Create visualforce page and include a button on this page. Redirect user to this page as the process of Installation and ask the user to click the button.
I only wanted to know If there was a more elegant way to solve the problem and if there is a way to call a method during the installation process.

Salesforce has recently implemented the ability to execute scripts (as Apex) during package Install / Uninstall:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_install_handler.htm

No, we can't have a post installation script for the app. What you are saying is best solution, just keep a custom setting to flag, if initial setup is not done, then redirect to the setup page first, other wise do the normal work.

My question would be revolving around why you need custom data for the app to run? One of the things Salesforce look for when doing a security review of your code and the unit tests you have is to check to see if you are requiring data in your org as this is bad practice. Note that if your app is requiring specific data to run then it cannot be tested properly as the data will not be in the org when running the tests on install.
What is the data you are requiring? Could it be stored in an xml like static resource file or something similar for you to load and parse as it is needed?
Paul

Related

Gatsby Dynamic Rebuild Static Pages on Production

I write my first Gatsby Page. I also use Laravel as backend server.
In my project i have many slug pages. I used createPages and api connection to create them. User can add files like images, audio files and pdf. When it happen, page should change a bit content and show this file on specify address. Develop version works fine (i bind button to start npm run refresh). I used gatsby refresh endpoint and add to scripts:
"refresh": "curl -X POST http://localhost:8000/__refresh"
And it's work fine. But i don't know how change this to use it properly on production build. Can anyone help me? Thanks
The ENABLE_GATSBY_REFRESH_ENDPOINT environment variable is only working on development. According to the documentation:
During local development, it can be useful to refresh sourced content
without restarting the development server. To facilitate this, Gatsby
exposes an environment variable called ENABLE_GATSBY_REFRESH_ENDPOINT.
What you need is called a webhook. Basically, a webhook is a way for an application to trigger a change that happens in real-time in a CMS.
Each CMS has its own way of implementing webhooks, but the idea is to trigger a build process once a change in your CMS occurs.

Gatsby add dynamic page on client side

I'm using a Gatsby setup hosted on Netlify.
I'm building some sort of recipe website where users can register, login and add recipes to their own cookbook page. To add a new recipe a user can fill in a form with some data (like recipe name, ingredients etc.). On submit the data will be stored inside a database. I then also want a dynamic page to be created for that specific recipe. (This is where you come in).
I know I can add pages via the gatsby-node.js file but I would prefer if this page can be added on the client side and exists instantly after the form submit without rebuilding the project. Is this possible in Gatsby and if so... how?
If this is not possible my best option would be calling the Netlify webhook to rebuild the project after the form submit and simply wait for the build to be completed before I can show the recipe detail page? Any thoughts on this?
Hope one of you coders can help me out here!
The way I would approach this is first show a dynamic version of the new recipe page (directly after submitting), which will only be visible to the authenticated user (based on its user ID and post ID). Maybe make this clear for the author with a note on that page. Something like: "This is a preview. Your recipe is being cooked up right now and will be ready in a few minutes."
At the same time, an incremental build would be triggered using a webhook from the backend. Both gatsby cloud and netlify support this now, so theoretically the build should be fast.
Triggering the webhook depends on your backend solution which you didn't mention. But when using for example Drupal you can use the build_hooks module. This can be configured to trigger a build when a recipe is posted back to Drupal.
I'm sure there would be a number of technical challenges but I think it should be possible. The trick would be not to generate too many dependencies in your new content, so the incremental build stays as small as possible.
Okay so I figured out there isn't a way in Gatsby to create the page directly in the client side. I decided to go with Albert's idea of first showing a dynamic page including a message saying this is a temporary page and the real recipe is "being cooked up".
On form submit I also just simply call the webhook to trigger Netlify deploy. This triggers a new deploy and in the gatsby-node.js I will create the new page based on the data I saved in my database on the form submit.

ExtJS6: Partial App load for special request that always opens in a new window

We have a ExtJS7 app, that for special requests like reset password, that always opens a new tab via email reset link, get loaded in full. We would like to load only few pages that are needed to load for these kind of request
Is there a way in ExtJS that would only load a particular page and its dependencies
I have not seen tutorials on this subject in official documentation. Myself did the following - just created another app (or bundle) for logging. The backend is responsible for the logic of what to display (loginapp or mainapp) - in the absence of a session, the user receives the app login
Absolutely. You can make another app - each app is a page, and will have its own packaged dependencies.
That's the easiest approach. A more complicated approach is to break your application into several ExtJS packages. You can then configure the app.json to exclude all of the packages from the micro loader. You then need to load these packages dynamically, presumably after logging in.
Doing this, though, is extremely complicated, and almost certainly not worth doing.

Cakephp3 handle authorization as a plugin

I've been working on cakephp3 for a while now. I've always used Cakephp's Auth component for authorization and authentication purpose.
I follow the very conventional procedure every time, like loading the component, adding isAuthorized function in controllers and defining allowMethods etc.
But now what I want is to develop my own plugin for this purpose, just using Cake's Auth component. So that i can reuse the plugin in all my future projects, also i want it to be like plug and play. Like You enable it, add few settings and your User management is done.
I know that how migrations work so I can add users table via migration every time. (Just an idea)
The thing I don't get right now is how to make everything separate from the core app? Like everything is done via plugin and nothing is added to every controller of the app.
Hope I'm clear about what I want to achieve.
Update: I know there is a whole list of third party Auth plugins. But I want to develop my own so i just need the idea of how things work.
Any solutions to my problem would save my day.

What is the best way to update an angular application?

Our team is constantly working on an angular application, and every week or 2 we update it with new features or correct some bugs that came out.
We are using a C# backend with webservices.
QUESTION: When we update the application on the server, we sometimes (this doesn't happen all the time) get the problem that user is still seeing the old HTML and functionalities. What is the way to solve this?
I didn't find this on google, maybe I'm not looking for the right terms,
any help is appreciated.
Users have to clear their cache to get the new version of the application.
What you are seeing are cached copies of the JS files (possibly HTML partials too).
When the browser parses the HTML page, it makes the request for getting the JS resource and looks at various information before deciding to retrieve either the cached copy (if any) or whether to query the server again.
You can find some extra details on the Google fundamentals on HTTP caching
A solution I have been adopting myself is to set the cache headers to cache the file for a very long period, and then use tools in the build to version the file either on the filename or with a request parameter.
I have used grunt-cache-breaker and found it to serve well for this purpose. I know there is a gulp equivalent too
The most common way to make sure cached versions of your javascript aren't used is adding the version as a parameter in the reference to the script like so:
<script src="/app.js?v=v1.0"></script>

Resources