Tuesday, January 31, 2017

Which interface needs to be implemented in Apex to be used in Flow ?

We can execute apex as well using flow by annotating it with “@InvocableMethod” and marking method as static. However this method only takes one parameter of type list. If we want to send multiple parameters, then simplest way is to create comma separated list of argument and pass it. In this method, we can break it and use according. Below is sample code.
Global class Flow_UpdateAccountField {    
    @InvocableMethod
    public static void performUpdate(List<String> lstCSV){
        List<String> recIds = lstCSV[0].split(',');
        //0 - AccId, 1-field1__c
  Account acc = new Account(Id=recIds[0], field1__c=recIds[1]);
  update acc;        
    } 

}

Tuesday, January 17, 2017

Which custom fields or relationships in salesforce ends with “__pc” and “__pr” ?

In normal scenario all custom fields ends with “__c” and relationships ends with “__r” However for Person accounts, custom fields ends with “__pc” and custom relationship ends with “__pr”.

How to query and abort scheduled job using Apex.

While updating class on Sandboxes, chances are high that it is being used in any scheduler, so below code will abort all scheduled job. If there are 150+ scheduled job, then you might want to use below code again and again in developer console until all jobs are removed from system.


//Limit is 150 because System.abortJob counted against DML 
List<CronTrigger> abort_job = [SELECT Id FROM CronTrigger 
                               WHERE State != 'Deleted' limit 150];
    for (CronTrigger t : abort_job) { //for each record
//try catch - to make sure one fail should not impact other jobs which needs to be cancelled
     try{
        System.abortJob(t.Id); //abort the job
     }catch(Exception e){}
     
    }

Monday, January 9, 2017

Which fields cannot be added as a custom Index?

  • multi-select picklists
  • text area (long)
  • text area (rich)
  • non-deterministic formula fields (Like any formula field using function NOW() or Today() )
  • encrypted text fields

When records are created in Salesforce, How it is queued for Indexing?

If newly created records are equal to or less than 9000, then it will be indexed in 1 to 3 minutes. However if records are more than 9000, then servers perform bulk indexing at a lower priority, so processing might take longer.

What are the fields with Databases index?

Below are the standard and custom fields with database index in salesforce.

A) ID
B) Name
C) OwnerID
D) CreatedDate
E) RecordType
F) SystemModstamp
G) Unique Fields
H) External ID fields
I) Master-Detail fields (custom fields are treated as custom indexes for index selectivity conditions and thresholds)
J) Lookup fields (treated as custom indexes for index selectivity conditions and thresholds)

How can we see field is indexed from Salesforce UI?

To see a field is indexed or not, go to fields section of any object and see if index column is checked or not. See the below screenshot for Account object.