Friday, 15 October 2021

securely share files,reports and dashboards in Salesforce

 sharing Salesforce Files :


1.File are just digital documents that can be uploaded to Salesforce.

2.Files can be shared with users or groups, and you can even create a public link that allows you to share them with people outside of your company.

3.Files can also be stored in private libraries or even marked as private when they are attached to a record.

4.Files such as images or PDFs can be previewed without having to be downloaded.

5.Replace old way of managing files in Salesforce classic.


Note : Salesforce Files is the way to organize your documents in Salesforce. 


Files in Salesforce Classic :


1.Classic Notes 

Classic notes, as they are now referred to, allowed users to write a brief text‑based note and attach it to a record, such as an opportunity or an account.

2.Attachements 

Users also had the option of attaching actual files, such as a Word or PDF document, to a Salesforce record.

3.Documents

users could upload actual documents to a document repository, but these files were separate from notes and attachments.


Ways to Share Files :


1.Chatter feed

you can post them to a Chatter feed.

2.Users and Groups

 You can also share them with specific users and groups

3.Public link

To collaborate with external users or customers, you can create publicly accessible links.

4.Attach to record

you can attach a file to a record.


Note :  All of these files can be managed From one central repository


Files Home :

Files Home is the place where you can easily manage all your Salesforce files.

 Files home allows you to search for files that you either own or can access.

 You can even preview files without having to download them first.

 If necessary, you can upload private files that will be marked as private.

 Once uploaded, you can share files with users, groups, or with a public link.

 

 Assignable File Permissions :

 

1.Viewer


The viewer permission indicates that the user can view, download, and share a file, along with being able to attach a file to a post.

  

2.Collaborator


A collaborator can also do these things, along with a few other things.


Viewer Vs Collaborator :


Viewer :

1.View or preview

2.Download

3.share

4.Attach file to post


Collaborator :

1.View or preview

2.Download

3.share

4.Attach file to post

5.Upload new version

6.Edit details

7.Change permission


Note :

A viewer can view or preview a file, download, share, or attach the file to a post.

A collaborator can do all of those same things, but they can also upload a new version, edit file details, and even change permissions for files that have already been shared.


A super important thing for you to realize is that if a user has been granted the Modify All Data system permission, they can access files they do not own, regardless of whatever permission has been assigned to them.

(or)

Users with " Modify All Data" permissions can access files they do not own.

Users with " vIew All Data" permission can view files they do not own.


Private Files :


Private indicates that the file has not been shared with anyone other than the owner.


The File Privacy on Records option lets you control the visibility of a file when it's attached to a record. 

If you don't see the File Privacy on Records option when you edit a file's details, ask your admin to add it. 

Only admins and file owners can change the value of File Privacy on Records.


Sharing Reports and Dashboards :


1.Viewer

Viewer access allows users to view reports or dashboards and see what level of access has been granted to that folder.

2.Editor

Editor access allows the users to also save, rename, or delete reports or dashboards in a folder.

3.Manager

And manager access grants the additional ability to share a folder, as well as change the folder's name, or even to delete that folder.


System Permissions :


By default, Salesforce users will have access to a My Personal Custom Reports folder and a My Personal Dashboards folder from where they create and customize personal reports and dashboards.


Summary :


Files can be uploaded and shared from :

1.Files Home

2.Chatter feeds

3.Object records

4.Public links


Uploading to record requires adding Files related list to objects page layout.


Files uploaded to home - private by default.

Beware modify/view All Data permissions.

Mark as private or move to private library to ensure privacy.


reports and dashboards :


Permissions for reports/dashboards controlled through folder access.

Set at the root level for nested folders.

Note : Even though you can have nested folders, access is set at the root folder level.


Each usr has access to :

-My Personal custom reports.

-My Personal dashboards


Note : Each internal user will have access to a my personal reports folder for custom reports and one for personal dashboards.


Team Sharing and Grant Access in Salesforce

 Account Team :


1.Account team is a group of users all working on the same account.

2.Account team cannot be the owner.

3.Account team will need object level read/write access.


Team Roles :


For Accounts, Opportunities and cases , record owners can use teams to allow other users access to their records.


Record owners can build a team for each record that they own.The record owner adds team members and specifies the

level of access each team member has to the record.


In account teams , team members also have access to any contacts,opportunities and cases associated with an account.


Case Team :


Case Team is a group of users all working on the same case.

Case record exists as a part of an account record.

Case Team cannot be the owner.

The goal of a Case Team is to resolve the case as soon as possible.

Very similar to Account Team, however the setup is quite different.


Sales Team :


