Thursday 8 December 2016

SQOL to know Code coverage in Salesforce


Salesforce provides developers a way to find out Codecoverage details. 
Write a SQOL by using  “ApexCodeCoverageAggregate”  to know Code coverage for all Apex Classes and Apex Triggers withing fraction of seconds. 

* SOQL :

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate


Tips : 

* Use of "ORDER BY" clause will let you have your result more presentable.

e.g. 

SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY  ApexClassOrTrigger.Name ASC




* Make sure that you have enabled "Use Tooling API" check box in Developer Console to execute following query.  (see following image - Red circle)




Tuesday 5 January 2016

@ReadOnly


 
  @ReadOnly
 

  •  Because of Limitations like 'Maximum no.of items in a collection that can be iterated is 1000' or 'generally query in VF should not go beyong 50,000 rows'.  It was not possible to show millions of records on VF page.                                                                                                     But thanks to @ReadOnly annotation in API version 23.0 now we can !
  • Only available for Web services and the Schedulable interface.
  • Used for methods.
  • Allows you to perform unrestricted queries against the Force.com database.  All other limits still apply.
  • To use the @ReadOnly annotation, the top level request must be in the schedule execution or the Web service invocation. 
   For example, if a Visualforce page calls a Web service that contains the @ReadOnly annotation, the request fails because Visualforce is the top level request, not the Web service.


  • ReadOnly mode restricts you from DML Operations, calls to System.Schedule, Sending an emails, calls to @Future annoted methods.
  • @ ReadOnly methods should also have @Remote action annotation and either global/public or static access specifiers.
  • Visualforce controller methods with the @ReadOnly annotation automatically take advantage of read-only mode and help us to retrieve a larger collection of records.
  • Very helpful and handy in a visualforce controller for building super custom reports.


  More : 
  https://success.salesforce.com/ideaView?id=08730000000kourAAA

@Deprecated


 @Deprecated  

  • Used in managed packages
  • Any classes,methods, interfaces, exceptions,variables or enums ,etc which can no longer be referenced in subsequent releases (of that Managed Package).
  • Mostly used when you are refactoring / making more changes/improvements in your Managed Package as the requirements evolve.
  • It restricts new subscribers to see "deprecated" elements while existing subscribers/API integrations  get proper functioning elements as they were.
  • All 'global' modifiers need to be 'deprecated' as who referred your 'decprecated' element.
  • Unmanaged packages cannot contain code that uses the deprecated keyword.
  • Can't use with WebSerivces
  • Enum, Interface, Abstract classes need to depcrecated totally - cant decpracate individual method or individual enum value.

 EXAMPLE : 

       
            // This method is deprecated. Use myOptimizedMethod(String a, String b) instead.
  @deprecated 
  global void myMethod(String a) { 
 }