Showing posts with label Answers. Show all posts
Showing posts with label Answers. Show all posts

Friday, March 27, 2020

2.Key Salesforce Interview Questions With Answers


Here is the order of execution in salesforce
  1. original record is loaded from the database.
  2. System Validation Rules.
  3. Executes flows  
  4. all before triggers.
  5. Custom Validation rules.
  6. Executes duplicate rules.
  7. Saves the record to the database, but doesn’t commit yet.
  8. all after triggers.
  9. assignment rules.
  10. auto-response rules.
  11. workflow rules.
  12. If there are workflow field updates, updates the record again.
  13. fires before and after triggers one more time. Custom validation rules, duplicate ru
  14. les, and escalation rules are not run again.
  15. Executes processes and flows launched via processes and flow trigger workflow actions.
  16. escalation rules.
  17.  entitlement rules.
  18. If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
  19. If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure.
  20. Criteria Based Sharing evaluation.
  21. Commits all DML operations to the database.
  22. post-commit logic, such as sending email.

You can put 20 components on a dashboard which can come from as few as one or as many as twenty reports.

Picklist Values SHould be able to Edit By Few Users Only
1.By Record types
2.By Permission Sets
3.Validation Rules
4.BY Restricted Picklist Values

It consist of child component and a button with onclick handler which will call the method defined in child component. The onclick handler will call the child component method by using querySelector. This file defines where you can use the component in Salesforce

You can restrict users to show required picklist values by creating diferent record types and pagelayouts. Also, you can write validation rule to restrict the values. Good Luck.
--
Select Restrict picklist to the values defined in the value set.
===
AND (
    $User.Username != $Setup.Restricting_case_type__c.Users__c,
    RecordType.Name = "DLVR Cases",
    OR (
        ISPICKVAL(Case_Issue__c, "Compliance"),
        ISPICKVAL(Case_Sub_Issue__c, "Abuse Report")
    )
)===




 best practices to write a bulkified trigger.

  1. Never ever write a SOQL query inside any “for” loop for whatsoever reason. If you do that, your trigger is guaranteed to hit the governor limits.
  2. If you need to fetch large amount of data from an object (More than 50,000 records), then go for batch apex to pull that data, else you will again bump into another governor limit that wouldn’t allow you to fetch more than 50,000 records.
  3. Never ever perform a DML operation inside a “for” loop.
  4. Do not fetch unnecessary data. Only fetch those fields and objects in your SOQL that you really require.


Deactivate User:
Deactivating a user in Salesforce means that user will not be deleted from the system but will no longer be able to log in to Salesforce and their records can be transferred to another user. They cannot be part of workflows or part of any automated processes.
Deactivating a user will be available user licenses available for use in your organization.
Deactivated users lose access to any records that were manually shared with them, or records that were shared with them as team members. Users higher in the role hierarchy relative to the deactivated users also lose access to those records. However, you can still transfer their data to other users and view their names on the Users page.
Freeze User:
Freezing a user in Salesforce means that only stops the user from being able to login.
In some cases, you can’t immediately deactivate a user (such as when a user is selected in a custom hierarchy field or a user that’s assigned as the sole recipient of a workflow email alert). To prevent users from logging into your organization while you perform the steps to deactivate them, you can freeze user accounts.
Freezing user accounts doesn’t make their user licenses available for use in your organization.
Process builder not supporting “Outbound Messaging” with in out of box functionality, but have workaround to archive that functionality instead of going separate workflow rule send outbound message. You can archive using Apex Code. 
... Note : You can archive this functionality using Workflow Rule.

Lightning Component Framework — Framework that allows you to build reusable components, customize the Salesforce1 Mobile App, and build standalone apps.
Lightning App Builder — UI tools that let you build apps lightning fast, using components provided by Salesforce and platform developers.
Lightning Connect — An integration tool that makes it easier for your Force.com app to consume data from any external source that conforms to the OData spec.
Lightning Process Builder — A tool for creating automated business processes.
Lightning Schema Builder — A tool for viewing and creating objects, fields, and relationships.

Where can an app builder change the layout of a lightning page?
  • Create a record page for Lightning Experience in one of these ways. From the Setup menu on a record page, select Edit Page. ...
  • In the Lightning App Builder, add, edit, or remove components to change the page's layout. ...
  • In the page properties, give your customized page a unique, descriptive label. ...
  • Save your page.

