Monday, August 19, 2013

Custom Links:

Custom Links:
Custom links are hyperlinks that can include Salesforce fields as tokens within a URL or on
Visualforce pages. For example, you could include an account name in a URL that searches Yahoo:

Pass Session IDs with SSL
Session IDs should never be passed to an “http” URL. Instead, pass session IDs with a secure
sockets layer (SSL) “https” URL. Any data that is passed to other applications hosted on the
Internet should always use SSL since it may contain sensitive customer information.

Use Relative Links to Salesforce Pages
When creating a custom link to a page within Salesforce, do not include the domain portion
of the URL. For example,
https://na1.salesforce.com/00Oz0000000EVpU&pv0={!Account_ID} should
not include https://na1.salesforce.com. Instead, use
/00Oz0000000EVpU&pv0={!Account_ID}.

Use Merge Fields to Pass Salesforce Data
You can add merge fields to a custom link to pass data from your Salesforce records, user
information, or company information to another website or application.
Use ampersands to pass multiple merge fields in a custom link. For example:
http://maps.yahoo.com/py/maps.py?cn={!Account_BillingCountry}&
csz={!Account_ShippingCity}+{!Account_ShippingState}+{!Account_ShippingPostalCode}+&
addr={!Account_ShippingAddress}.


Substitute Symbols for Certain Characters
Due to URL encoding standards set forth by the World Wide Web Consortium (W3C),
some characters cannot be passed through a URL. For example, the space and newline
character. Instead, use %2D for a space and %0D for a newline. For more information on
URL encoding and what characters cannot be passed through a URL, see W3C.

Linking to Documents
Use custom links to reference documents from any Salesforce record detail page:
1. Create a folder on the Documents tab to which all users have access.
2. Upload the document to that folder.
3. From the Documents tab, choose the folder and click Go.
4. Click View next to the document.
5. Copy the document’s URL from the browser. For example,
https://na1.salesforce.com/servlet/servlet.FileDownload?file=015300000000xvU.
6. Use the URL to create the custom link. Remember to omit the domain portion,
https://na1.salesforce.com.

Linking to Reports
Use custom links to run reports with filtered results from any Salesforce record detail page. For
example, if you frequently run a mailing list report for the contacts related to an account, create a
custom link for accounts that links directly to a report that is automatically filtered to the account
you are viewing. To do this, your custom link needs to pass the account’s unique record ID to the
report.
1. First, you will need an ID for the type of record by which you want to filter your report (in this
example, an account). View any record of the right type and copy the 15 character ID from the
last part of the URL. For example, https://na1.salesforce.com/001200030012j3J.
2. From the Reports tab, create the report you want by either customizing a standard report or
creating a new custom report.
3. On the Select Criteria page of the wizard, filter the report by the record ID you previously
copied. For example, “Account ID equals 001200030012j3J”. See the sidebar on the left for
tips on setting other report options.
4. Run the report to verify that it contains the data you expect.
5. Click Customize and navigate to the Select Criteria page of the wizard.
6. Delete the record ID from the report filter, but leave the field and operator values intact. Note
the order of your filter, for example, first, second, third, etc.
7. Click Save or Save As to save the report to a public folder accessible by the appropriate users.
Save does not create a new custom report, whereas Save As does.
8. Run the report and copy the report’s URL from the browser.
9. Begin creating your custom link. In the Link URL field, paste the report URL you copied.
Remember to omit the domain portion, https://na1.salesforce.com.
10. At the end of the URL add the following text: ?pv0=. Use pv0 if your filter is in the first position,
pv1 if second, pv2 if third, and so on. Then use the merge field drop-down lists to add the
appropriate ID merge field (in this example, {!Account_ID}). For example,
/00O30000000dS8u?pv0={!Account_ID}.
11. Add the custom link to the appropriate page layouts.
12. Verify that the new custom link works correctly.

Setting Report Options
• When creating a report for use in a custom link, set date ranges and report options generically
so that report results include a variety of data that can be useful for multiple users.
• For example, if you set a date range using the “Created Date” of a record, set the Start Date far
enough in the past to not exclude any relevant records and leave the End Date blank.
• For example, if you scope the report to just “My” records, the report may not include all records
that a user can see. Try setting the report options to “All visible” records