1.A Sales Team is a group of users working on an opportunity or an account.

2.Sales Team and Account Team members often have access to the same records.

3.Sales Team cannot be the owner.

4.Unser Account Team roles is where you also access Sales Team roles.

Thursday, 14 October 2021

Salesforce Sharing Model

 Profiles and Permission sets are just a baseline for record access.



You can think of the model as an upside down triangle where the tools located at the top of the triangle provide 

the widest level of access to the greatest number of users, and tools that are located at the bottom can be used 

more precisely to grant certain kinds of access to the least number of users.


Starting at the top, there is territory hierarchy access, and this is part of a territory management feature that Salesforce provides.


Teams are groups of users that work together on objects like accounts, opportunities or cases.


Manual sharing allows users to intentionally grant record access to a user that would normally not have access.


Sharing rules, which can be used to extend access to users in public groups or roles.


Role hierarchy, which automatically grants access to certain users depending on where they fall on that hierarchy.


Org-wide defaults are used to restrict access.


Implicit sharing applies to records involved in parent-to-child relationships, and this can have big implications for your entire sharing model.

And sitting at the very bottom of all of this is that baseline access,and this involves a combination of a profile along with permission sets.


Implicit Sharing :


Happens when parent and children involved.

Overrides explicit sharing (Manual sharing & sharing rules).


Note :

Implicit sharing can occur when there are children records that are associated with a parent record.

For instance, accounts and contacts are designed with this kind of relationship. Contacts are considered children of a parent account, 

and what can seem reasonable is that users that could access a contact can also access the account. The very important thing to realize 

is that this type of relationship can override explicit sharing that is done with either manual sharing or sharing rules


View ALL or Modify All Permissions and View All Data or Modify All Data Permissions :


When granting access to an object, it is possible to use the View All or Modify All permissions. 

It is also possible to give you View all data or modify all data permissions to a particular profile. As you can probably guess, 

this will grant access to all records, and this is sometimes done for system administrators for good reasons, but realize 

that doing this will override whatever sharing model has been put in place, so it should be used with caution.


Access Grants :


Access Grants determine who sees what data in Salesforce.The process of determining this all starts with an object sharing table.


Object Sharing Table :


1.Object Sharing Tables Separate from the actual object table.

2.Object Sharing Tables Stores data about explicit and implicit grants.


Explicit Access Grant vs Implicit Access Grant :


Explicit :

1.Applies for territories and teams.

2.Happens when user creates record(owner).

3.When record is shared manually sharing/sharing rules.


Implicit :


1.Implicit sharing is built-in sharing that Salesforce offers.

2.Applies to Parent/child relationships.

3.can go both ways for parent and child.


Note : Access grants live in sharing objects.


Record access happens through access grants, and these grants reside in a sharing object or table, as you might think of it. 

Keep in mind that sharing objects are completely separate from the record object where the actual data being shared lived


Sharing Table Names :

Object sharing tables are created automatically and follow a very specific naming pattern.

For example, when the object record table is named Account, the sharing table will be named AccountShare, and the thing that ties these two tables together is the owner of the record.


Account --> AccountShare


And when dealing with a custom object, such as the one that is named MyCustomObject, the sharing table will be named MyCustomObject, followed by two underscores, and the word Share.


MyCustomObject --> MyCustomObject__Share


Record Access Calculation :

1.Only happens during a configuration change.

2.Improves record access performance.

3.Results in creation of access grants.


Salesforce uses Access Grants in order to identify how much access user have to object records. 

This comes into picture only when OWD for object is either PRIVATE or PUBLIC READ ONLY.

Access Grant also specify the sharing tool (like sharing rule, teams,roles etc) responsible for providing record access to user.


There are four types of access grants used by Salesforce:


Explicit grants can occur as a result of a few different things, but they always happen when a user creates a new record and thus becomes the owner. 

Implicit grants happen automatically whenever there's a parent-to-child relationship involved. 

Group membership grants occur whenever a user is a member of a group that has explicit access to a record. 

Inherited Grants are inherited when a user inherits access to a role, territory or group hierarchy.


Sharing Recalculation :


Sharing Recalculation happens when changes made to :


1.Group membership

2.Role hierarchies

3.Territory hierarchies


Sharing recalculation happens when changes are made to group membership or role hierarchies or territory hierarchies, 

and these changes could involve things like adding or removing members or changing where a member is placed in that hierarchy.


Sharing Recalculation can also be done manually.

The recalculation process can also happen when an admin manually kicks it off in setup.


Organization-wide Defaults :


1.Default level of access to user-owned records.