Calling Web Services from a Trigger in Salesforce
  1. Step 1: Create a object RndCenter.
  2. Step 2: Consume WebServiceweb service information. ...
  3. Step 3: Create Triggertrigger rnd1 on RndCenter__c (after insert) ...
  4. step 4 :Create a class which call webservice. public class TempConvertWebService.


Transaction Control

All requests are delimited by the trigger, class method, Web Service, Visualforce page or anonymous block that executes the Apex code. If the entire request completes successfully, all changes are committed to the database. For example, suppose a Visualforce page called an Apex controller, which in turn called an additional Apex class. Only when all the Apex code has finished running and the Visualforce page has finished running, are the changes committed to the database. If the request does not complete successfully, all database changes are rolled back.
Sometimes during the processing of records, your business rules require that partial work (already executed DML statements) be “rolled back” so that the processing can continue in another direction. Apex gives you the ability to generate a savepoint, that is, a point in the request that specifies the state of the database at that time. Any DML statement that occurs after the savepoint can be discarded, and the database can be restored to the same condition it was in at the time you generated the savepoint.
The following limitations apply to generating savepoint variables and rolling back the database:
  • If you set more than one savepoint, then roll back to a savepoint that is not the last savepoint you generated, the later savepoint variables become invalid. For example, if you generated savepoint SP1 first, savepoint SP2 after that, and then you rolled back to SP1, the variable SP2 would no longer be valid. You will receive a runtime error if you try to use it.
  • References to savepoints cannot cross trigger invocations because each trigger invocation is a new trigger context. If you declare a savepoint as a static variable then try to use it across trigger contexts, you will receive a run-time error.
  • Each savepoint you set counts against the governor limit for DML statements.
  • Static variables are not reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.
  • Each rollback counts against the governor limit for DML statements. You will receive a runtime error if you try to rollback the database additional times.
  • The ID on an sObject inserted after setting a savepoint is not cleared after a rollback. Create an sObject to insert after a rollback. Attempting to insert the sObject using the variable created before the rollback fails because the sObject variable has an ID. Updating or upserting the sObject using the same variable also fails because the sObject is not in the database and, thus, cannot be updated.


The Best Ways to Retrieve Names of All Objects Using Apex

The Best Ways to retrieve a list of all Objects using Apex, you can use Schema.getGlobalDescribe() method.


Its simple use below code:

for( Schema.SObjectType o: Schema.getGlobalDescribe().values()){
    System.debug(o.getDescribe().getName());
}
Schema.getGlobalDescribe() :







Difference between View All and Modify All in Object Settings in profiles/permission sets

I wanted to double check and make sure I understand this correctly. This is something simple, but from everywhere I look online I can only find answers to specific use cases. Maybe that's how easy this question is. But can someone correct me if I am wrong?
In permission sets/profiles, when going through Object Settings, when setting the editability level of an object - the difference between view all and modify all is
1. View all gives the user access to view all records in that object, but you can adjust their edit and create rightsThey can't have delete rights because then that would mean....
2. They can modify all. Which means the user can view all and edit, create, delete records of that object
Best Answer chosen by Kruse Collins
You are correct in that the View All records they will have the ability to view every record regardless of sharing rules. You can adjust all the other permission, but if you add the delete permission they will also need the Edit permission. They will only be able to delete records that they can edit through sharing rules.

The Modify All means they can view, edit and delete all records regardless of sharing. You can still leave off the Create permission.




How to send email on birthday ?

My org has 10000 employees and I want to send email on their birthday. How to automate this process?
  • May 7, 2016
  • Like
  • 0
Best Answer chosen by THUNDER CLOUD
Hi,

You can achieve the above scenario by using Batch Apex and Schedule Apex. Please check the below sample code.

Batch Class

