Wednesday, October 26, 2016

Access salesforce API version of a class in Apex

This can be achieved by using following steps
1. Login to your sandbox.
2. Go to Developer Console.
3. Go to Debug menu and click on Open Execute Anonymous Window
4. Paste the following code in that window.
ApexClass apexClass = [
  SELECT ApiVersion
  FROM ApexClass
  WHERE Name = 'YourClass Name'
];
System.debug(apexClass.ApiVersion);
5.Run this code.
6. This will print the  API version of your Apex class.

Thursday, June 23, 2016

What are different kinds of dashboard component

1. Chart: Use a chart when you want to show data graphically.
2. Gauge: Use a gauge when you have a single value that you want to show within a range of custom values.
3. Metric: Use a metric when you have one key value to display.
  • Enter metric labels directly on components by clicking the empty text field next to the grand total.
  • Metric components placed directly above and below each other in a dashboard column are displayed together as a single component.
4. Table: Use a table to show a set of report data in column form.
5. Visualforce Page: Use a Visualforce page when you want to create a custom component or show information not available in another component type
6. Custom S-Control: Custom S-Controls can contain any type of content that you can display or run in a browser, for example, a Java applet, an ActiveX control, an Excel file, or a custom HTML Web form

Wednesday, June 8, 2016

What is Permission sets in Salesforce.

A permission set is a collection of settings and permissions that give users access to various tools and functions. The settings and permissions in permission sets are also found in profiles, but permission sets extend users’ functional access without changing their profiles. 

For example, to give users access to a custom object, create a permission set, enable the required permissions for the object, and assign the permission set to the users. You never have to change profiles, or create a profile for a single use case. While users can have only one profile, they can have multiple permission sets.
Permission sets include settings for:
  • Assigned apps
  • Object settings, which include:
  • Tab settings
  • Object permissions
  • Field permissions
  • App permissions
  • Apex class access
  • Visualforce page access
  • System permissions
  • Service providers (only if you’ve enabled Salesforce as an identity provider)

In salesforce which fields are indexed automatically?

The following fields are indexed by default:

  • primary keys (Id, Name and Owner fields),
  • foreign keys (lookup or master-detail relationship fields),
  • audit dates (such as LastModifiedDate),
  • Custom fields marked as External ID or Unique

Tuesday, April 5, 2016

How to Get a List of Fields Set on an sObject in Apex

I recently had a requirement to dynamically determine what fields had been set or queried on a sObject, so that a comparison could be done on what was actually stored in Salesforce's Datastore.

Surprisingly, there's no way method on the sObject that let's you tell what's actually been queried or set. So without further ado, here's the method that I decided to use because it's much faster than doing a describe and catching every exception.



public class Utils {
    //Takes in an sObject and determines what values 
//have been queried or set on the page.
 public static Set<String> getFieldsSet(sObject obj)
    {
        if (obj == null)
            return new Set<String>();
             
  Map<String, Object> fieldValues = 
(Map<String, Object>) JSON.deserializeUntyped(JSON.serialize(obj));
         
   if (fieldValues.containsKey('attributes'))
      fieldValues.remove('attributes');
         
        return fieldValues.keySet();
    }
}

How to Dynamically Tell if a Salesforce Field Exists

I have been working on a lot of dynamic apex and soql. I had a requirement to develop a custom appexchange app that could be dynamically querying objects based on a mapping that the admin had supplied and had stored in custom settings.

Originally, I was querying to see if the field existed and returning true if a result was received but this ended taking a lot longer than doing a describe.

I wasn’t able to find any information on how to really tell if a field exists or not. Without further ado, doesFieldExist will return true if the object and field both exist. If the object has been removed and the code hasn’t caught that it will also return false. And finally, if the object exists but the field doesn’t it will return false.

public boolean doesFieldExist(String objName, string fieldName)
    {
   try {
     SObject so = Schema.getGlobalDescribe().get(objName)
.newSObject();
   return so.getSobjectType().getDescribe().fields.getMap()
.containsKey(fieldName);
        }
        catch(Exception ex) {}
         
        return false;
    }

Tuesday, March 29, 2016

Sunday, March 20, 2016

what is the difference between isNull and isBlank?

ISNULL:
  
  •        Determines if an expression is null (blank) and returns TRUE if it is. If it contains a value, this function returns FALSE.
  •         Text fields are never null, so using this function with a text field always returns false. For example, the formula field IF(ISNULL(new__c) 1, 0) is always zero regardless of the value in the New field. For text fields, use the ISBLANK function instead.
  •         Multi-select picklist fields are never null in s-controls, buttons, and email templates, so using this function with a multi-select picklist field in those contexts always returns false.
  •         Empty date and date/time fields always return true when referenced in ISNULL functions.
  •         Choose Treat blank fields as blanks for your formula when referencing a number, percent, or currency field in an ISNULL function. Choosing Treat blank fields as zeroes gives blank fields the value of zero so none of them will be null.
  •         Merge fields can be handled as blanks, which can affect the results of components like s-controls because they can call this function.
  •         When using a validation rule to ensure that a number field contains a specific value, use the ISNULL function to include fields that do not contain any value. For example, to validate that a custom field contains a value of ’1,’ use the following validation rule to display an error if the field is blank or any other number: OR(ISNULL(field__c), field__c<>1)

     ISBLANK:
  •      Determines if an expression has a value and returns TRUE if it does not. If it contains a value, this function returns FALSE.
  •       Use ISBLANK instead of ISNULL in new formulas. ISBLANK has the same functionality as ISNULL, but also supports text fields. Salesforce.com will continue to support ISNULL, so you do not need to change any existing formulas.
  •      A field is not empty if it contains a character, blank space, or zero. For example, a field that contains a space inserted with the spacebar is not empty.
  •      Use the BLANKVALUE function to return a specified string if the field does not have a value; use the ISBLANK function if you only want to check if the field has a value.
  •      If you use this function with a numeric field, the function only returns TRUE if the field has no value and is not configured to treat blank fields as zeroes.