Showing posts with label salesforce training.. Show all posts
Showing posts with label salesforce training.. Show all posts

Friday, July 18, 2014

What is the Difference between Roles and Profiles in salesforce?

What is the Difference between Roles and Profiles in salesforce?

Roles

In salesforce, roles are defined so as to increase the data visibility a particular user has. The data visibility can be increased using sharing rules or by building role hierarchy. Role hierarchy allows the user sitting in higher level have access of records owned by users having role lower in hierarchy. It is not mandatory that a user should have a role.

Organisation wide default sets the default access for objects, for example OWD set as private would mean that only the owner of the record can access the record. One way to grant additional access of these records to other users is through roles i.e users higher in role hierarchy would get the access of records owned by users lower in hierarchy. Other way is by writing sharing rules, wherein we can specify the logic to decide which record should be shared and with what role user. We can specify against custom objects whether the records should be shared using role hierarchy or not but this is default set for standard objects and cannot be changed. That is, standard object records will always be shared according to role hierarchy. Defining role for users is not a mandatory thing, however not defining role for a user could affect the data shown on opportunity and other reports for that user.
Summarizing the points for role,

1. Role controls the level of record access user has
2. Helps extend the OWD settings for different objects
3. Sharing rules can be written to share records with particular role and subordinates
4. Defining role for user is not mandatory. 


Profiles

Unlike role,  profile is mandatory for every user in salesforce. You cannot have a user without a profile. It is the building pillar of the entire org. Profile states the objects/field permissions and also other permissions with in the org. It defines what a user can do within the org, it states the access settings and user permissions. Profile controls following -
  • Object permissions [create, delete,read, edit permissions] 
  • field permissions [view, edit]
  • Record type permission 
  • Which Apps can be viewed 
  • Login hours can be defined 
  • IP address permissions 
  • Which tabs are visible 
  • Which page layouts can be viewed  
  • Classes, vf pages permissions
Salesforce provides some standard profiles with different set of permissions for each, we can create our own profiles to have permissions as per our requirement. New profile should be cloned from existing profile.

Difference between the two can be summarized as below

1. Role defines what user can see depending on the hierarchy(Helps in defining data visibility)
2. Profile defines what a user can do within the org(Defines various permissions)
3. Defining profile for a user is mandatory, role is not.











Monday, June 16, 2014

How to Execute the Batch Apex Class for Every 30 minutes?

We can achieve using System.schedule method.

Below is the Example – we need to execute this from the system log or anonymous apex section of the IDE:

batchApexMethod exeClass = new batchApexMethod();
String cronStr = '0 0,30 * * * *';
System.schedule('Process Accs Job', cronStr, exeClass);


for More info you can check using below link






Sunday, April 13, 2014

What is difference between SOQL and SOSL?

What is difference between SOQL and SOSL?




SOQL
SOSL
SOQL (Salesforce Object Query Language ) retrieves the records from the database by using “SELECT” keyword.
SOSL(Salesforce Object Search Language) retrieves the records from the database by using the “FIND” keyword.
By Using SOQL we can know in Which objects or fields the data resides.
By using SOSL, we don’t know in which object or field the data resides.
We can retrieve data from single object or from multiple objects that are related to each other.
We can retrieve multiple objects and field values efficiently when the objects may or may not be related to each other.
We can Query on only one table.
We can query on multiple tables.


What is SOSL in Apex?

What is SOSL in Apex?


Salesforce Object Search Language (SOSL) is a simple language for searching across all multiple persisted objects simultaneously.
  1. Sosl statements evaluate to a list of SObjects where each list contains the search results for a particular sobject type.
  2. SOSL queries are only supported in apex classes and anonymous blocks.
  3. We can not use a SOSL query in trigger.

EX:-
The following example that searches all fields across all account and contact objects.

List<List< Sobject>> searchList = [FIND ‘Text*’  IN ALL FIELDS RETURNING Account,Contact];
system.debug(‘searchlist is :’+searchList );

Ex2 : - The Example shows the data with test in Accounts,Contacts,Leads,Oppotunities with Vf page.

Vf  Page :-

<apex:page controller="DeferenceDemoController">
 <apex:form >
    <apex:commandButton value="Show records using SOSL" action="{!soslDemo_method}"/>
    <apex:pageBlock title="Accounts">
      <apex:pageblockTable value="{!accList }" var="acc">
         <apex:column value="{!acc.name}"/>
         <apex:column value="{!acc.Type}"/>
      </apex:pageblockTable>
    </apex:pageBlock>
