Saturday, 25 October 2014

How to move record types using Apache ANT tool in Salesforce?

1. Execute the below Query in https://workbench.developerforce.com.

Query:

SELECT SobjectType, DeveloperName FROM RecordType

2. Copy the result in an excel file.

3. Use Concatenate excel function to create like below

<members>SobjectType.DeveloperName</members>

4. Copy all the concatenated SobjectName.DeveloperName in the package.xml like below

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Account.Sample1</members>
<members>Account.Sample2</members>
<name>RecordType</name>
</types>
<types>
<members>*</members>
<name>Profile</name>
</types>
<types>
<members>*</members>
<name>Layout</name>
</types>
<version>30.0</version>
</Package>

5. Retrieve and then deploy.

How to use Checkbox field in Formula(Text) in Salesforce?

Use IF() to use Checkbox field in Formula(Text) in Salesforce.

Example:
IF(checkbox field, 'True', 'False')

How to query setup objects in Developer console in Salesforce?

Enable "Use Tooling API" to query setup objects in Developer console in Salesforce.


How to stop emails in Salesforce?

The Email Notification can be turned off or the level can be changed using the below steps

1.       From Setup, click Email Administration --> Deliverability.
2.       Set the Access Level.

No access: Prevents all outbound email to and from users.
System email only: Allows only automatically generated emails, such as new user and password reset emails.
All email: Allows all types of outbound email. Default for new, non-sandbox organizations.

Reference - https://help.salesforce.com/apex/HTViewHelpDoc?id=emailadmin_deliverability.htm

Triggers - Best Practices in Salesforce

1. Future methods, SOQL and DML:

    Avoid writing Future methods, SOQL and DML inside the "For" loop.

2. Bulkify the trigger:

    Start developing the logic for bulk of records getting inserted or updated or deleted. Trigger will be invoked when we insert bulk of records from any data loading tools or through Web services. So, we should not concentrate on 1 record, we have to concentrate on bulk of records.

3. Larger sets of records:

    Use SOQL in For loop, to avoid 50001 limit error.

Account[] accts = [SELECT id FROM account];

Exception will be thrown, if there are more than 50000 records.

for (List<Account> acct : [SELECT id, name FROM account WHERE name LIKE 'Test']) {

    // Your logic here

    update acct;
}

The Force.com platform chunk your large query results into batches of 200 records by using this syntax where the SOQL query is in the for loop definition, and then handle the individual datasets in the for loop logic.

4. Make use of the Limits Apex Methods to check whether we are nearing Governor Limits.

Number of SOQL Queries allowed in this Apex code context - Limits.getLimitQueries()

Number of records that can be queried  in this Apex code context - Limits.getLimitDmlRows()

Number of DML statements allowed in this Apex code context - Limits.getLimitDmlStatements()

Number of CPU usage time (in ms) allowed in this Apex code context - Limits.getLimitCpuTime()


5. Never hardcode SFDC record ids.

Unlisted Groups in Salesforce.com

Setup --> Chatter --> Settings --> Edit --> Enable Unlisted Groups.

Unlisted groups are similar to private groups in that only members can view an unlisted group’s feed or files. However, unlisted groups provide more privacy compared to private groups.

1. Membership for unlisted groups is by invitation only. Nonmembers can’t ask to join them.
Unlisted groups don’t display in list views, feeds, and search results for nonmembers. Only members and users with the “Manage Unlisted Groups” permission can find and access an unlisted group.

2. You can’t see unlisted groups on a user’s profile in Chatter unless you have access to the group.
Even users with the “Modify All Data” or “View All Data” permissions can’t access an unlisted group unless they’re members or they have the “Manage Unlisted Groups” permission.
Nonmembers can’t visit the group detail page. (With private groups, nonmembers can see a truncated version of the detail page, which shows the name, description, and member list, but not the feed or files.)

3. Chatter enforces group name uniqueness across public, private, and unlisted groups. If a user tries to create a group with the same name as an unlisted group, they’ll see an error message that informs them that a group by the same name exists. For this reason, we recommend that you don’t include sensitive information in unlisted group names. Choose names that are difficult to guess or not obvious. For example, don’t use an obvious name like Acme Merger.


Limitations:

1. If you decide to create an unlisted group, make sure that you consider these limitations.
Custom pages or third-party applications integrated with Salesforce could expose unlisted group information to users who don't have access via the Salesforce UI. Check in with your administrator about who can access information in unlisted groups in your organization.

2. After creating an unlisted group, you can’t change it to a private or public group. You also can’t change a private or public group to an unlisted group.

3. You can’t use topics in unlisted groups. You can add a hashtag topic when writing a post or comment in an unlisted group, and the topic will be formatted as a link after you post. However, a topic detail page isn’t created, and the link won’t work.

4. You can’t mention unlisted groups in posts or comments.

How to search in multiple files in Notepad++?

1. Go to Search --> Find in Files


2. Enter the text to search and select the folder.

How to use Record type in formula field in Salesforce?



Sample Formula Field:



Output:


System.QueryException: invalid ID field: null in salesforce

To avoid "System.QueryException: invalid ID field: null", before adding to a list or set, check whether you are adding null.

For example, check the below code

set<Id> acctIds = new set<Id>();
for(Contact con : contactList) {
    acctIds.add(con.AccountId);
}

