Documente Academic
Documente Profesional
Documente Cultură
Q) How to restrict the user to see any record, let’s say opportunity?
Ans : set up opportunity sharing to be private. If both users are admins or have view all records on opportunity,
then that overrides private sharing.
Q) Where is the option of the report for the “Custom Object with related object” and what are the condition to
generate related reports?
If the parent object is the standard object provided by the salesforce like “Account”, “Contact” then the report will
be in there section with related custom object.
If both objects are the custom then the report will be in “Other Reports” Sections.
Following are the conditions to get the report of related objects:
Q) 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.
Q) 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?
Lets 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”.
Q) What happen if child have two master records and one is deleted?
Ans :Child record will be deleted.
Q) What is Scheduler class in Apex and explain how to use Crone statement to Schedule Apex class?
Ans:
The Apex class which is programed to run at pre defined interval.
Class must implement schedulable interface and it contains method named execute().
There are two ways to invoke schedular :
Using UI
Using System.schedule
The class which implements interface schedulable get the button texted with “Schedule”, when user clicks on
that button, new interface opens to schedule the classes which implements that interface.
To see what happened to scheduled job, go to “Monitoring | Scheduled jobs ”
Example of scheduling :
scheduledMerge m = new scheduledMerge();
String sch = '20 30 8 10 2 ?';
system.schedule('Merge Job', sch, m);
To see how to make crone job string – Refer this Online Crone Expression Generator tool .
Note : Salesforce only accepts integer in Seconds and Minutes. So, lets say if you want to run Apex job on every 10
minutes, crone statement will be ‘0 0/10 * 1/1 * ? *’ and salesforce will throw an error saying
“System.StringException: Seconds and minutes must be specified as integers“. That mean like Time based
Workflow, minimum interval to schedule job is 1 hour.
8.What are the problems you have encountered when calling batch apex from the trigger?
Ans: At a time only 5 apex batch jobs can be processed. Flex Queue does allow more than 5 concurrent
batch jobs but it simply lines up the remaining jobs and keep their status as "Holding". So, apparently
user feels that more than 5 jobs have been submitted but they all go in the "Holding" status.
Flex queue itself has a limit of holding up to 100 apex batch jobs only. Therefore, in a live org with
thousands of users working simultaneously, lining up apex batch jobs from a trigger will create issues. If
the apex flex queue reaches 100 jobs and at the same time a user tries to update something that is
further triggering an apex batch then s(he) will see the following error on screen:
"System.AsyncException: You've exceeded the limit of 100 jobs in the flex queue for org X. Wait for
some of your batch jobs to finish before adding more. To monitor and reorder jobs, use the Apex Flex
Queue page in Setup".
Q) How to restrict any Trigger to fire only once OR how we can avoid repeated or multiple execution of Trigger?
Ans:
Triggers can fire twice, once before workflows and once after workflows, this is documented at
http://www.salesforce.com/us/developer/docs/apexcode/ Content/ apex_triggers_order_of_execution.htm:
“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:
Add a static Boolean variable to a class and check its value within the affected triggers.
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;
}
}
}
}
Q) 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?
Ans : 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.
1. How would you invoke the apex class through the process Builder?
In Process builder select immediate action
Select Action type as APEX and Apex Class
Note: Apex class method should me @InvokableMethod to call in Process builder.
https://blog.webnersolutions.com/salesforce-call-apex-class-from-process-builder
2. How you will pass parameters (Ex: id of record) for an apex class through process builder?
Apex variable selection ->You can select formula, Global constant, reference,
and id
https://www.tutorialkart.com/apex_soql/apex-access-modifiers-with-sharing-without-sharing/
With Sharing:
If you declare a class as a with sharing, sharing rules given to the current user will be taken to the consideration
and the user can access or perform the operations based on the permissions given to him on object and fields
(Field level security and sharing rules)
Without Sharing:
If you declare a class as a without sharing, then this Apex class runs in system mode which means Apex code has
access to all the objects and field irrespective of current users sharing rules, field level security and object
permissions.
If the class is not declared as without sharing or with sharing then the class is by default taken as
with sharing.
Both inner and outer class can be declared as with sharing.
If the inner class declared as with sharing and top-level class is declared as without sharing, then
by default entire context will run with sharing context.
If a class in not declared as with/without sharing and if this class is called by another class in
which sharing rules is enforced then both the classes run with sharing.
Outer class is declared as with sharing and inner class is declared as without sharing, then the
inner class runs in without sharing context.
2. Is it possible to deploy a trigger without it’s test class if org has code coverage of >75%, if not then what
is the minimum code coverage to deploy?
At least 75% of your Apex code must be covered by unit tests, and all of those tests must complete
successfully. Note the following:
When deploying to a production organization, every unit test in your organization namespace is executed.
Calls to System.debug are not counted as part of Apex code coverage.
Test methods and test classes are not counted as part of Apex code coverage.
While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of
code that is covered. Instead, you should make sure that every use case of your application is covered,
including positive and negative cases, as well as bulk and single records. This should lead to 75% or more
of your code being covered by unit tests.
Every trigger must have some test coverage.
All classes and triggers must compile successfully.
Global Keyword :-
This means the method or variable can be used by any Apex code that has access to the class, not just the Apex
code in the same application. This access modifier should be used for any method that needs to be referenced
outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as
global, you must also declare the class that contains it as global.
Ex: trinner.new.addError(‘Error’);
Contact.LastName.addError(‘Error’);
5. With Apex triggers how would they usually execute it as? Will they take users sharing rules into
consideration? Do they run Apex triggers in user context?
System mode -
System mode is nothing but running apex code by ignoring user's permissions. For example, logged in user does
not have create permission but he/she is able to create a record.
In system mode, Apex code has access to all objects and fields— object permissions, field-level security, sharing
rules aren't applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or
objects for a user.
In Salesforce, all apex code run in system mode. It ignores user's permissions. Only exception is anonymous blocks
like developer console and standard controllers. Even runAs() method doesn't enforce user permissions or field-
level permissions, it only enforces record sharing.
User mode -
User mode is nothing but running apex code by respecting user's permissions and sharing of records. For example,
logged in user does not have create permission and so he/she is not able to create a record.
In Salesforce, only standard controllers and anonymous blocks like developer console run in user mode.
6. From Salesforce standpoint, is it best to use out of box /write Apex code, what would you do when you
are given a requirement? Walk me through your thought process?
7. In a project, for custom functionality you were required to add functionality to an object, especially
write Apex trigger code and let’s say you have Trigger on custom object A, what would you do in that scenario?
8. If you look at custom object and there are already 5 triggers …would you write new trigger or would
you change the existing trigger?
All the triggers will run, but the order of execution is not predictable also we
can't prioritize one.
The order of execution isn’t guaranteed when having multiple triggers for the
same object due to the same event. For example, if you have two before insert
triggers for Case, and a new Case record is inserted that fires the two
triggers, the order in which these triggers fire isn’t guaranteed.
Ref: https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
If our suggestion seems relevant then please mark the most appropriate
answer as "Best Answer" right under the comment. This will help other
community members if they would have a similar issue in the future, also help
us to keep this community clean
The after undelete trigger event only works with recovered records—that is, records that were deleted and then
recovered from the Recycle Bin through the undelete DML statement. ... The after undelete trigger events only run
on top-level objects.
For example, if you delete an Account, an Opportunity may also be deleted.