How to generate random password using Apex?
Integer len = 10; Blob blobkey = crypto.generateAesKey(128); String key = EncodingUtil.convertToHex(blobkey); String pwd = key.substring(0,len); system.debug('Random Password-' + pwd);
Integer len = 10; Blob blobkey = crypto.generateAesKey(128); String key = EncodingUtil.convertToHex(blobkey); String pwd = key.substring(0,len); system.debug('Random Password-' + pwd);
A debug log records database operations, system processes, and errors that occur when executing a transaction or while running unit tests. The system generates a debug log for a user every time that user executes a transaction that is included in the filter criteria. We can monitor specific users in Debug log by adding them to list of Monitored Users.
Add Users to the debug log:
Step1: Go to Setup, click Monitoring | Debug Logs.
Step2: Click on New button to add User.
Step3: Add User and Save.
Debug log can contain information about:
Debug Log Categories:
We can specify the following log categories. The amount of information logged for each category depends on the log level:
Log Category | Description |
Database | Includes information about database activity, including every data manipulation language (DML) statement or inline SOQL or SOSL query. |
Workflow | Includes information for workflow rules, flows, and processes, such as the rule name, the actions taken, and so on. |
Validation | Includes information about validation rules, such as the name of the rule, whether the rule evaluated true or false, and so on. |
Callout | Includes the request-response XML that the server is sending and receiving from an external Web service. This is useful when debugging issues related to using Force.com Web services API calls. |
Apex Code | Includes information about Apex code and can include information such as log messages generated by DML statements, inline SOQL or SOSL queries, the start and completion of any triggers, and the start and completion of any test method, and so on. |
Apex Profiling | Includes cumulative profiling information, such as the limits for your namespace, the number of emails sent, and so on. |
Visualforce | Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page. |
System | Includes information about calls to all system methods such as the System.debug method. |
Debug Log Levels:
We can specify the following log levels.
Note: The following are the limits for debug logs:
Example:
Here is a sample debug log I’ve written it in an Apex class, which is the controller of a visualforce page.
System.debug('This is a test debug log');
Now execute that visualforce page on which the code is written.
After execution again go to the Debug Logs page, where the user is added. You will see the screen like below:
As you can see now that new row is added in “Debug Logs” section. click on the “view” button.
Here is the example of Opportunity object, based on Stage Picklist values.
Apex Class:
public class SearchOpportunity { public Opportunity opp {get;set;} public List<Opportunity> OpportunityList {get;set;} public SearchOpportunity () { opp = new Opportunity(); } public PageReference doSearch() { OpportunityList =[Select Id, Name, StageName FROM Opportunity WHERE StageName =: Opp.StageName]; return null; } }
Visualforce Page:
<apex:page controller="SearchOpportunity"> <apex:form> <apex:pageBlock Title="Search Opportunities"> <b>Stage :</b> <apex:inputField value="{!opp.StageName}" /> <apex:commandButton value="Search" action="{!doSearch}"/> </apex:pageBlock> <apex:pageBlock title="List of Opportunities"> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!OpportunityList}" var="item"> <apex:column value="{!item.Name}" headerValue="Name"/> <apex:column value="{!item.StageName}" headerValue="Stage"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Output:
Apex uses the same primitive data types as the SOAP API. All primitive data types are passed by value, not by reference.
All Apex variables, whether they’re class member variables or method variables, are initialized to null. Make sure that you initialize your variables to appropriate values before using them. For example, initialize a Boolean variable to false.
Integer i = 1;
Long l = 2147483648L;
Double d = 3.14159;
Double d = 256.32;
String str = 'Biswajeet Samal';
Date myDate = Date.newinstance(2015, 09, 14); Output: 2015-09-14 00:00:00
Time tm = newInstance(10,12,5,11); Output: 10:12:05
Date dt = Datetime.now();
ID id='00910000004T2AGAA0';
If you set ID to a 15-character value, Apex converts the value to its 18-character representation. All invalid ID values are rejected with a runtime exception.
Boolean isValid = true;
It stores files data in binary format.
SELECT Id, IsSandbox, Name FROM Organization LIMIT 1
If IsSandbox is true, the it is Sandbox Org else it is Production Org.