01global class BatchWishes implements Database.Batchable<Employee__c> {
02     global Iterable<employee__c> start(Database.BatchableContext bc){
03     list<employee__c> sq=[select name,empname__c ,Email_Id__c from employee__c where Date_of_Birth__c=today];
04    return sq;
05    }
06   global  void execute(Database.BatchableContext bc, List<employee__c> lst)
07      {
08list<Messaging.SingleEmailMessage> mail = new list<Messaging.SingleEmailMessage>();
09
10        for(employee__c e: lst)
11        {
12         Messaging.SingleEmailMessage maileach = new Messaging.SingleEmailMessage();
13         list<string> toadd=new list<string>();
14         toadd.add(e.Email_Id__c );
15          maileach.settoaddresses(toadd);
16          maileach.setsubject('birthday wishes');
17          maileach.setplaintextbody('happy birthday '+e.empname__c);
18          mail.add(maileach);
19        }
20       
21    Messaging.SendEmailResult[]  result =Messaging.sendEmail( mail);
22      
23    }
24   global  void finish(Database.BatchableContext sc)
25    
26    {
27      system.debug(sc);
28     
29    }
30}

Schedule class

1global class BirthdayNameOptions implements Schedulable{
2
3global   void execute(SchedulableContext dc){
4//batch class name  
5 BatchWishes bth=new BatchWishes ();
6    Database.executeBatch(bth,20);
7    }
8}

You can schedule a batch which runs at 12 am every day.Please follow the below steps for Schedule a batch class.

Go to Setup--->Develop--->Apex classes--->Schedule Apex

Here you can set the time.Please check the below screenshot.

User-added image

Process Builder supports three types of processes for your automation needs. The type determines what triggers the process.
  • A record change process starts when a record is created or updated.
  • An event process starts when a platform event message is received.
  • An invocable process starts when something else, like another process, invokes it.
Each process consists of:
  • Criteria that determine when to execute an action group.
  • Action groups, which consist of immediate or scheduled actions. Only record change processes support scheduled actions.

Process Builder vs. Workflow

Use the more powerful and flexible Process Builder to perform the same actions as Workflow. With Process Builder, you can:
  • Create a record of any object type
  • Update any related record—not just the record or its parent
  • Use a quick action to create a record, update a record, or log a call
  • Invoke a process from another process
  • Launch a flow—you can’t schedule this action with workflow
  • Send an email
  • Send a custom notification
  • Post to Chatter
  • Submit a record for approval

Delegated Approver cannot see anything in the 'Items to Approve' list


Delegated Approver. Your alternate approver. If populated, this user receives the same approval requests as you do. Delegated approvers can't reassign approval requests; they can only approve or reject approval requests.




What permissions do I need to import records?

You need different permissions to import records with Data Loader and Data Import Wizard.

Data Loader

Importing records with Data Loader requires these permissions.
  • “Read,” “Create,” “Edit,” and “Delete” on the objects
  • “API Enabled”
  • “Bulk API Hard Delete” (only if you configure Data Loader to use Bulk API to hard-delete records)


Data Import Wizard

IMPORT OPTIONUSER PERMISSIONS NEEDED
To import accounts and contacts that you own via the Data Import Wizard:
Import Personal Contacts
To import accounts and contacts owned by others via the Data Import Wizard:
Modify All Data

26. How to get current logged in users id in apex ?
Ans: Use Userinfo.getuserid() to get the current logged in user's id in apex ?

Userinfo.getuserid()

27. How to convert a csv file  browsed in visualforce page into a string.
Ans: use csvfilecontents.tostring(). method to convert blob to string
csvfilecontents.tostring()

4.How can you use custom label; in visualforc page?
Ans: Use this syntex for accessing custom albel in visualforce page - {!$Label.Samplelabel}
{!Label.Samplelabel}
accessing static resource {!$Resource.Testresourcename}
{!$Resource.Testresourcename}


https://i0.wp.com/alienbrainz.com/wp-content/uploads/2018/12/complex-comparision.jpg?fit=1553%2C2113&ssl=1





Custom Label: Automatic information Presenting in application in native language.
Custom metadata: Customizable, deployable, packageable and upgradeable application data
Custom settings: Custom set of data like Custom objects.





List<Map<string, Account>> m1=new List<Map<string, Account>>(); m1= [Select id,name From Account WHere Name='gagan'] CO Vehicle Picklist 500 Users Certain SEt of Users 200 Roles 500 Prfiles 250 Users- add records- Need to CHange the Record with Pick list values Changes Vehicle Record Type Picklis values+ REcords are already Existed Picklist already Polulated Pagelyaouts- Different Profiles Permission Sets - Vehicle- Picklist values Fields- Modify all Data - --- 10 Picklist Values Existed 250 Users 5 Picklist Values A1---------A10 A1.......A5 -- Parent Child




ECS Contact Form

Name

Email *

Message *