Best Practices for Advanced Users
Pre-Populate Fields
Create custom links that pre-populate fields with default values. For example, by default give
new contracts 12–month terms that start today.
Get the names of the fields you want to pre-populate by opening the detail page where the
custom link will display. Click New from the appropriate related list.
For example, to add a custom link that creates contracts on the account detail page, click New
from the Contracts related list of an account detail page. If the Contracts related list is not
visible on the account detail page, add it to the related list section of the account page layout;
see “Customizing Page Layouts” in the online help.
Copy the URL from the address bar of your Web browser. For example:
https://na1.salesforce.com/003/e?retURL=%2F001D0000003qFmB&
accid=001D0000003qFmB
In your browser, view the source of the contract edit page. In Internet Explorer, select View
> Source; in Mozilla Firefox, select View > Page Source.
Search the page source for the label of the fields you want to pre-populate. For example, to
pre-populate the Contract Term field on contracts, search for “Contract Term.”
For each field, locate the relevant <input> tag—usually within the immediate <td> (table
cell) tag. Copy the text after name=. For example, from <input name="ctrc40"/>, copy
ctrc40. See the sidebar for more information about these field names.
From Setup, click Customize > Accounts > Buttons, Links, and Actions to begin creating
your custom link. Name the new link appropriately, such as “New 12–Month Contract.” In
the field entry area, paste the URL you copied from the address bar of your Web browser..
Remember to omit the domain portion, https://na1.salesforce.com.
Delete the 15-character ID from the URL after “acc_id”. Use the merge field drop-down
lists to add the appropriate ID merge field. For example, {!Account_ID}.
Insert the link parameters using the following syntax: “&{field input name}=desired
field value.” For example, the following link sets the contract term to 12 months with a
start date of today:
/800/e?retURL=%2F001D0000003pmTi&accid={!Account.Id}&
ctrc40=12&ctrc5={!Today}
Add the custom link to the appropriate page layouts.
Verify that the new custom link works correctly. Note that custom links can alternatively be
configured as custom buttons; see “Defining Custom Buttons and Links” in the online help.
Custom Links Do Not Support Data Type Conversion
When creating custom links to pass data from one Salesforce field to another, the data must
match the data type of the fields in which you are placing it. For example, if you have numeric
data, you must pass it to a numeric field.
Single Sign-On
Use custom links to pass a session ID to support Single Sign-On (SSO), so users can avoid
multiple logins to web applications that your organization hosts to manage Force.com data.
To do this, construct your custom link to pass the {!User_Session_ID} merge field. This
allows users to access all authorized resources during a single authentication. External systems
can access Salesforce resources using a web service, which allows organizations to communicate
data without intimate knowledge of each other's IT systems behind a firewall.
Send the Server Date in the URL
Some integration projects may need custom links to include a server date to know the Salesforce
initiation date. The Salesforce server date can be passed to external systems using custom
links. For example, http://someurl.com/somepath?current_date={!Today}.
Dates use the Pacific time zone.
Avoid Double Sets of Tabs in a Browser
Unlimited Edition and Enterprise Edition users can build a custom link to perform an action
that keeps users in the same browser window and does not display a double set of tabs. Create
a Visualforce page that contains the following code, replacing <REGULAR_WIL> with your
regular or existing custom link.
<script language="JavaScript">
function redirect() {
parent.frames.location.replace("<REGULAR_WIL>")
}
redirect();

</script>

Saturday, August 17, 2013

OOP (Object Oriented Programming) in SFDC:

OOP (Object Oriented Programming) in SFDC:
In apex you use classes to define what objects will be able to do.A class consists of methods and attributes.The methods of a class describe what an object of a class will be able to do.The attributes of  a class describe the state of the class or the instance of the class.
To define a class ,you first need to specify the access modifier as private, public or global .Next ,you can specify optional definition modifiers such as virtual , abstract, with sharing or without sharing.After you define modifiers you need to specify the keyword class , the unique name of the class and optional implementations and extensions.Finally in the body of the class you can define your own attributes and methods.

A class can implement multiple interfaces , but only  extend one class. A class can cast as a super class and verify an objects class using the instanceof keyword.You can implement interfaces and extend classes using the keywords virtual, abstract and extends.Except anonymous blocks all apex code executes in system mode when the code executes in the system mode it ignores all create, run , update and delete permissions on objects field level security and record level sharing privileges.Salesforce provides sharing models to execute apex code with just the rows available to the operating user.These sharing models enable you to enforce record level access within the context of a common or shared environment.


