Explain few considerations for @Future annotation in Apex.
Ans :
- Method
must be static
- Cannot
return anything ( Only Void )
- To
test @future methods, you should use startTest and stopTest to make it
synchromouse inside Test class.
- Parameter
to @future method can only be primitive or collection of primitive data
type.
- Cannot
be used inside VF in Constructor, Set or Get methods.
- @future
method cannot call other @future method.
Explain Considerations
for Static keyword in Apex.
Ans :
- Apex
classes cannot be static.
- Static
allowed only in outer class.
- Static
variables not transferred as a part of View State.
- Static
variables and static block runs in order in which they are written in
class.
- Static
variables are static only in scope of request.
What is difference
between public and global class in Apex ?
Ans :
Ans :
- Public
class can be accessed within application or namespace. This is not exactly
like public modifier in Java.
- Global
class visible everywhere , any application or namespace. WebService must
be declared as Global and which can be accessed inside Javascript also. It
is like public modifier in Java.
How can you call Apex
class using Javascript ? Give Example.
Ans :
Ans :
|
1
|
global class myClass {
|
|
|
2
|
webService static Id makeContact (String lastName, Account a)
{
|
|
|
3
|
Contact
c = new Contact(LastName =
lastName, AccountId = a.Id);
|
|
|
4
|
return c.id;
|
|
|
5
|
}
|
|
|
6
|
}
|
|
we can execute above method from javascript like
:
|
1
|
var
account = sforce.sObject("Account");
|
|
|
2
|
var id
= sforce.apex.execute("myClass“ , "makeContact",
|
|
|
3
|
{lastName:"Smith",
a:account});
|
To call a webService method with no parameters,
use {} as the third parameter forsforce.apex.execute .
Also, you can use the following line to display
a popup window with debugging information:
sforce.debug.trace=true;
sforce.debug.trace=true;
What are few
Considerations about Trigger ?
Ans :
Ans :
- upsert triggers
fire both before and after insert or before and after update triggers as appropriate.
- merge triggers
fire both before and after delete triggers for the losing records and
before update triggers for the winning record only.
- Triggers
that execute after a record has been undeleted only work with specific objects.
- Field
history is not recorded until the end of a trigger. If you query field
history in a trigger, you will not see any history for the current
transaction.
- You
can only use the webService keyword in a trigger when it is in a method
defined as asynchronous; that is, when the method is defined with
the @future keyword.
- A
trigger invoked by an insert, delete, or update of a recurring event or recurring taskresults
in a runtime error when the trigger is called in bulk from the Force.com
API.
- Merge trigger
doesn’t fire there own trigger instead they fire delete and update of
loosing and winning records respectively.
Which SOQL statement can
be used to get all records even from recycle bin or Achieved Activities?
Ans : We will need “ALL Rows” clause of SOQL.
Sample :
Ans : We will need “ALL Rows” clause of SOQL.
Sample :
|
1
|
SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS
|
How can you lock
record using SOQL so that it cannot be modified by other user.
Ans : we will need “FOR UPDATE” clause of SOQL.
Sample :
Sample :
|
1
|
Account
[] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];
|