2.Used to initially lock down data for objects.

3.Set different levels for internal/external users.

4.Mixes with sharing tools to open up access.


Note :  org-wide defaults is the only way to limit record access.


The org-wide default can lock down access and then the other sharing tools can be used to open that access up to certain users or a group of users,

 and all of this is based on the concept of record ownership.

 

All records in Salesforce must be owned by an individual user or a group of users that are assigned to a queue.


OWD Default Levels :


1.Private


The most restrictive one is private, and this means that only the record owner and users that are above them in the role hierarchy can view or edit 

those records.


2.Public read-only


Public read-only allows all users to view records, but they can't edit them.


3.public read/write


public read/write is the least restrictive access, and this means that full access is allowed for all users.


4.public read/write/transfer (only for cases and Leads)


which is used only for case and lead records since these types of records can be transferred to another owner.


5.Controlled by parent


Controlled by parent applies to records that are part of a parent-to-child relationship, and this means that the child inherits the access of the parent.


6.Public Full Access (only for Campaign)


This one only applies to campaign records.


Implicit Sharing :


Implicit sharing is automatic and built into the platform and it takes precedent before any org-wide defaults are set. 

It all centers around the parent-to-child relationship, and it applies specifically to the account object when the account object is 

associated with a child object,such as contact.


Salesforce will automatically ensure that any users that can see that contact can also see the account that it is related to and they will in effect 

have read-only access to the account object as long as they are also able to see the contact.


And this level of access happens as a result of implicit sharing as it's built in automatically to Salesforce.


Record Access Logic :


How record access logic works in Salesforce?


It all begins with a Salesforce user, and every time that user attempts to access a record from a particular object and the org-wide default 

for that object is set as private or read-only, the system will look at the object's sharing table for all access grants. But that is not all. 

The system will also join the group membership table based on the ID of the user that's trying to access that object's record. 

And depending on what is found, the least restrictive access will be granted to that user, and this determines what kind of access they get.


Control by parent:


Control by parent means that users have the same access to the child object as they do to their parent, 

but it is important to understand that the control by parent setting is not the same thing as implicit sharing.


Change Org-wide Default (OWD) :


The original values would display until the operation completes because it's an asynchronous process that's happening in the background.


Notes :

1.Organization-wide settings are the only way to limit user record access.

2.Implicit sharing applies to parent-child relationships.

3.Settings checked every time user accesses record when set to private or read-only.

4.Private is most restrictive level of access.


Role Hierarchy :


1.Role hierarchies provide data access for a group of users. 

2.For the most part, it allows managers access to records that are owned by their employees. 

3.Essentially, record access is opened up vertically to users that are higher up in the hierarchy. 

4.By default, peers, or other members that are assigned to the role, will not have access to these records.


Note :

The role hierarchy sits right here in the middle. This means that baseline access, 

implicit sharing or org-wide defaults will override any access that is provided by the role hierarchy.


Remember, changes to a role hierarchy can result in a sharing recalculation, and depending on the size of the org, 

well this could have huge performance impacts.


Orgs that were created prior to the spring '21 release are limited to 500 roles, and orgs created after this time can create up to 5000 roles.


Implicit Sharing :


if a Salesforce user is able to access a contact, then they automatically have access to the parent account record, but that access is read-only.

objects are associated with separate sharing objects or tables, and each record in these sharing tables has a row cause. 


Sharing Row Cause :


1.Owner

Owner means the user accessing the record is the owner of that record.

2.Manual/Rule

Manual or rule indicates that the record was shared manually using the user interface or using an automated sharing rule.

3.Implicit Parent

Implicit parent means that if a user can access a contact, opportunity or case, then they automatically get read-only access to the parent account.

4.Implicit Child

An implicit child allows the account owner access to child records.


Implicit Sharing Types :


1.Parent 


1.Read-only access on parent account for user with access to the child record.

2.Does not apply when child set as "Controlled by Parent".


2.Child 


1.Access to child records for the owner of the parent account.

2.Does not apply when child set as "Controlled by Parent".


Notes :

The role hierarchy open up access to records vertically.

Implicit sharing can go both ways and is not same as "Controlled by parent" setting.


Sharing Rules :


1.OWD must be read-only or private.

2.Opens up object access for a group of users.

3.Specify the level of access in the rule.

4.sharing is based on :

   -> who owns the record

   -> values of certain fields


Note :

Sharing rules are created for objects, but you only do this if the org‑wide default for that object is set to private or read-only;

otherwise, there is no need to create a sharing rule since everyone has access to that object.


Public Group vs Queue :


Public Group :


