Wednesday, 16 August 2017

Identify Current User Access To Record Using UserRecordAccess Object

Arpit Sharma
Salesforce provide UserRecordAccess object to identify access of user on set of records. We can query on this object based on user ID.

Key Points of UserRecordAccess
    1. This object is read only.
    2. It is available in API Version 24.0 and later.

Fields of UserRecordAccess 
    • RecordId - Id of record in which we need to check access, It is available in SELECT clause and WHERE clause. 
    • UserId - It is available in WHERE clause.
    • User Record Access Id - It is available in WHERE clause.
    • Maximum Access Level - It is used to identify maximum access of record having user(Picklist type). Value available in picklist.
        • None
        • Read
        • Edit
        • Delete
        • Transfer
        • All
    • HasTransferAccess(Boolean Type)
    • HasEditAccess(Boolean Type)
    • HasDeleteAccess(Boolean Type)
    • HasAllAccess(Boolean Type)

Sample Query
SELECT RecordId, HasEditAccess,HasReadAccess, HasTransferAccess, MaxAccessLevel,HasDeleteAccess
     ,HasAllAccess FROM UserRecordAccess
     WHERE UserId = UserInfo.getUserId()
     AND RecordId = :recordId     

References
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_userrecordaccess.htm
https://help.salesforce.com/articleView?id=000181207&type=1



  

Friday, 11 August 2017

Reports In Salesforce

Arpit Sharma
Why Report


Report is usually used to represent data in presentable form, Creating a report manually required lot of effort which included many question in mind i.e which type of data you required, what is the best way to represent data in report.

If you need data based on some criteria then there may be chances some unwanted data visible in report or some important data is not visible because of some human error. Report generated become more complicated when you work on large data. This is point where you need some automatic process to generate report for you business.

We will discuss here, about reports in Salesforce

Reports in Salesforce

Various tools are available in market to generate reports but if you are working in Salesforce then either you need to write custom code for represent that data or Salesforce itself provide most advance way to generate report by using just some point and click that does not require knowledge of code and reduce efforts and time

What Salesforce provide 
  1. We can set schedule time of report generation.
  2. Salesforce display data to user in report according to security model means user can't see data if user does not have permission of that data.
  3. In salesforce we can generate four type of reports
    • Tabular Reports
    • Summary Reports
    • Matrix Reports
    • Joined Reports 
Guys all above is basic idea about what is report, how it is useful for us and what Salesforce provide to us.

We will discuss above report types in details in upcoming tutorials

Feel free to comment if you have any question and suggestions in this tutorial.






Friday, 14 April 2017

apex:slds - Include lightning design system by using apex tag

Arpit Sharma


To use lightning design system we don't need to upload library  to static resource and reference them in visual force page. We can include them by using apex tag i.e <apex:slds/>. here is example of include of slds in visual force page.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<apex:page standardStylesheets="false" sidebar="false" showHeader="false">
  <apex:slds/>
  <apex:form>
      <!-- Without lightning designing CSS-->    
      <div >
          <label for="inputLabel">Input Label</label>
          <div>
             <input type="text" id="inputLabel"  placeholder="Without lightning designing CSS"/>  
          </div>
      </div>
      <!-- With lightning designing CSS-->
      <div class="slds-form-element">
          <label class="slds-form-element__label" for="inputLabel">Input Label</label>
          <div class="slds-form-element__control">
             <input type="text" id="inputLabel" class="slds-input" placeholder="With lightning designing CSS"/>  
          </div>
      </div>    
  </apex:form>
</apex:page>



Thursday, 13 April 2017

How to get object name from ID of record

Arpit Sharma




In Salesforce some time we have requirement to retrieve object name from record ID. So We can done this by two approach.

First approach
  • Get SObject type from record ID by using getSObjectType() method.
  • Convert Sobject type into string value.


1
2
3
4
Contact contactRecord = new Contact(FirstName = 'Test', LastName = 'Contact');
insert contactRecord;
// contactRecord.Id.getSObjectType() return Sobject Type of record then we convert them into String
String objectName = String.valueOf(contactRecord.Id.getSObjectType());

Second approach

  • Get Sobject type from record id by using getSObjectType() method.
  • Describe Sobject type by using getDescribe() method.
  • Then get name of object from object describe by using getName() method .


1
2
3
4
5
6
7
8
Contact contactRecord = new Contact(FirstName = 'Test', LastName = 'Contact');
insert contactRecord;
/*
   - first we get Sobject type by using statement contactRecord.Id.getSObjectType()
   - we describe Sobject type by using getDescribe() method.
   - then from object describe by using getName() we can get name of that object 
*/
String objectName = contactRecord.Id.getSObjectType().getDescribe().getName();