Tag Archives: Salesforce

Difference Between Deactivate User and Freeze User in Salesforce

Deactivate User:

  • Deactivating a user in Salesforce means that user will not be deleted from the system but will no longer be able to log in to Salesforce and their records can be transferred to another user. They cannot be part of workflows or part of any automated processes.
  • Deactivating a user will be available user licenses available for use in your organization.
  • Deactivated users lose access to any records that were manually shared with them, or records that were shared with them as team members. Users higher in the role hierarchy relative to the deactivated users also lose access to those records. However, you can still transfer their data to other users and view their names on the Users page.

Freeze User:

  • Freezing a user in Salesforce means that only stops the user from being able to login.
  • In some cases, you can’t immediately deactivate a user (such as when a user is selected in a custom hierarchy field or a user that’s assigned as the sole recipient of a workflow email alert). To prevent users from logging into your organization while you perform the steps to deactivate them, you can freeze user accounts.
  • Freezing user accounts doesn’t make their user licenses available for use in your organization.

Apex Trigger Context Variables

All triggers define implicit variables that allow developers to access runtime context.
These variables are contained in the System.Trigger class:

Variable Usage
isExecuting Returns true if the current context for the Apex
code is a trigger, not a Visualforce page,
a Web service, or an executeanonymous()
API
call.
isInsert Returns true if this trigger
was fired due to an insert operation, from the Salesforce user
interface, Apex,
or the API.
isUpdate Returns true if this trigger
was fired due to an update operation, from the Salesforce user
interface, Apex,
or the API.
isDelete Returns true if this trigger
was fired due to a delete operation, from the Salesforce user
interface, Apex,
or the API.
isBefore Returns true if this trigger
was fired before any record was saved.
isAfter Returns true if this trigger
was fired after all records were saved.
isUndelete Returns true if this trigger
was fired after a record is recovered from the Recycle Bin (that is, after an undelete operation from the Salesforce user
interface, Apex,
or the API.)
new Returns a list of the new versions of the sObject records. This
sObject list is only available in insert, update,
and undelete triggers, and the
records can only be modified in before triggers.
newMap A map of IDs to the new versions of the sObject records. This map
is only available in before
update
, after
insert
, after
update
, and after
undelete
triggers.
old Returns a list of the old versions of the sObject records. This
sObject list is only available in update and delete
triggers.
oldMap A map of IDs to the old versions of the sObject records. This map
is only available in update and
delete triggers.
size The total number of records in a trigger invocation, both old and
new.

Global Picklist Value Set in Salesforce

Global Picklist or Picklist Value Set is an Universal Picklist Values, which can be applied to any custom picklist fields that you create both on standard and custom objects.

Lets take an example, I have an object called “Student” and “Student Application” in these two object I have to create a picklist field called “Language”. So, here I’ve created a “Picklist Value Set” and used it on both object “Student Application”.

Click Setup || App Setup || Create || Picklist Value Set || Click ‘New’

Create “Language” Picklist Value Set:

Create “Language” Picklist from Picklist Value Set in “Student” and “Student Application” object:

Check “Language” Picklist Value Set, where it is used:

Note: You can have up to 500 picklist global value sets in an org. Each global value set, or restricted picklist, can contain a mix of 1,000 active and inactive values. Unrestricted picklists can have up to 1,000 active values. There’s no limit on the number of custom picklists that use global picklist value sets.

Picklist Value Set Considerations:

  • Validation rules are still defined at the field level, and are not part of the Picklist Value Set definition. This means, you can have the Business Unit picklist field on Account to respect a validation rule; and the same field on the Contact object not.
  • It is possible to create a mutli-select picklist field using a Picklist Value Set definition. However, in such cases the “replace” functionality available on regular picklist fields are not available.
  • Also, a picklist field created based on a Picklist Value Set cannot be used as a dependent picklist. It can still be used as a controlling picklist field. This is a known and documented limitation.

Field Set in Salesforce

A field set is a grouping of fields, you can use the field set in visualforce page to display group of fields in that page dynamically. No need to do code modifications to the page, In field set only you can add, remove & reorder fields. Generally these field sets are useful in managed packages. If the page is added to a managed package, administrators can add, remove, or reorder fields in a field set to modify the fields presented on the Visualforce page without modifying any code. Field sets are available for Visualforce pages on API version 21.0 or above. You can have up to 50 field sets referenced on a single page.

Here the below example is on a custom object “Project__c”.
To create a field set, go to object.
Create field set by clicking on new button in field set section.

Enter required fields and save.

We will get below screen to add fields to field set, where We can drag and drop fields.
Add the necessary fields to field set and save it.

Property of Field Set:

Property Name Description
DBRequired Indicates whether the field is required for the
object
FieldPath Lists the field’s spanning info
Label The UI label for the field
Required Indicates whether the field is required in the field
set
Type The data type for the field

Working with Field Sets Using Visualforce:
Field sets can be directly referenced in Visualforce by combining the $ObjectType global variable with the keyword FieldSets. Here in below Visualforce page the above created Field Set is referenced.

<apex:page standardController="Project__c">
    <apex:form>
        <apex:pageblock>
            <apex:pageblockSection>
                <apex:repeat value="{!$ObjectType.Project__c.FieldSets.Project}" var="f"> 
                    <apex:inputField value="{!Project__c[f.fieldPath]}" required="{!OR(f.required, f.dbrequired)}"/>
                </apex:repeat>
            </apex:pageblockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>

The above code displays all fields in the field set. See the below screen to see the output of above code.

If this Visualforce page is added to a managed package and distributed, subscribers can edit the Project field set. The logic for generating the Visualforce page remains the same, while the presentation differs based on each subscriber’s implementation. To reference a field set from a managed package, you must prepend the field set with the organization’s namespace. Using the markup above, if Project comes from an managed package called TestManagedPackage, the field set is referenced like this:

{!$ObjectType.Project__c.FieldSets.TestManagedPackage__Project}

Working with Field Sets Using Apex:
Fields in a field set are automatically loaded when your Visualforce page uses a standard controller. When using a custom controller, you need to add the required fields to the SOQL query for the page. Apex provides two Schema objects that allow you to discover field sets and the fields they contain, Schema.FieldSet and Schema.FieldSetMember.

Here is an example to display a Field Set on a Visualforce Page using apex.

To dynamically get all the fields from “Project” Field Set we can use Schema.FieldSet and Schema.FieldSetMember methods.

Controller:

public class Sample{

    public Project__c proj { get; set; }
    
    public Sample() {
        this.proj = new Project__c();
    }

    public List<Schema.FieldSetMember> getFields() {
        return SObjectType.Project__c.FieldSets.Project.getFields();
    }
}

Visualforce Page:

<apex:page controller="Sample">
    <apex:form >
        <apex:pageBlock title="Project">            
            <apex:pageBlockSection>
                <apex:repeat value="{!fields}" var="f">
                    <apex:inputField value="{!proj[f.fieldPath]}" required="{!OR(f.required, f.dbrequired)}"/>
            </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

The above code displays all fields in the “Project” field set. See the below screen to see the output of above code.

Field Set Considerations:

  • Fields added to a field set can be in one of two categories:
    • If a field is marked as Available for the Field Set, it exists in the field set, but the developer hasn’t presented it on the packaged Visualforce page. Administrators can display the field after the field set is deployed by moving it from the Available column to the In the Field Set column.
    • If a field is marked as In the Field Set, the developer has rendered the field on the packaged Visualforce page by default. Administrators can remove the field from the page after the field set is deployed by removing it from the In the Field Set column.
  • The order in which a developer lists displayed fields determines their order of appearance on a Visualforce page.