1.Contains group of users.

2.Can include users in role or territory.

3.Used with sharing rules.


Queue :


1.Manage ownership of objects, such as leads, cases, and even custom objects.

2.The record is owned by the queue and not any of the users that are assigned to that queue.

3.Queues are not used in sharing rules.


owner-based sharing rules and criteria-basedsharing rule :


owner-based sharing rules starts with a Salesforce record that can be shared with a public group or a specific role, along with users assigned to roles above or below that role.

criteria-based role is the second type of sharing role that you can create. It works by looking at the value of one of our fields, and depending on what value is entered, sharing the object with a public group or role.


Note :

Territories can be included in a public group.


Public Groups :


When creating a public group, you will see a checkbox next to Grant access using hierarchies. 

Remember that from the role hierarchy. When this is checked, the sharing rule will be inherited by any members 

that also belong to a role higher in the role hierarchy. This setting is checked or enabled by default.

 

Manual Sharing :


First of all, if you are following along, you may need to enable manual user record sharing. It is not enabled by default in developer orgs.


In terms of who can grant access through manual sharing, that includes the record owner, 

obviously, but also any users that are above them in the role hierarchy, along with any user that has been granted full access to the object,

and finally, any administrators. 

Wednesday, 13 October 2021

Organization-wide Defaults (OWD)

 Organization-wide Defaults are used to lock down data records for specific objects.

Each object will be assigned a level and these can be different for an internal versus external users.

Access will then be opened up to other users or groups using a mixture of manual sharing. sharing roles, and the role hierarchy.


Access Levels :


1.Private 


Private is the most restrictive level of access and this means that only the record owner and any users above them in the role hierarchy 

can view, edit, or report on those records. In other words, only managers can see the records of their employees. 


2.Public read-only


Public read only indicates that all users can view and report on records, but only the owner and their managers can actually edit the record, 

and remember all this is still dependent on whether users have the appropriate object level permission.


3.Public read/write


Public read/write access means that all users can view, edit, and report on all records. 

So this is kind of the least restrictive level of access and this one should only be assigned after really careful consideration.


4.Public read/write/transfer


Public read/write/transfer is a special level that is only available to lead and case objects and since those are the only kinds of 

accounts that allow for a transfer to happen.



Grant Access Using Hierarchies


By default, the Grant Access Using Hierarchies option is enabled for all objects, and it can only be changed for custom objects.


This is checked for all objects by default, but important thing to remember, admins can uncheck this box for custom objects only.


Note :

org-wide defaults are the only way that you have to limit record access for users.


Access Grants :


Access grants start with the org-wide default level for each object.

And when they are set to private or read only, an access grant is assigned, and this determines how much access a user or group has to that object's records. 

And that leads us to what those access grant types can be.


Note : Access grants determines how records can be accessed.


1.Explicit grants


Explicit grants happen when a user becomes the owner of a record or a user 

shares a record using one of the sharing tools that I already mentioned.


 

2.Group Membership grants


Group membership grants occur when an explicit grant is directly assigned to a member of a group, queue, role, or a territory.


3.Inherited grants


Inherited grants happen when a user inherits access because they are part of some group or hierarchy. 


This comes into picture when user get access to records because of role hierarchy, territory hierarchy or inherit access through group hierarchy.


4.Implicit Grants


Think of this as Salesforce's built-in sharing. It just applies to objects that have a parent-to-child relationship. 


Sharing database Architecture :


Salesforce store access grants in three types of tables:

1.Object Record Tables

This table indicate which user, group or queue own each record.

2.Object Sharing Tables

This table store information like which record is shared with which user or group either by apex manage sharing rule 

or declarative sharing when object OWD is not PUBLIC READ/WRITE.

This table store data that supports explicit and implicit grants.

3.Group Maintenance Tables

This table store data that supports group membership grants and inherited grants. 


Role Hierarchy :


Represents group of managed users.

Managers have same access as employees.

Peers do not share access to records.


Note : Poorly designed role hierarchies can have big impact on org maintenance and performance.



Salesforce Permission Set Groups

 Permission Set Group - The Next Generation Permission Management.

The permission set group, are a bundle of permission sets.

You can group permission sets based on user roles using Permission Set Groups for easier user permission management.

Move the bulk of the permissions from the profiles into smaller chunks and break it into multiple permission sets. 

This way each permission set is granular and does not have overlapping functionality.

The Permission set group allows to combine multiple permission sets into a single permission set group for user assignment. 

Use a Permission set group to multiple permission sets together based on the job role. 

You can include a permission set in more than one permission set group. You can also remove individual permissions from a group with the muting feature.