List<Account> listAccount = [SELECT Id, Name FROM Account WHERE ID IN: acctIds];

Account is not a required field in Contact. So, there is a chance for this field to be blank. You can rewrite the logic as below.

Code to avoid null in SOQL:

set<Id> acctIds = new set<Id>();
for(Contact con : contactList) {
    if(con.AccountId != null) {
        acctIds.add(con.AccountId);
    }
}

List<Account> listAccount = [SELECT Id, Name FROM Account WHERE ID IN: acctIds];

Account is not a required field in Contact. So, there is a chance for this field to be blank. So, before adding it to the set, I have checked whether it is null.

ASP.NET - Server Controls

Controls are small building blocks of the graphical user interface, which includes text boxes, buttons, check boxes, list boxes, labels and numerous other tools, using which users can enter data, make selections and indicate their preferences.
Controls are also used for structural jobs, like validation, data access, security, creating master pages, data manipulation.
ASP.Net uses five types of web controls, which are:
  • HTML controls
  • HTML Server controls
  • ASP.Net Server controls
  • ASP.Net Ajax Server controls
  • User controls and custom controls
ASP.Net server controls are the primary controls used in ASP.Net. These controls again could be grouped into the following categories:
  • Validation controls - these are used to validate user input and work by running client-side script
  • Data source controls - these controls provides data binding to different data sources
  • Data view controls - these are various lists and tables, which can bind to data from data sources for display
  • Personalization controls - these are used for personalization of a page according to the user's preference, based on user information
  • Login and security controls - these controls provide user authentication
  • Master pages - these provides consistent layout and interface throughout the application
  • Navigation controls - these helps in navigation, for example, the menus, tree view etc.
  • Rich controls - these implements special features, for example, AdRotator control, FileUpload control, Calendar control etc.
The basic syntax for using server controls is:
<asp:controlType  ID ="ControlID"
                     runat="server"
                     Property1=value1  [Property2=value2] />
However, visual studio has the following features, which helps in error free coding:
  • Dragging and dropping of controls in design view
  • IntelliSense feature that displays and auto-completes the properties
  • The properties window to set the property values directly
Properties of the Server Controls
The ASP.Net server controls with a visual aspect are derived from the WebControl class and inherit all the properties, events and methods of this class.
The WebControl class itself and some other server controls that are not visually rendered, e.g., the PlaceHolder control or XML control etc., are derived from the System.Web.UI.Control class.
ASP.Net server controls inherit all properties, events and methods of the WebControl and System.Web.UI.Control class.
The following table shows the inherited properties, which are common to all server controls:

Property
Description
AccessKey
Pressing this key with the Alt key moves focus to the control
Attributes
It's the collection of arbitrary attributes (for rendering only) that do not correspond to properties on the control.
BackColor
Background colour.
BindingContainer
The control that contains this control's data binding.
BorderColor
Border colour.
BorderStyle
Border style.
BorderWidth
Border width.
CausesValidation
Indicates if it causes validation.
ChildControlCreated
It indicates whether the server control's child controls have been created.
ClientID
Control ID for HTML markup.
Context
The HttpContext object associated with the server control.
Controls
Collection of all controls contained within the control
ControlStyle
The style of the Web server control.
CssClass
CSS class
DataItemContainer
Gets a reference to the naming container if the naming container implements IDataItemContainer.
DataKeysContainer
Gets a reference to the naming container if the naming container implements IDataKeysControl.
DesignMode
It indicates whether the control is being used on a design surface.
DisabledCssClass
Gets or sets the CSS class to apply to the rendered HTML element when the control is disabled.
Enabled
Indicates whether the control is grayed out
EnableTheming
Indicates whether theming applies to the control.
EnableViewState
Indicates whether the view state of the control is maintained.
Events
Gets a list of event handler delegates for the control.
Font
Font .
Forecolor
Foreground colour.
HasAttributes
Indicates whether the control has attributes set.
HasChildViewState
indicates whether the current server control's child controls have any saved view-state settings.
Height
Height in pixels or %.
ID
Identifier for the control.
IsChildControlStateCleared
Indicates whether controls contained within this control have control state.
IsEnabled
Gets a value indicating whether the control is enabled
IsTrackingViewState
It indicates whether the server control is saving changes to its view state.
IsViewStateEnabled
It indicates whether view state is enabled for this control.
LoadViewStateById
It indicates whether the control participates in loading its view state by ID instead of index.
Page
Page containing the control.
Parent
Parent control.
RenderingCompatibility
It specifies the ASP.NET version that rendered HTML will be compatible with.
Site
The container that hosts the current control when rendered on a design surface.
SkinID
Gets or sets the skin to apply to the control. (
Style
Gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control.
TabIndex
Gets or sets the tab index of the Web server control.
TagKey
Gets the HtmlTextWriterTag value that corresponds to this Web server control.
TagName
Gets the name of the control tag.
TemplateControl
The template that contains this control.
TemplateSourceDirectory
Gets the virtual directory of the Page or control containing this control.
ToolTip
Gets or sets the text displayed when the mouse pointer hovers over the Web server control.
UniqueID
Unique identifier
ViewState
Gets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page.
ViewStateIgnoreCase
It indicates whether the StateBag object is case-insensitive.
ViewStateMode
Gets or sets the view-state mode of this control.
Visible
It indicates whether a server control is visible.
Width
Gets or sets the width of the Web server control.