Thursday, 13 September 2018

                             Queueable Apex:


Queueable Apex is similar to future methods, but provide additional job chaining and allow more complex data types to be used.

Queueable Apex allows you to submit jobs for asynchronous processing similar to future methods with the following additional benefits:
  • Non-primitive types: Your Queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types. Those objects can be accessed when the job executes.
  • Monitoring: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the AsyncApexJob record. You can use this ID to identify your job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.
  • Chaining jobs: You can chain one job to another job by starting a second job from a running job. Chaining jobs is useful if you need to do some sequential processing.
---------------------------------------------------------------------------------------------------------------------
Queueable Apex:

public class QueueableExample implements Queueable {
public void execute(QueueableContext context) {
        Account a = new Account(Name='Annappa',Phone='11111111');
       insert a;     
    }
}
----------------------------------------------------------------------------------------------------------------------
Execute:

ID jobID = System.enqueueJob(new QueueableExample());
system.debug(jobId);

-------------------------------------------------------------------------------------------------------------------------

Eliminate bad code coverage data for Apex classes:


Issue: There may be times where we see a different code coverage value than the actual value. This might be caused due to bad code coverage data or aggregate results from previous test runs.

Solution: To eliminate any bad code coverage data in your organization you can follow the steps mentioned below.

For Classic:
---------------------------------------------------------------------------------
First re-run all tests in your organization: 
---------------------------------------------------------------------------------
1a) Setup | Develop | Apex Test Execution
  b) View Test History
  c) Clear test data.

2 a) Setup | Develop | Apex Classes
  b) Compile all classes

3 a) Setup | Develop | Apex Test Execution
 b) Select tests | "My Namespace" | Select all
 c) Click run

4 a) Setup | Develop | Apex Classes
  b) Estimate your organization's code coverage

  ---------------------------------------------------------------------------------
To Remove Bad data:
---------------------------------------------------------------------------------
1 a) Open Developer console
  b) Execute the following query in "Query Editor" with "Tooling API" checked.

SELECT Id, NumLinesUncovered FROM ApexCodeCoverageAggregate WHERE NumLinesUncovered = NULL

c) Select all the returned rows and hit "Delete Row"
d) Try to estimate the code coverage again
---------------------------------------------------------------------------------

                        Error while updating debug log trace flag


Some times we will receive below error while setting  debug log trace flag for user

"Having an active trace flag triggers debug logging. You have 259 MB of the maximum 250 MB of debug logs. Before you can edit trace flags, delete some debug logs."

Solution:

  • In dev console, Select tab "Query Editor" at the bottom of the console
  • Select check box "Use Tooling API"
  • Use this query: SELECT Id FROM ApexLog
  • Delete all rows

Once all rows are deleted you will be able to save new debug logs.