Interfaces are classes that only include the method signature.The methods are not implemented in the interfaces.Another class must be created to supply the implementation.
Methods and Attributes access modifiers are Private, Protected, Public, Global
Static attributes and methods do not require an instance of an object to run.They can shared by objects based on the class in which static attributes and methods are defined.
How to instantiate an object
How to overload constructors
Developers can use this keyword to represents the methods and attributes of the current instance of a class.
Apex includes various classes in its system-delivered class library.Two such classes System and User info

Apex run time engine strictly enforces a number of limits on resources due to the multi-tenant environment.
Apex also contains built in methods to help manage these limits.These methods can be utilized for debugging and printing messages.some of them shown below.two versions getDMLStatements(), getLimitDMLStatements()...
Apex provides support to  programmatically control the workflow with apex process classes and approval namespace.You can use apex process classes to submit workflow requests and process the results of those requests.You can use the apex approval namespace to create and submit an approval request.
Summary

Friday, August 16, 2013

Data Types:

Data Types:
Each variable and expression belong to a specific data type.Different data types shown below
some primitive data types associate with methods
sObject data type shown below
A collection data type can store groups of elements of other primitive, composite, or collection data types.A collection data type does not have any restrictions on the number of elements it can hold.but you should be careful not to exceed the heap size.You use the limit methods to check the heap size.Collection data types shown below
List Data Type shown below
Set Data Type shown below
Map Data Type shown below

Developers use loop statements to repeatedly execute a set of statements.Apex supports following loop types do-while, while, traditional for loop, list or set iteration for loop, soql for loop.
Summary
some of the anonymous blocks examples are
//--------------------------------------------------------------------------------------------
//TASK 1: Create a Hello World anonymous block.
//TODO: Write a single line to output the text "Hello World!" to the results window
System.debug('Hello World!');

//--------------------------------------------------------------------------------------------
//TASK 2: Create a map of integers and check if the map contains a specific key.
//TODO: Instantiate a map called “numbers” that has an integer as keys and a string as values.
Map<Integer, String> numbers = new Map<Integer, String>();

//TODO: Create a FOR loop that loops 100 times and adds the values 0 thru 99 as the key and the string value of the number as the value of the map.
for (Integer i=0; i<100; i++){
  numbers.put(i, String.valueof(i));
}

//TODO: Create an IF statement that verifies that the map contains the value 35 and display the value using a System.debug statement.
if (numbers.containskey(35)){
   System.debug('The answer is: ' + numbers.get(35));
}

//--------------------------------------------------------------------------------------------
//TASK 3: Create a list of new accounts with unique names.
//TODO: Instantiate a list of Account data types
List<Account> accts = new List<Account>();

//TODO: Create a loop to add 20 new accounts to the list with a unique name for each account.
for (Integer i=0; i<20; i++){
  Account a = new Account(name='Account Name' + i);
  accts.add(a);

Monday, August 12, 2013

APEX :

APEX :
Apex is built on the Force.com platform and therefore it is plugged into other Force.com features.Apex allows developers to create highly complex, transactional and intelligent code.Apex is strongly tied with data structures and business logic needs.

Apex Benefits
Apex is governed and can only do what the system allows.Differences between apex and java

Classes and Triggers are two primary components constructed within salesforce when you write the apex code.When developers save apex code they always save it as a class or a trigger.

Apex is a proprietary language that sits within the Force.com platform and it can be invoked through triggers and classes.How to invoke apex
Syntax looks like this
Apex architecture looks like this
If the declarative features do not provide the  required functionality ,developers can use apex.

Use cases :
and a simple Hello world apex class and trigger
public class HelloWorldPositionClass {

public static void helloWorld(List<Position__c> positions){

for (Position__c p:positions){
if (p.Hello__c != 'World') {
p.Hello__c = 'World';
}
}
}
}

trigger HelloWorldPositionTrigger on Position__c (before insert, before update) {

    List<Position__c> positions = Trigger.new;

HelloWorldPositionClass.helloWorld(positions);

}

Summary of apex