<apex:pageBlock title="Contacts">
    <apex:pageblockTable value="{!conList}" var="con">
     <apex:column value="{!con.name}"/>
     <apex:column value="{!con.email}"/>
</apex:pageblockTable>
</apex:pageBlock>
<apex:pageBlock title="Leads">
    <apex:pageblockTable value="{!leaList}" var="lea">
     <apex:column value="{!lea.name}"/>
     <apex:column value="{!lea.company}"/>
    </apex:pageblockTable>
</apex:pageBlock>
<apex:pageBlock title="Opportunities">
    <apex:pageblockTable value="{!optyList}" var="opty">
     <apex:column value="{!opty.name}"/>
    <apex:column value="{!opty.StageName}"/>
</apex:pageblockTable>
</apex:pageBlock>
 </apex:form>
</apex:page>

Apex Controller :-

Public with sharing class DeferenceDemoController {
Public List<Opportunity> optyList {get;set;}
Public List<Lead> leaList{get;set;}
Public List<contact> conList{get;set;}
Public List<account> accList{get;set;}
  Public DeferenceDemoController(){
  }
 Public void soslDemo_method(){
  optyList = New List<Opportunity>();
  leaList = New List<Lead>();
  conList = New List<contact>();
  accList = New List<account>();
  List<List <sObject>> searchList = [FIND 'test' IN ALL FIELDS RETURNING  Account (Id,Name,type),Contact(name,email),Opportunity(name,StageName),Lead(company,name,status) ];
  accList = ((List<Account>)searchList[0]);
  conList  = ((List<contact>)searchList[1]);
  optyList = ((List<Opportunity>)searchList[2]);
  leaList  = ((List<Lead>)searchList[3]);
 }
}






What is SOQL in Apex?

What is SOQL in Apex?


Salesforce Object Query Language (SOQL) is a query-only language. While similar to SQL in some ways, it's an object query language that uses relationships, not joins, for a more intuitive navigation of data. This is the main query language that is used for data retrieval of a single sOobject and its related sObjects. 

SOQL Query Examples
A SOQL query is enclosed between square brackets.

sObject s = [SELECT Id, Name FROM Merchandise__c WHERE Name='Pencils'];

A SOQL statement is centered on a single database object, specifying one or more fields to retrieve from it.The fields to select are separated by commas.

Simple SOQL Statement

SELECT Id, Name FROM Account

Filtering Records

SOQL supports filter conditions to reduce the number of records returned.A filter condition
consists of a field name to filter, an operator, and a literal value.
Valid operators are

> (greater than),
< (less than),
>= (greater than or equal to),
<= (less than or equal to),
= (equal to),
!= (not equal to),
IN and NOT IN (matches a list of literal values, and supports semi-joins and anti-joins), and INCLUDES and EXCLUDES (match against multi-select picklist values).

On String fields the LIKE operator is also available,
which applies a pattern to filter records.The pattern uses the % wildcard to match zero or
more characters, _ to match one character, and the \ character to escape the % and _
wildcards, treating them as regular characters.

EX: -

SELECT Name
FROM Account
WHERE AnnualRevenue > 100000000
AND Type = 'Customer - Direct'
AND LastModifiedDate = THIS_YEAR

SOQL Statement with Record Limit

SELECT Name, Type
FROM Account
WHERE LastModifiedDate = TODAY
LIMIT 10

Sorting Query Results

Results of a query can be sorted by up to 32 fields in ascending (ASC, the default) or descending (DESC) order. Sorting is not case-sensitive, and nulls appear first unless otherwise specified (NULLS LAST).Multi-select picklists, long text areas, and reference type fields cannot be used as sort fields.

EX: -

SELECT Name, Type, AnnualRevenue
FROM Account
ORDER BY Type, LastModifiedDate DESC

Querying Multiple Objects

The result of a SOQL query can be a simple list of records containing rows and columns or hierarchies of records containing data from multiple, related objects. Relationships between objects are navigated implicitly from the database structure.

The two ways to navigate object relationships in SOQL are child-to-parent and parent-to-child.

SOQL with Child-to-Parent Relationship
EX: -

SELECT Name, Contact__r.MailingCity, Contact__r.CreatedBy.Name
FROM Resource__c
WHERE Contact__r.MailingState = 'IL'

At most, five levels of parent objects can be referenced in a single child-to-parent query, and the query cannot reference more than 25 relationships in total.

