What are Named Credentials?
Named Credentials is a secure way to store external application credentials (username/password or secure tokens) when you make a callout to an external system from apex.Create a named credential as below.We just create a username password credential, but keep in mind that named credentials support a variety of options including oAuth, AWS etc.
Recursion happens when code execution falls in a loop and keeps executing indefinitely. You get a run time exception 'maximum trigger depth exceeded'
To avoid such situations we use a static variable. Below is a simple example. In the code below the trigger fires on after update and updates the lead one more time. But, we want to run this for one time only. Setting the static boolean flag avoids executing the trigger the second time. Static variables live throughout the entire apex transaction and hence their value remains intact. Try removing the static keyword to get into the exception.