Note : 

1.whenever possible permissions should be handled by permission sets and permission set groups and not profiles.

2.Permissions moving from profiles to permission sets or permission set groups.


Tuesday, 12 October 2021

Salesforce IP Ranges

 we can define two types of IP Ranges in salesforce.


1.Login IP Ranges

2.Trusted IP Ranges


Want to improve user security for your organization beyond usernames and passwords? 


Use login IP ranges and trusted IP ranges to control the IP address ranges from which your users can log in to Salesforce.


Login IP ranges control login access for a user profile. Users with profile login IPs can only log in from IP addresses within the range; 

otherwise, they’re denied access to Salesforce. Login IP ranges are typically used to restrict login IPs at a granular level.


Trusted IP ranges control login access for an organization. When users log in from trusted IPs, they aren’t challenged to verify their identity 

(such as by entering a code sent to their mobile phone). Unknown users logging in from non-trusted IPs are challenged to verify their identity, 

and if successful, allowed to access Salesforce. Trusted IP ranges are typically used to “allowlist” IPs at the organization level.


Trusted IP Ranges :

1.Trusted IP Ranges Set at org level.

2.Computer activation not required.

 User logging in within the Trusted IP range means that computer activation is not trusted.

 so effectively, one particular login restriction is removed.

 

 Note : Trusted IP ranges remove the computer activation requirement.


Login IP Ranges :


1.Login IP Ranges set at Profile or user level.

2. Prevents login outside range.


Login IP ranges prevents user login outside the range.


Note :

Even if user IP address is in the range of Trusted IP Ranges but not in Login IP Ranges,

user still will not able to login and get the same error message.


Login Hours :


Login Hours settings will control what hours the user can log in during.


1.The first thing that is checked on any login is your profile login hours. 

If you have login hours on your profile, and you are outside login hours, 

the login process stops and you are denied access. No further checks are done. 

If you don't have login hours set, or if you are within login hours, you move to step 2.


2.Next we look to see if your profile has an IP restriction set on it. If you do and you are not within the login IP range, 

you are denied access. No further checks are done. No verification email. Nothing. Your access is blocked absolutely. 

If you are within your profile IP range, you are granted access.


3.If there is no profile IP range, then we will look for a browser cookie set that identifies that this user has accessed this org previously, 

or if they are within the organization-wide IP restrictions (Setup>Security Controls>Network Access). 

If you are your browser does not have the cookie, or is you are not within the org-wide range, your access is blocked but there are two ways to still gain access.

Saturday, 9 October 2021

Salesforce Functions

 what is a function?

A single purpose,on demand,short-lived microservice without complex infrastructure.


1.Elastic Scale

Extend Salesforce data with elastic compute that scales on demand.

2.Stay on platform

Build with pre-configured secure access to C360 data.

3.Expand Talent Pool

Extend Salesforce data with elastic Build inclusive with all your developer talent 

using open languages and tools that scale on demand.


Anatomy of a Function :


Each javascript Function exports an async function this is where all of the works is done.


module exports = async function(event,context,logger){

  // Do something

}


Each function has access to the event,context & logger objects.


The event contains the payload that was passed into the function.

The Context allows access to an authenticated Org and the Salesforce SDK.

The logger helps you log right from your function.


Invoking Function(Sync)


Functions can be invoked directly from Apex.

you can use the functions.Function class to get a function reference 

and invoke it by passing it a JSON payload.

You can then get the response from the functions.FunctionInvocation object.


You can invoke them synchronously and asynchronously


public with sharing class GenericFunctionInvoker{

 public static String invoke(String functionName,String payload){

  functions.Function function=functions.Function.get(functionName);

  functions.FunctionInvocation invocation=function.invoke(payload);

  String response=invocation.getResponse();

  return response;

  

 }

}


Invoking Functions (Async) :


An async invocation receives a callback, which inherits from functions.FunctionCallback.


public with sharing class GenericFunctionInvoker{

 public static String invoke(String functionName,String payload){

  functions.Function function=functions.Function.get(functionName);

  functions.FunctionInvocation invocation=function.invoke(payload, new MyCallback());

  

 }

 public class MyCallback implements function.FunctionCallback{

 

 public void handleResponse(functions.FunctionInvocation invocation){

   String response=invocation.getResponse();

 }

 

 }

}


Enable Functions in scratch org :


Edit the config/project-scratch-def.json file to enable the "Functions" feature and save. We will use this configuration to create a new Scratch Org:


{

  "orgName": "acme company",

  "edition": "Developer",

  "features": ["Functions"]

}