351. Onchange event does not work with
<apex:actionsupport> in IE9. How to resolve this error?
If we add the Header on Visualforce page then
it creates lots of problem in IE9. I think there are few java-script library
loaded by Header of Salesforce which makes IE9 compatible. So the best solution
is to enable the Header by using “showHeader=true” in Apex page.
352. If IE9 is not working with your custom
visualforce page then how to tell your visualforce code to run in IE8
compatibility mode?
Add following metatag to pages:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
353. It may happen that above tips will not work
as lots of time the page header already set. Then, how to achieve same result
using Apex?
Add below line of code in Apex (Constructor)
Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
354. How to display the formatted number / date in
Visualforce? Which component should be used?
Use component “<apex:outputText>”.
Example : Format the number into currency.
<apex:outputtext value="{0, number,
000,000.00}">
<apex:param value="{!valFromController}" />
</apex:outputtext>
OR
<apex:outputtext value="{0, number,
###,###.00}">
<apex:param value="{!valFromController}" />
</apex:outputtext>
355. You want to display the Encrypted field on
Visualforce and you are using component apex:outputText. Will it work for
Encrypted fields?
Encrypted custom fields that are embedded in
the <apex:outputText> component display in clear text. The
<apex:outputText> component doesn’t respect the View Encrypted Data
permission for users. To prevent showing sensitive information to unauthorized
users, use the <apex:outputField> tag instead.
356. Will below query work? Explain.
SELECT COUNT(Id), Name,
Address__c FROM Opportunity GROUP BY Name
Above query will throw an error.
Explanation: In Group by clause the columns
selected must be either used in Group by clause or in aggregate functions. The
Name field is neither used in aggregate methods and in group by clause and
hence will result in error “Malformed Query”.
357. Explain difference in COUNT() and
COUNT(fieldname) in SOQL.
COUNT()
· COUNT() must be the only element in the SELECT list.
· You can use COUNT() with a LIMIT clause.
· You can’t use COUNT() with an ORDER BY clause. Use
COUNT(fieldName) instead.
· You can’t use COUNT() with a GROUP BY clause for API version
19.0 and later. Use COUNT(fieldName) instead.
COUNT(fieldName)
· You can use COUNT(fieldName) with an ORDER BY clause.
· You can use COUNT(fieldName) with a GROUP BY clause for API
version 19.0 and later.
358. How to write the “Where” clause in SOQL when
Group By is used?
We cannot use the “Where” clause with Group By
instead we will need to use the “Having Clause“.
Example:
Get all the opportunity where more than one
record exists with same name and name contains “ABC”.
SELECT COUNT(Id)
, Name FROM Opportunity GROUP BY Name Having COUNT(Id)
> 1 AND Name like '%ABC%'
359. Let’s consider that the first component in VF
page is the Datepicker. In that case whenever the page loads, salesforce auto
focus the first component resulting in Datepicker onfocus event. Because of
this the Datepicker component opens automatically. How we can avoid this?
On load event, write the javascript code to
autofocus any other field or any other non-visible component.
Example :
<span id="focusDistraction"></span>
<script type="text/javascript">
/* prevent autopup of the
date inputfield by the default focus behavoir */
window.onload=function()
{
document.getElementById('focusDistraction').focus();
}
</script>
360. How to force lead assignment rule via Apex
while updating or adding the Lead?
To enforce Assignment Rules in Apex you will
need to perform following steps:
1. Instantiate the “Database.DMLOptions”
class.
2. Set the “useDefaultRule” property of
“assignmentRuleHeader” to True.
3. Finally call a native method on your Lead
called “setOptions”, with the Database.DMLOptions instance as the argument.
// to turn ON the Assignment Rules in Apex
Database.DMLOptions dmlOptn
= new Database.DMLOptions();
dmlOptn.assignmentRuleHeader.useDefaultRule
= true;
leadObj.setOptions(dmlOptn);
361. Access custom controller-defined enum in
custom component?
We cannot reference the enum directly since
the enum itself is not visible to the page and you can’t make it a property.
Example:
Apex class:
global with sharing class My_Controller
{
public Case currCase {get; set;
}
public enum StatusValue
{RED, YELLOW, GREEN}
public StatusValues
getColorStatus() {
return StatusValue.RED; //demo
code - just return red
}
}
Visualforce page:
<apex:image url='stopsign.png' rendered="{!colorStatus
== StatusValue.RED}"/>
Above code snippet will throw error something
like “Save Error: Unknown property‘My_Controller.statusValue’”
Resolution:
Add below method in Apex Controller:
public String currentStatusValue {
get{ return getColorStatus().name(); }}
and change Visualforce code to
<apex:image url='stopsign.png' rendered="{!currentStatusValue
== 'RED'}" />
362. What is the need of “Custom Controller” in
Visualforce as everything can be done by the combination of Standard Controller
+ Extension class.
· Sharing setting is applied on standard object/extension by
default; In case we don’t want to apply sharing setting in our code then Custom
controller is only option.
· It is possible that the functionality of page does not required
any Standard object or may require more than one standard object, then in that
case Custom controller is required.
363. In class declaration if we don’t write
keyword “with sharing” then it runs in system mode then why keyword “without
sharing” is introduced in apex?
Let’s take example, there
is classA declared using “with sharing” and it
calls classB method. classB is not declared with any keyword then by
default “with sharing” will be applied to that class because originating call
is done through classA. To avoid this we have to explicitly define classB with
keyword “without sharing”.
364. If user doesn’t have any right on particular
record and have only read level access at object level. Can he change the record
owner?
Yes. In profile, there is setting for
“Transfer Record”.
365. In Which Scenario share object
“MyCustomObject__share” is not available/created for custom object
“MyCustomObject” ?
The object’s organization-wide default access
level must not be set to the most permissive access level. For custom
Objects, that is Public Read/Write.
366. How to get the picklist value in Apex class?
Using Dynamic apex, we can achieve this. On
object of type pickilist, call getDescribe(). Then call the getPicklistValues() method.
Iterate over result and create a list. Bind it to <apex:selectOptions>.
Code Example:
Let’s say we have a custom object called
OfficeLocation__c. This object contains a picklist field Country__c.
The first thing we need to do, within our
controller is use the getDescribe() method to obtain information on
the Country__c field:
Schema.DescribeFieldResult fieldResult =
OfficeLocation__c.Country__c.getDEscribe();
We know that Country__c is a
picklist, so we want to retrieve the picklist values:
List<Schema.PicklistEntry> ple =
fieldResult.gerPicklistValues();
The only thing left for us to do is map the
picklist values into an <apex:selectOptions> tag can use for
display. Here is the entire method from our controller to do this:
public List<SelectOption>
getCountries()
{
List<SelectOption>
options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult =
OfficeLocation__c.Country__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(
Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return
options;
}
With our controller
logic all complete, we can call the getCountries() method from our Visualforce
page, and populate the <apex:selectList> tag:
<apex:selectList
id="countries" value="{!Office_Location__c.Country__c}"
size="1" required="true">
<apex:selectOptions
value="{!countries}"/>
</apex:selectList>
367. What are the types of controller in visual
force?
There are basically two types of Controller in
Visual force page.
1.
Standard Controller and
2. Custom Controller
368. How many Controllers can be used on single VF
page?
Only one controller can be used salesforce.
Other than them, Controller extension can be used.
There may be more than one Controller
extension.
Example:
<apex:page standardController="Account"
extensions="ExtOne,ExtTwo" showHeader="false">
<apex:outputText value="{!foo}" />
</apex:page>
if ExtOne and ExtTwo, both have the
method getFoo() then the method of ExtOne will be executed.
A controller extension is any Apex class that
contains a constructor that takes a single argument of
typeApexPages.StandardController or CustomControllerName, where
CustomControllerName is the name of a custom controller that you want to
extend.
369. Explain System.runAs()
Generally, all Apex code runs in system mode,
and the permissions and record sharing of the current user are not taken into
account. The system method, System.runAs(), lets you write test methods
that change user contexts to either an existing user or a new user. All of that
user’s record sharing is then enforced. You can only use runAs in a test
method. The original system context is started again after all runAs() test
methods complete.
Example :
System.runAs(u) {
// The following code runs as user 'u'
System.debug('Current User: ' +
UserInfo.getUserName());
System.debug('Current Profile: ' +
UserInfo.getProfileId()); }
// Run some code that checks record sharing
}
370. Explain Test.setPage().
It is used to set the context to current page,
normally used for testing the visual force controller.
371. Difference between SOSL and SOQL in
Salesforce ?
SOSL
|
SOQL
|
Stands for "Salesforce object search
language".
|
Stands for "Salesforce object query
language".
|
Works on multiple object at a same time.
|
Need to write different SOQL for different
object.
|
All fields are already text indexed.
|
SOQL against same field will be slow.
|
Cannot used in Triggers. Can only be used in
Apex class and anonymous block.
|
Can be used in Apex class and Triggers.
|
372. How to round the double to two decimal places
in Apex?
Decimal d = 100/3;
Double ans = d.setScale(2) ;
372. In how many ways we can invoke the Apex
class?
1. Visualforce page
2. Trigger
3.
Web Services
4.
Email Services
373. Can we create Master Detail relationship on
existing records?
No. As discussed above, first we have to
create the lookup relationship then populate the value on all existing record
and then convert it.
374. How validation rules executed? is it page
layout / Visualforce dependent?
The validation rules run at the data model
level, so they are not affected by the UI. Any record that is saved in
Salesforce will run through the validation rules.
375. What is the difference between
database.insert and insert?
insert is the DML statement which is same
as databse.insert.
However, database.insert gives more
flexibility like rollback, default assignment rules etc. we can achieve the database.insert
behavior in insert by using the method setOptions(Database.DMLOptions)
Important Difference:
· If we use the DML statement (insert), then in bulk operation if
error occurs, the execution will stop and Apex code throws an error which can
be handled in try catch block.
· If DML database methods (Database.insert) used, then if error occurs
the remaining records will be inserted / updated means partial DML operation
will be done
376. What is the scope of static variable?
When you declare a method or variable as
static, it’s initialized only once when a class is loaded. Static variables
aren’t transmitted as part of the view state for a Visualforce page.
Static variables are only static within the
scope of the request. They are not static across the server, or across the
entire organization.
377. Other than SOQL and SOSL what is other way to
get custom settings?
Other than SOQL or SOSL, Custom settings have
their own set of methods to access the record.
For example:If there is custom setting of name
ISO_Country,
SO_Country__c code =
ISO_Country__c.getInstance(‘INDIA’);
//To return a map of data sets defined for the
custom object (all records in the custom object), //you would use:
Map<String,ISO_Country__c> mapCodes =
ISO_Country__c.getAll();
// display the ISO code for India
System.debug(‘ISO Code:
‘+mapCodes.get(‘INDIA’).ISO_Code__c);
//Alternatively you can return the map as a list:
List<String> listCodes =
ISO_Country__c.getAll().values();
378. What happens if child have two master records
and one is deleted?
Child record will be deleted.
379. What is Difference in render, rerender and
renderas attributes of visualforce?
render – It works like “display” property
of CSS. Used to show or hide element.
rerender – After Ajax which component
should be refreshed – available on commandlink, commandbutton, actionsupport
etc.
renderas – render page as pdf, doc and
excel.
380. How to get the list of all available sobject
in salesforce database using Apex (Dynamic Apex)?
Map<String, Schema.SObjectType> m =
Schema.getGlobalDescribe();
381. How to create instance of sObject dynamically? Normally the
sObject is created like “Account a = new Account();”. But if you are in
situation that you don’t know which sObject is going to be instantiated? Means
it will be decided at runtime, how you will handle it?
public SObject getNewSobject(String t){
// Call global describe
to get the map of string to token.
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
// Get the token for the
sobject based on the type.
Schema.SObjectType st = gd.get(t);
// Instantiate the
sobject from the token.
Sobject s = st.newSobject();
return s;
}
382. How to get all the fields of sObject using
dynamic Apex?
Map<String, Schema.SObjectType> m =
Schema.getGlobalDescribe() ;
Schema.SObjectType s =
m.get('API_Name_Of_SObject') ;
Schema.DescribeSObjectResult r = s.getDescribe()
;
Map<String,Schema.SObjectField> fields =
r.fields.getMap() ;
383. How to get all the required fields of sObject
dynamically?
There is no direct property available in Apex dynamic
API to represent the required field. However there is another way to know about
it.
If any fields have below three properties then
it is mandatory field.
1. If it is Creatable
2. If it is not nillable and
3.
If it does not have any default value
Map<String, Schema.SObjectType> m =
Schema.getGlobalDescribe() ;
Schema.SObjectType s = m.get(so.apiName) ;
Schema.DescribeSObjectResult r = s.getDescribe()
;
Map<String,Schema.SObjectField> fields =
r.fields.getMap() ;
for(String f : fields.keyset())
{
Schema.DescribeFieldResult
desribeResult = fields.get(f).getDescribe();
if(
desribeResult.isCreateable() && !desribeResult.isNillable()
&& !desribeResult.isDefaultedOnCreate() )
{
//This is mandatory / required field
}
}
384. What is property in Apex? Explain with
advantages.
Apex mainly consists of the syntax from the
well known programming language Java. As a practice of encapsulation in
java we declare any variable as private and then create the setters and getters
for that variable.
private String name;
public void setName(String n)
{
name = n;
}
public String getName()
{
return name;
}
However, the Apex introduced the new concept
of property from language C# as shown below:
public String name {get; set;}
As we can see how simple the code is and
instead of using nearly 8 to 11 lines all done in 1 line only. It will be very
useful when lots of member is declared in Apex class. It has another advantage
in “number of lines of code” limit by salesforce which will drastically reduced.
385. What is the controller extension?
Any apex class having a public constructor
with Custom Controller or Standard Controller object as a single argument is
known as controller extension.
386. Explain the need or importance of the
controller extension.
Controller extension is very useful and
important concept introduced by the salesforce recently. It gives the power to
programmer to extend the functionality of existing custom controller or
standard controller.
A Visualforce can have a single Custom
controller or standard controller but many controller extensions.
We can say that the custom extension is the
supporter of custom or standard controller.
Consider one example: If there is one
controller written and used by the multiple visualforce pages and one of them
needs some extra logic. Then instead of writing that logic to controller class
(Which is used by many visualforce pages) we can create a controller extension
and apply to that page only.
387. How to read the parameter value from the URL
in Apex?
Consider that the parameter name is
“RecordType”.
String recordType =
Apexpages.currentPage().getParameters().get('RecordType');
388. If one object in Salesforce have 2 triggers
which runs “before insert”. Is there any way to control the sequence of
execution of these triggers?
Salesforce.com has documented that trigger sequence cannot
be predefined. As a best practice create one trigger per object and use comment
blocks to separate different logic blocks. By having all logic in one trigger
you may also be able to optimize on your SOQL queries.
389. What is the difference between trigger.new and trigger.old in
Apex – SFDC?
Trigger.new:
Returns a list of the new versions of the sObject records
Note that this sObject list is only available in insert and
update triggers
i.e., Trigger.new is available in before insert, after insert,
before update and after update
In Trigger.new the records can only be modified in before
triggers.
Trigger.old:
Returns a list of the old versions of the sObject records
Note that this sObject list is only available in update and
delete triggers.
i.e., Trigger.old is available in after insert, after update,
before delete and after update.
390. How to restrict any Trigger to fire only once?
Triggers can fire twice, once before workflows and once after
workflows.
“The before and after triggers fire one more time only if
something needs to be updated, If the fields have already been set to a value,
the triggers are not fired again.”
Workaround:
public class HelperClass {
public static boolean firstRun
= true;
}
trigger affectedTrigger on Account (before delete, after delete,
after undelete) {
if(Trigger.isBefore){
if(Trigger.isDelete){
if(HelperClass.firstRun){
Trigger.old[0].addError('Before Account Delete Error');
HelperClass.firstRun=false;
}
}
}
}
394. What are Global variables explain with examples?
Global variables are the variables used to reference the general
information about the current user or your organization on a page.
Example:
Global variables must be referenced
using Visualforce expression syntax to be evaluated, for
example, {!$User.Name}.
List of available global variables are as
below
1. $Action
2. $Api
3. $Component
4. $ComponentLabel
5. $CurrentPage
6. $Label
7. $Label.Site
8. $ObjectType
9. $Organization
10. $Page
11. $Profile
12. $Resource
13. $SControl
14. $Setup
15. $Site
16. $User
17. $UserRole
18. $System.OriginDateTime
19. $ User.UITheme and $User.UIThemeDisplayed
395. How to create Many to Many relationships between object?
Creating Many to Many relationship in salesforce is little
tricky. You cannot create this type of relationship directly. Follow below
steps to create this type of relationship.
Create both objects which should be interlinked.
Create one custom object (also called as junction object),
which should have auto number as unique identification and create two
master relationships for both objects, no need create tab for this object.
Now on both objects, add this field as related list.
396. In which sequence Trigger and automation rules run in
Salesforce.com?
The following is the order salesforce logic is applied to a record.
1. Old record loaded from database (or initialized for new inserts)
2. New record values overwrite old values
3. System Validation Rules
4. All Apex “before” triggers (EE / UE only)
5. Custom Validation Rules
6. Record saved to database (but not committed)
7. Record reloaded from database
8. All Apex “after” triggers (EE / UE only)
9. Assignment rules
10. Auto-response rules
11. Workflow rules
12. Escalation rules
13. Parent Rollup Summary Formula value updated (if
present)
14. Database commit
15. Post-commit logic (sending email)
Additional notes: There is no way to control the order of
execution within each group above.
397. What is S-Control?
S-Controls are the predominant salesforce.com widgets which are
completely based on Javascript. These are hosted by salesforce but executed at
client side. S-Controls are superseded by Visualforce now.
398. What is a Visualforce Page?
Visualforce is the new markup language from salesforce, by using
which, We can render the standard styles of salesforce. We can still use HTML
here in Visualforce. Each visualforce tag always begins with “apex” namespace.
All the design part can be acomplished by using Visualforce Markup Language and
the business logic can be written in custom controllers associated with the
Page.
399. Will Visual force still supports the merge fields usage
like S-control?
Just like S-Controls, Visualforce Pages support embedded merge
fields, like the {!$User.FirstName} used in the example.
400. What are Merge fields? Explain with example?
Merge fields are fields that we can put in Email templates, mail
merge templates, custom link or formula fields to incorporate values from a
record.
Example: {!CustomObject.FieldName__c}
401. Where to write Visualforce code?
You can write the code basically in 3 ways.
1. setup->App Setup->Develop->Pages and create new
Visulaforce page.
2. Setup -> My Personal Information -> Personal Information
-> Edit check the checkbox development mode. When you run the page like
this, https://ap1.salesforce.com/apex/MyTestPage.you will find the Page editor
at the bottom of the page. You can write you page as well as the controller
class associated with it, there itself.
3. Using Eclipse IDE you can create the Visulaforce page and write
the code.
402. What is difference in 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.
403. How to schedule a class in Apex?
To invoke Apex classes to run at specific times, first
implement the Schedulable interface for the class, then specify the
schedule using either the Schedule Apex page in the Salesforce user
interface, or the System.schedule method.
After you implement a class with
the Schedulable interface, use the System.Schedule method
to execute it. The scheduler runs as system: all classes are executed,
whether the user has permission to execute the class or not.
The System.Schedule method takes three arguments: a
name for the job, an expression used to represent the time and date the job is
scheduled to run, and the name of the class.
Salesforce only adds the process to the queue at the scheduled
time. Actual execution may be delayed based on service availability.
The System.Schedule method uses the user's time zone for the basis of
all schedules. You can only have 25 classes scheduled at one time.
Example Code:
String CRON_EXP = '0 0 * * * ?';
clsScheduledHourly sch = new
clsScheduledHourly();
system.schedule('Hourly Sync', CRON_EXP, sch);
404. What are different APIs in salesforce.com?
REST API:
REST API provides a powerful, convenient, and simple REST-based
Web services interface for interacting with Salesforce. Its advantages include
ease of integration and development, and it’s an excellent choice of technology
for use with mobile applications and Web projects. However, if you have a large
number of records to process, you may wish to use Bulk API, which is based on
REST principles and optimized for large sets of data.
SOAP API:
SOAP API provides a powerful, convenient, and simple SOAP-based
Web services interface for interacting with Salesforce.You can use SOAP API to
create, retrieve, update, or delete records. You can also use SOAP API to
perform searches and much more. Use SOAP API in any language that supports Web
services.
For example, you can use SOAP API to integrate Salesforce with
your organization’s ERP and finance systems, deliver real-time sales and
support information to company portals, and populate critical business systems
with customer information.
Chatter API:
Chatter API is a REST API that provides programmatic access to
Chatter feeds and social data such as users, groups, followers, and files. It's
used by developers who want to integrate Chatter into a variety of applications
such as mobile applications, intranet sites, and third-party Web applications.
Chatter API is similar to APIs offered by other companies with feeds, such as
Facebook and Twitter. Its advantages include ease of integration and
development.
Bulk API:
Bulk API is based on REST principles and is optimized for
loading or deleting large sets of data. You can use it to query, insert,
update, upsert, or delete a large number of records asynchronously by
submitting batches which are processed in the background by Salesforce.
SOAP API, in contrast, is optimized for real-time client
applications that update small numbers of records at a time. Although SOAP API
can also be used for processing large numbers of records, when the data sets
contain hundreds of thousands of records, it becomes less practical. Bulk API
is designed to make it simple to process data from a few thousand to millions
of records.
The easiest way to use Bulk API is to enable it for processing
records in Data Loader using CSV files. This avoids the need to write your own
client application.
Metadata API:
Use Metadata API to retrieve, deploy, create, update, or delete
customizations for your organization. The most common use is to migrate changes
from a sandbox or testing organization to your production environment. Metadata
API is intended for managing customizations and for building tools that can
manage the metadata model, not the data itself.
The easiest way to access the functionality in Metadata API is
to use the Force.com IDE or Force.com Migration Tool. These tools are built on
top of Metadata API and use the standard Eclipse and Ant tools respectively to
simplify the task of working with Metadata API. Built on the Eclipse platform,
the Force.com IDE provides a comfortable environment for programmers familiar
with integrated development environments, allowing you to code, compile, test,
and deploy all from within the IDE itself. The Force.com Migration Tool is
ideal if you want to use a script or a command-line utility for moving metadata
between a local directory and a Salesforce organization.
Streaming API:
Use Streaming API to receive notifications for changes to data
that match a SOQL query that you define.
Streaming API is useful when you want notifications to be pushed
from the server to the client. Consider Streaming API for applications that
poll frequently. Applications that have constant polling action against the
Salesforce infrastructure, consuming unnecessary API call and processing time,
would benefit from this API which reduces the number of requests that return no
data. Streaming API is also ideal for applications that require general
notification of data changes. This enables you to reduce the number of API
calls and improve performance.
Apex REST API:
Use Apex REST API when you want to expose your Apex classes and
methods so that external applications can access your code through REST
architecture. Apex REST API supports both OAuth 2.0 and Session ID for
authorization.
Apex SOAP API:
Use Apex SOAP API when you want to expose your Apex methods as
SOAP Web service APIs so that external applications can access your code
through SOAP. Apex SOAP API supports both OAuth 2.0 and Session ID for
authorization.
405. How to display error message on Visualforce page?
In the Visualforce page add the tag:
<apex:pageMessages
/>
In the controller
class add the error message where required
if ( requiredFieldName == null){
ApexPages.addMessage(new
ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter a value in the
Required Field'));
}
406. What is Visualforce View State? And what are best practices to
reduce the view state size?
Visualforce pages that contain a form component
also contain an encrypted, hidden form field that encapsulates the view state
of the page. This view state is automatically created, and as its name
suggests, it holds the state of the page – state that includes the components,
field values and controller state.
Best Practices to reduce the view state size
·
Minimize number of form on a page. Use
apex:actionRegion instead of using 2 or more forms.
·
Refine your SOQL to only retrieve the data
needed by the page.
·
All public and private data members present in
Standard, Custom and Controller extensions are saved.
·
Mark any Apex variables that are not necessary
to the view state as Transient. (The transient variables are not passed to view
state and therefore not stored in View State)
·
Create wizards with as few pages as possible
·
Use outputLink components instead of
commandLink or commandButton components where possible as they don’t need to be
nested in a form.
407. What are custom settings?
Custom settings are similar to custom objects and enable
application developers to create custom sets of data, as well as create and
associate custom data for an organization, profile, or specific user. All
custom settings data is exposed in the application cache, which enables
efficient access without the cost of repeated queries to the database. This
data can then be used by formula fields, validation rules, Apex, and
the SOAP API.
There are two types of custom settings:
List Custom Settings
A type of custom setting that provides a reusable set of static
data that can be accessed across your organization. If you use a particular set
of data frequently within your application, putting that data in a list custom
setting streamlines access to it. Data in list settings does not vary with
profile or user, but is available organization-wide. Because the data is
cached, access is low-cost and efficient: you don't have to use SOQL queries
that count against your governor limits.
Hierarchy Custom Settings
A type of custom setting that uses a built-in hierarchical logic
that lets you “personalize” settings for specific profiles or users. The
hierarchy logic checks the organization, profile, and user settings for the
current user and returns the most specific, or “lowest,” value. In the
hierarchy, settings for an organization are overridden by profile settings,
which, in turn, are overridden by user settings.
408. What is APEX?
It is the in-house technology of salesforce.com which is similar
to Java programming with object oriented concepts and to write our own custom
logic.
• Apex is a procedural scripting language in
discrete and executed by the Force.com platform.
• It runs natively on the Salesforce servers,
making it more powerful and faster than non-server code, such as
JavaScript/AJAX.
• It uses syntax that looks like Java
• Apex can written in triggers that act like
database stored procedures.
• Apex allows developers to attach business
logic to the record save process.
• It has built-in support for unit test
creation and execution.
Apex provides built-in support for common
Force.com platform idioms, including:
• Data manipulation language (DML) calls, such
as INSERT, UPDATE, and DELETE, that include built-in DmlException handling
• Inline Salesforce Object Query Language
(SOQL) and Salesforce Object Search Language (SOSL) queries that return
lists of sObject records
- Looping that allows for bulk processing of
multiple records at a time
- Locking syntax that prevents record update
conflicts
- Custom public Force.com API calls that can
be built from stored Apex methods
- Warnings and errors issued when a user tries
to edit or delete a custom object or field that is referenced by Apex
Note: Apex is included in Unlimited Edition,
Developer Edition, Enterprise Edition, and Database.com
Apex vs. Java: Commonalities
• Both have classes, inheritance,
polymorphism, and other common OOP features.
• Both have the same name variable,
expression, and looping syntax.
• Both have the same block and conditional
statement syntax.
• Both use the same object, array, and comment
notation.
• Both are compiled, strongly-typed, and
transactional.
Apex vs. Java: Differences
• Apex runs in a multi-tenant environment and
is very controlled in its invocation and governor limits.
• To avoid confusion with case-insensitive
SOQL queries, Apex is also case-insensitive.
• Apex is on-demand and is compiled and
executed in cloud.
• Apex is not a general purpose programming
language, but is instead a proprietary language used for specific business
logic functions.
• Apex requires unit testing for development
into a production environment.
409. Explain the Apex Data Manipulation Language (DML) Operations?
Use data manipulation language (DML) operations to insert,
update, delete, and restore data in a database.
You can execute DML operations using two
different forms:
Apex DML statements, such as:
insertSObject[]
Apex DML database methods, such as:
Database.SaveResult[] result =
Database.Insert(SObject[])
While most DML operations are available in
either form, some exist only in one form or the other.
The different DML operation forms enable different types of
exception processing:
· Use DML statements if
you want any error that occurs during bulk DML processing to be thrown as
an Apex exception that immediately interrupts control flow (by
using try. . .catch blocks). This behavior is similar to the way
exceptions are handled in most database procedural languages.
· Use DML database methods if you want to allow partial success of
a bulk DML operation—if a record fails, the remainder of the DML operation can
still succeed. Your application can then inspect the rejected records and
possibly retry the operation. When using this form, you can write code that
never throws DML exception errors. Instead, your code can use the appropriate
results array to judge success or failure. Note that DML database methods also
include a syntax that supports thrown exceptions, similar to DML statements
Pie chart and Bar chart using Apex in Visualforce page
Sample Code:
Visualforce page:
<apex:page controller="Graph" >
<apex:pageblock title="Members and their Years of experience" >
<apex:chart height="250" width="350" data="{!pieData}">
<apex:pieSeries tips="true" dataField="data" labelField="name"/>
<apex:legend position="bottom"/>
</apex:chart>
</apex:pageblock>
<apex:pageblock title="Members and their Years of experience" >
<apex:chart height="250" width="350" data="{!pieData}">
<apex:axis type="Numeric" position="left" fields="data" title="Years of experience"/>
<apex:axis type="Category" position="bottom" fields="name" title="Member"/>
<apex:barSeries orientation="vertical" axis="left" xField="name" yField="data"/>
</apex:chart>
</apex:pageblock>
</apex:page>
Apex Controller:
public with sharing class Graph
{
public List<PieWedgeData> getPieData()
{
List<PieWedgeData> data = new List<PieWedgeData>();
List<Member__c> memb = new List<Member__c>();
String sql = 'SELECT Name, Year_s_Of_Experience__c FROM Member__c';
memb = Database.Query(sql);
for(Member__c temp:memb)
{
data.add(new PieWedgeData(temp.Name,temp.Year_s_Of_Experience__c));
}
return data;
}
// Wrapper class
public class PieWedgeData
{
public String name { get; set; }
public Decimal data { get; set; }
public PieWedgeData(String name, Decimal data)
{
this.name = name;
this.data = data;
}
}
}
Output:
411.Sample Visualforce page and apex controller to display account records based on selected picklist value
note: you can directly copy paste into you developer org
Visualforce Page:
<apex:page standardController="account" extensions="CustomReport">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!account.type}" styleClass="relative">
<apex:actionSupport event="onchange" action="{!recordValues}" reRender="val"/>
</apex:inputField>
</apex:pageBlockSection>
<apex:dataTable value="{!acc}" var="var" id="val">
<apex:column value="{!var.name}" headerValue="Name"/>
<apex:column value="{!var.type}" headerValue="type"/>
<apex:column value="{!var.industry}" headerValue="industry"/>
</apex:dataTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Controller:
public with sharing class CustomReport
{
public list<account> acc{set;get;}
public account acct{set;get;}
public CustomReport(ApexPages.StandardController controller)
{
this.acct = (Account)controller.getRecord();
}
public void recordValues()
{
acc=[select id,name,type,industry from account where type=:acct.type];
}
}
Salesforce Lightning:
1. create domain name for your org :
setup
|-----Adminster
|--------Domain Management
|--------------MyDomain
a. Enter Domain Name
b. Check availabilty
c. Register
4. Click on login button to test the connection
5. Deploy to users so that users can login using this domain url
2. create package : This is optional ,but if you want to provide lightning apps to the external system or if you want to provide this lightning application as Appexchange product then Package creation is a must
=============================================================================================================
Lishtning Application
============================================================================================================
1. Steps to create lightning Application
UserName
|----Developer Console
|---File
|-----Lightning App
|---App name
Note : All the lightning applications will have an extention of .app
Ex: <aura:application>
This is a test application
</aura:applicaiton>
2. <aura: applicaiton >
1. Every lightning application will start and end with <aura:applicaiton> component .
Arributes :
a)access : indicates whether this app can be extended by another app outside of a namespace.
possible values : global and public
b)controller: This is will take name of the Apex class whose functionalities are used in this application..
If you create namespace : :namespace.className.
if you dont create namespace : classname
c.extends:name of the app which need to be extended .
d.extensible:Indicates whether this app can be extended by another app.
possible values : true /false
e)implements:It will take the list of interfaces that the application want to implements.
Ex : implements ="one,two,three"
Note : App can implement more than one interface
=============================================================================================================
Component :
=============================================================================================================
1.<aura:component> :
a. Components are the functional units of Aura,
b. These components encapsulate modular and reusable sections of UI.
c. They can contain other components or HTML markup.
Syntax:
<aura:component>
<!-- Optional component attributes here -->
<!-- Optional HTML markup -->
</aura:component>
d.Attributes :
1)access:indicates whether this component can be extended by another app outside of a namespace.
possible values : global and public
2)controller : This is will take name of the Apex class whose functionalities are used in this Component.
If you create namespace : :namespace.className.
if you dont create namespace : classname
3)extends:name of the component which need to be extended .
4)extensible:Indicates whether this componnent can be extended by another component.
possible values : true /false
5)implements: It will take the list of interfaces that the component want to implements.
Ex : implements ="one,two,three"
Note : Componnet can implement more than one interface
e. Steps to create aura: componet
UserName
|------Developer console
|----File
|----Lightning Componet
|--------------Component Name
Example : capital1.cmp
<aura:component >
<h1> This is a line one </h1>
<h2> This is line two</h2>
<h3> This is line three</h3>
</aura:component>
f. How to invoke the component in the application ;
1. if the you have created any namespace then is should be called using namespace
<namespace: componentName >
Ex: if namespace : capitalInfosol
component name is : example1
<capitalinfosol : example1>
2) if you dont have the namespace then it will be called using defualt namespace i.e c
<c: example1>
Example : one .app
<aura:application >
This is a test app
<c:capital1></c:capital1>
</aura:application>
============================================================================================================
Example 1 : Create an application with multiple components
============================================================================================================
a . Create a new component : student
<aura:component >
<h1> Iam new Student </h1>
<div> This is a test component</div>
</aura:component>
b. create a new component studentAddress
<aura:component >
<div>
Ameerpet <br/>
SRNagar
<br/>
Hyd
<br/>
TG
<br/>
</div>
</aura:component>
c. Create new Application : app2
<auar: application >
<c:student />
<c:studentAddress />
</aura:application>
===========================================================================================================
Example 2: Applying CSS on component
===========================================================================================================
1. create a Component : csscomp.cmp
<aura:component >
<h1> This is line one </h1>
<div class="red"> This is red</div>
<div class="green"> This is green</div>
<div class="blue"> This is blue</div>
</aura:component>
2. Style
: Click on Style button on the right side wizard
:Then it creates csscomp.css
.THIS {
background-color:yellow;
padding-top : 40px;
padding-left :40px;
}
.THIS.red {
background-color: red;
}
.THIS.blue {
background-color: blue;
}
.THIS.green {
background-color: green;
}
3. Application : capital3
<aura: application>
<c:csscomp> </c:csscomp>
<aura :application>
=====================================================================================================
Creating attributes for a component
===================================================================================================
<aura:attribute>
aura:attribute is used to create an attribute on an app, interface, component, or event.
Attributes :
a) access:Indicates whether the attribute can be used outside of its own namespace.
b) name
:Required.The name of the attribute.
c) type
:Required. The type of the attribute.
Possible values (Date,DateTime,Decimal,Double,Integer ,Long ,string ,Boolea )
d) defualt: Value that should be assingned to the attribue if no values are assigned to it.
e) description: A summary of the attribute and its usage
f) required : Specified wheather attribute value need to be required to run this component.
Example :
<aura: attribue name="empName" type="String" defualt="capitalinfo" required="true" />
Examples :
<aura:component >
<aura:attribute name="empName" type="string" />
<aura:attribute name="salary" type="Decimal" required="true" />
<aura:attribute name="city" type="string" default="Hyd" />
<aura:attribute name="phones" type="String[]" description="This contains all phone numbers of account" />
</aura:component>
How to read the values of attributes in the component / appliation
1. we get the values of the atrributes using {! v.attributeName}
Ex : {! v.empName }
Ex :{! v.salary}
Ex :{! v.city}
Ex :{! v.phone}
Example : How to pass the values of the component from application .
a. Create a new Component :employee.cmp
<aura:component >
<aura:attribute name="name" type="string" required="true"/>
<aura:attribute name="exp" type="Decimal" />
<aura:attribute name="City" type="String" default="Hyd" />
<div>
Employee Name : {! v.name} <br/>
Employee Exp : {! v.exp} <br/>
Employee City :{! v.city}
</div>
</aura:component>
b. create style for the component : employee.css
.THIS {
padding-top: 40px;
padding-left:80px;
color: blue;
}
c. Create an application : capital.4
<aura:application >
<c:employee name="Satish Myla" exp="3.4" />
</aura:application>
=============================================================================================================
<aura:handler>
a. This component is used to intialize the values /attributes in the component /application
b. This event istriggered on app or component for initialization.
c. This event is automatically fired when an app or component is has initializations prior to rendering. T
Attributes :
a .name
: It should be alwasys "init" only
b. value
: This should be assined {! this}
c. action
:The client-side controller action that handles the value change.
Syntax :
<aura:handler name="init" value="{!this}" action="{!c.functionname} " />
Syntax of controller :
(
{
methodname :function(component)
{
}
})
Q:: How to read the values of attributes with in the controller
component.get("v.attributename");
Q:: How to set the values of attributes with in the controller
component.set("v.attribute" ,value);
============================================================================================================
Example 1:
a. Create a component with three attributes aval,bval,cval
Calculate.cmp
<aura:component >
<aura:attribute name="aval" type="Integer" required="true" />
<aura:attribute name="bval" type="Integer" required="true"/>
<aura:attribute name="cval" type="Integer" />
<aura:handler name="init" value="{!this}" action="{!c.add}" />
<div>
<h2> AVal : {!v.aval}</h2>
<h2>BVal :{!v.bval}</h2>
<h2>CVal :{!v.cval}</h2>
</div>
</aura:component>
b. create style for the component :
.THIS {
padding-left :80px;
padding-top :80px;
color :green;
}
c. create a clientside controller by clicking controller button on right side menu wizard
calculate.js
({
add : function(component) {
var aval=component.get("v.aval");
var bval=component.get("v.bval");
var cval=aval+bval;
component.set("v.cval",cval);
}
})
d. crate new application capital.app
<aura:application >
<c:calculate aval="10" bval="10" />
</aura:application>
Examples 2 :
a. create a new custom component :
empcomp
<aura:component >
<aura:attribute name="empName" type="string" default="Enter Name" />
<aura:handler name="init" value="{!this}" action="{!c.show}" />
Employee Name :{! v.empName}
</aura:component>
b. createa client side Controller:
({
show : function(component) {
component.set(" v.empName "," Satish Myla ");
}
})
c create a Application :
<aura:application >
<c:empcomp> </c:custom1>
</aura:application>
Example 3:
a. create custom component : intrestcalcualte
<aura:component >
<aura:attribute name="empName" type="string" default="Enter Name" />
<aura:attribute name="amount" type="decimal" />
<aura:attribute name="rate" type="integer" />
<aura:attribute name="years" type="integer" />
<aura:attribute name="intrest" type="decimal" />
<aura:handler name="init" value="{!this}" action="{!c.calculate}" />
<div>
Employee Name :{! v.empName} <br/>
Amount : {!v.amount} <br/>
Rate : {!v.rate} <br/>
Years :{! v.years} <br/>
Intrest:{! v.intrest}
</aura:component>
b. create a css style for a component ;
.THIS {
padding-left :80px;
padding-top :80px;
color :green;
}
c. create a clinet side controller
({
calcualte : function(component) {
component.set("v.empName","satish myla");
var amount=component.get("v.amount");
var years=component.get("v.years");
var rate=component.get("v.rate");
var intrest=amount*years*rate/100;
component.set("v.intrest",intrest);
}
})
d. create an application
<aura:application >
<c:intrestcalcualte amount="10000" rate="10" years="2"></c:comp3>
</aura:application>
=============================================================================================================
How to refer to array of elements :
===========================================================================================================
<aura:iteration> :
1. This component is used to display collecton elements by iterating over every element
Attribues :items: Required. The collection of data to iterate over.
var : Required. The variable name to use for each item inside the iteration.
Example 1:
1. create custom component :
collection1:
<aura:component>
<aura:iteration items="1,2,3,4,5" var="item">
<h1>Items : {!item}</h1>
</aura:iteration>
</aura:component>
2. Create a applicaiton : capital6
<aura:application>
<c:collection1 />
</aura:application>
Example 2:
1. create custom component : collection2.cmp
<aura:component >
<aura:attribute name="names" type="string[]" default="['Ram','Ravi','Kiran']" />
<aura:iteration items="{!v.names}" var="s">
<h1> Employee Name :{!s} </h1>
</aura:iteration>
</aura:component>
2. Application :
<aura:application >
<c:collection2></c:collection2>
</aura:application>
Example 3:
1. create a custom component :
<aura:component >
<aura:attribute name="names" type="string[]" />
<aura:handler name="init" value="{!this}" action="{!c.callme}" />
<aura:iteration items="{!v.names}" var="s">
<h1> Employee Name :{!s} </h1>
</aura:iteration>
</aura:component>
2. create custom controller
({
callme : function(component) {
var names=['Ram','Kiran','Hari'];
component.set("v.names",names);
}
})
3. create new Application
<aura:application >
<c:collection3></c:collection3>
</aura:application>
==============================================================================================================
Example : Creating Form using UI components in Lightning
1. create the component to create UI comonents
<aura:component >
<ui:inputNumber label="Amount" placeholder="0" /><br/>
<ui:inputText label="Enter Name" placeholder="FirstName,Last" /><br/>
<ui:inputCurrency label="Salary " /> <br/>
<ui:inputDateTime label="Date" displayDatePicker="true"/>
<ui:button label="Submit" />
</aura:component>
2. create a application
<aura:application >
<c:uicomponent1 />
</aura:application>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q:: Setting and getting values of component using id in the controller method
component.find("idname").get("v.value");
component.find("idname").set("v.value",value);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Example 1:
1. create a component :uicomponent2
<aura:component >
<ui:inputText label="Enter Name" placeHolder="Employee Name" aura:id="name" />
<ui:inputText label="My Name " aura:id="myname" />
<ui:button label="submit" press="{!c.callme}" />
</aura:component>
2. create a controller :
({
callme : function(component) {
var name=component.find("name").get("v.value");
component.find("myname").set("v.value",name);
}
})
3. Create a application :
<aura:application >
<c:uicomponent2 />
</aura:application>
Example 2 :
<aura:component >
<ui:inputText label="Name" aura:id="name" placeholder="First, Last"/>
<ui:button aura:id="outputButton" label="Submit" press="{!c.getInput}"/>
<ui:outputText aura:id="nameOutput" value=""/>
</aura:component>
Controller :
({
getInput : function(cmp, event) {
var fullName = cmp.find("name").get("v.value");
var outName = cmp.find("nameOutput");
outName.set("v.value", fullName);
}
})
Application :
<aura:application >
<c:comp5></c:comp5>
</aura:application>
=============================================================================================
Example 9 :set the attribute values from the UI components based on the events on componets
<aura:component >
<aura:attribute name="first" type="String" default="John"/>
<aura:attribute name="last" type="String" default="Doe"/>
<ui:inputText label="First Name" value="{!v.first}" updateOn="keyup"/>
<ui:inputText label="Last Name" value="{!v.last}" updateOn="keyup"/>
<!-- Returns "John Doe" -->
<ui:outputText value="{!v.first +' '+ v.last}"/>
</aura:component>
Application :
<aura:application >
<c:comp6></c:comp6>
</aura:application>
==========================================================================================
Example 10:Creating a picklist component
<aura:component >
<ui:inputSelect>
<ui:inputSelectOption text="Red"/>
<ui:inputSelectOption text="Green" value="true"/>
<ui:inputSelectOption text="Blue"/>
</ui:inputSelect>
</aura:component>
Application :
<aura:application>
<c:compPick></c:compPick>
</aura:application>
============================================================================================
Example 12: If Else in the lightning
<aura:component >
<aura:attribute name="edit" type="Boolean" default="true"/>
<aura:if isTrue="{!v.edit}">
<ui:button label="Edit"/>
<aura:set attribute="else">
No button
</aura:set>
</aura:if>
</aura:component>
Application :
<aura:application>
<c:comp8></c:comp8>
</aura:application>
==========================================================================================
Reading the data from the Apex Class:
1. Every method of the apex which we want to invoke in the lightning should obey the following rules
a . Method should be annotated with @AuraEnabled
b. Method should be static method
c. Method should have returnType to pass the data
2. If you want to the apex class in the lightning component / application it should be define as a controller
3.When we want to invoke the reffer to the server-side controller method from the client side controller
method
Syntax :
component.get("c.methodName");
4. When want to the setCallback of to the controller
var mycall=component.get("c.methodName");
myCall.setcallback(this, function(response) {
logic
});
5.When the method gives the reponse check the status
var state=response.getStatus();
6.Every apex method invocation from the controller javascript is asynchronous so we need to
enqueu the job;
$A.enqueueAction(action);
Example
:
1. Create a apex class with aura enabled methods
Apex class : AuraExample1
public class AuraExample1 {
@AuraEnabled
public Static String getName(){
return 'Satish Myla';
}
}
2. create a custom Componet which invokes the apex class
<aura:component controller="AuraExample1">
<aura:attribute name="empName" type="string" />
<ui:button label="Get EmpData" press="{!c.show}"/>
<h1>Employee Name :{! v.empName} </h1>
</aura:component>
3. create a client side controller
({
show : function(component) {
var action=component.get("c.getName");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.empName", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
4. create a application
<aura:application >
<c:apexcall />
</aura:application>
===============================================================================================
Example 14: Reading a list account records from Sobject and display in Lightning
Apex class : AuraExample2:
public class AuraExample2 {
@AuraEnabled
public Static Account[] getAccounts(){
List<Account> accs=[select id,name from Account limit 4];
return accs;
}
}
Component : Custom5 :
<aura:component controller="AuraExample2">
<aura:attribute name="Accounts" type="Account[]" />
<ui:button label="Get Accounts" press="{!c.getAccs}"/>
<aura:iteration var="a" items="{!v.Accounts}">
<p>{!a.Name} : {!a.Id}</p>
</aura:iteration>
</aura:component>
Controller:
({
getAccs: function(cmp){
var action = cmp.get("c.getAccounts");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.Accounts", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Application :
<aura:application >
<c:custom5></c:custom5>
</aura:application>
==============================================================================================
Example 15 :Setting the body part of the component
-------------------------------------------------------------------
<aura:component>
<aura:set attribute="body">
<!--START BODY-->
<div>Body part</div>
<ui:button label="Push Me"/>
<!--END BODY-->
</aura:set>
</aura:component>
App6.app
<aura:application >
<c:bodyAttribute></c:bodyAttribute>
</aura:application>
-------------------------------------------------------------------------
Example 16: Component Facets
-------------------------------------------------------------------------
facetHeader.cmp
<aura:component>
<aura:attribute name="header" type="Aura.Component[]"/>
<div>
<span class="header">{!v.header}</span><br/>
<span class="body">{!v.body}</span>
</div>
</aura:component>
facetHeaders.cmp
<aura:component>
See how we set the header facet.<br/>
<c:facetHeader>
Nice body!
<aura:set attribute="header">
Hello Header!
</aura:set>
</c:facetHeader>
</aura:component>
Application
<aura:application >
<c:facetHeaders></c:facetHeaders>
</aura:application>
========================================================================================
Example 17 : Adding lightning application in vf page
<aura:application access="GLOBAL" extends="ltng:outApp">
<aura:dependency resource="ui:button"/>
</aura:application>
VF Page :
<apex:page>
<apex:includeLightning />
<div id="lightning" />
<script>
$Lightning.use("c:app15", function() {
$Lightning.createComponent("ui:button",{ label : "Press Me!" },
"lightning",function(cmp) {});
});
</script>
</apex:page>