SOQL with Parent-to-Child Relationship

The second form of relationship query is the parent-to-child query.

EX: -

SELECT Id, Name,
(SELECT Total_Hours__c
FROM Timecards__r
WHERE Week_Ending__c = THIS_MONTH)
FROM Resource__c

Note: A parent-to-child query cannot reference more than twenty child objects.

SOQL Query in Apex Using SOQL For Loop

Decimal totalHours = 0;
for (Proj__c project : [ SELECT Total_Billable_Hours_Invoiced__c FROM Proj__c
WHERE Start_Date__c = THIS_YEAR ]) {
  totalHours += project.Total_Billable_Hours_Invoiced__c;
}







Thursday, April 10, 2014

What is interface in Apex and how to create interface in apex?

What is interface in Apex and how to create interface in apex?


An interface is like a class in which none of the methods have been implemented the method signatures are there, but the body of each method is empty. To use an interface, another class must implement it by providing a body for all of the methods contained in the interface.

Defining an interface is similar to defining a new class.For example, a company might have two types of purchase orders, ones that come from customers, and others that come from their employees. Both are a type of purchase order. Suppose you needed a method to provide a discount. The amount of the discount can depend on the type of purchase order.

An interface can extend another interface. As with classes, when an interface extends another interface, all the methods and properties of the extended interface are available to the extending interface

Interface:
public interface PurchaseOrder {
// All other functionality excluded
Double discount();
}



Implemented Class:

// One implementation of the interface for customers
public virtual class CustomerPurchaseOrder implements PurchaseOrder {
public virtual Double discount() {
return .05; // Flat 5% discount
}
}








What is an object?

What is an object?


An object is an instance of a class.

All objects have state and behavior, that is, things that an object knows about itself, and things that an object can do. The state of a PurchaseOrder object—what it knows—includes the user who sent it, the date and time it was created, and whether it was flagged as important. The behavior of a PurchaseOrder object—what it can do—includes checking inventory, shipping a product, or notifying a customer.

ex:-

Order__c orderObj = new Order__c();


here “orderObj  “ is the object of the Order__c.


Wednesday, April 9, 2014

What is Class and How to define Class in Apex?

What is Class and How to define Class in Apex? How to created class in Apex?


A class is a template or blueprint from which objects are created.For example, the PurchaseOrder class describes an entire purchase order, and everything that you can do with a purchase order. An instance of the PurchaseOrder class is a specific purchase order that you send or receive.

A class can contain variables and methods. Variables are used to specify the state of an object, such as the object's Name or Type. Since these variables are associated with a class and are members of it, they are commonly referred to as member variables. Methods are used to control behavior, such as getOtherQuotes or copyLineItems.

To define a class, specify the following:

1. Access modifiers:
  • You must use one of the access modifiers (such as public or global) in the declaration of a top-level class.
  • You do not have to use an access modifier in the declaration of an inner class.

2. Optional definition modifiers (such as virtual, abstract, and so on)

3. Required: The keyword class followed by the name of the class

4. Optional extensions and/or implementations

Use the following syntax for defining classes:

private | public | global
[virtual | abstract | with sharing | without sharing | (none)]
class ClassName [implements InterfaceNameList | (none)] [extends ClassName | (none)]
{
// The body of the class
}

• The private access modifier declares that this class is only known locally, that is, only by this section of code. This is the default access for inner classes—that is, if you don't specify an access modifier for an inner class, it is considered private. This keyword can only be used with inner classes.

• The public access modifier declares that this class is visible in your application or namespace.

• The global access modifier declares that this class is known by all Apex code everywhere. All classes that contain methods defined with the webService keyword must be declared as global. If a method or inner class is declared as global, the outer, top-level class must also be defined as global.

• The with sharing and without sharing keywords specify the sharing mode for this class.

• The virtual definition modifier declares that this class allows extension and overrides. You cannot override a method with the override keyword unless the class has been defined as virtual.

• The abstract definition modifier declares that this class contains abstract methods, that is, methods that only have their signature declared and no body defined.

Declaring Class Variables :

To declare a variable, specify the following:
• Optional: Modifiers, such as public or final, as well as static.
• Required: The data type of the variable, such as String or Boolean etc...
• Required: The name of the variable.
• Optional: The value of the variable.

Use the following syntax when defining a variable:
[public | private | protected | global | final] [static] data_type variable_name [= value]

For example:

private static final Integer MY_INT;
private final Integer i = 1;





 
| ,