Trigger.new : Returns a list of the new versions of the sObject records. Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.
Trigger.old : Returns a list of the old versions of the sObject records. Note that this sObject list is only available in update and delete triggers.
Truncating a custom object allows Salesforce to delete all records from particular objects and save the empty object and its metadata. This is a fast way to delete all records from custom objects compared to Import Wizard and Data Import Wizard. This action will remove records from custom objects and you cannot recover them from the recycle bin.
Enable Truncate for custom objects: Before using this feature for your organization, you must enable it. To do this, follow these instructions:
- Go to Setup | Build | Customize | User Interface.
- 2. On the user interface page, navigate to the Setup section.
- Select the Enable Custom Object Truncate checkbox, as shown in the following screenshot:
- Click on Save.
Performing Truncate for custom objects: You can use this feature when you have created a custom object and filled it with test records. To delete those test records with a single action, you can use this feature. To perform this action, follow these instructions:
- Go to Setup | Build | Create | Objects.
- Identify the object on which you want to perform this action and click on an object name to go to its detail page. In this example, Waypoint Object is selected.
- Click on the Truncate button, as shown in the following screenshot:
- It will pop up a window. Read the warning message carefully and type the
object name as shown in the following screenshot:
- Click on the Truncate button to complete the process.
- Truncating a custom object permanently removes all of its records.
- You can’t recover the records from the Recycle Bin.
- A copy of the truncated object appears in the Deleted Objects list for 15 days, during this period the object and its records continue to count toward your organization’s limits, and then the copied object and its records are permanently deleted.
- You cannot truncate object with one or more child objects as containing data, this include Master-Detail and Lookup relationship.
- If you have any auto-number field, the number will be continue from truncated object.
- You cannot truncate custom objects, that are referenced by another object through a lookup field or that are on the master side of a master-detail relationship.
- You cannot truncate custom objects, that are referenced in a reporting snapshot, or have a custom index or an external ID, or have activated skinny tables.
Integer len = 5;
String str = string.valueof(Math.abs(Crypto.getRandomLong()));
String randomNumber = str.substring(0, len);
system.debug('Random Number-' + randomNumber);
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:
- Database changes
- HTTP callouts
- Apex errors
- Resources used by Apex
- Automated workflow process, such as :
- Workflow rules
- Assignment rules
- Approval processes
- Validation rules
Debug Log Categories:
We can specify the following log categories. The amount of information logged for each category depends on the log level:
||Includes information about database activity, including every data manipulation language (DML) statement or inline SOQL or SOSL query.
||Includes information for workflow rules, flows, and processes, such as the rule name, the actions taken, and so on.
||Includes information about validation rules, such as the name of the rule, whether the rule evaluated true or false, and so on.
||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.
||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.
||Includes cumulative profiling information, such as the limits for your namespace, the number of emails sent, and so on.
||Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.
||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:
- Once a user is added, that user can record up to 20 debug logs. After a user reaches this limit, debug logs stop being recorded for that user. Click Reset on the Monitoring Debug logs page to reset the number of logs for that user back to 20. Any existing logs are not overwritten.
- Each debug log can only be 2 MB. Debug logs that are larger than 2 MB are reduced in size by removing older log lines, such as log lines for earlier System.debug statements. The log lines can be removed from any location, not just the start of the debug log.
- Each organization can retain up to 50 MB of debug logs. Once your organization has reached 50 MB of debug logs, the oldest debug logs start being overwritten.
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.