Posts

Share the file to external User

 Requirement:  Once the file is uploaded by the internal user then it will be shared the external user (Portal User) Solution Write a trigger on the contentDocumentLink object once the file uploaded share the file to the external user public without sharing class ContentDocumentLinkTriggerHandler {         public static final String ALL_USERS_SHARING = 'AllUsers'; public void runTrigger(){ // Method will be called to handle After Insert ContentDocumentLink if(Trigger.isAfter && Trigger.isInsert) { onAfterInsert((list<ContentDocumentLink>)trigger.new,(map<id,ContentDocumentLink>) trigger.newMap); } // Method will be called to handle After Update ContentDocumentLink if(Trigger.isAfter && Trigger.isUpdate) { onAfterUpdate((list<ContentDocumentLink>)trigger.new,(map<id,ContentDocumentLink>) trigger.newMap); } // Method will be called to handle After Update ContentDocumentLink if(Trigger.isAfter &am

Get the record Count of all countable Sobjects in Salesforce

Image
  Salesforce: Get the record count of all objects Use case: A client wants to access the data volume for data migration and needs to get record counts from all countable objects in Salesforce Solution:  1) log in to Workbench 2) Go to Utilities > Rest Explorer 3) Do a GET call on this URI: /services/data/v56.0/limits/recordCount ( change 56.0 with the latest API version) 4) Check the result. Copy the JSON and convert it to CSV Note: 1) The Rest call result does not include uncountable objects and record count for deleted records in the recycle bin 2) Ensure your user has "View Setup and Configuration” permission

Show Hyperlink against the Record in Datatable in LWC

Image
  Requirements : Show the case records in the data table. when click on case number it will redirect to the detail page Apex Class: showCaseRecordsinDatatable public with sharing class showCaseRecordsinDatatable {        @AuraEnabled     public static list<case> fetchCases(){         try {             return [Select Id, subject,CaseNumber, Description, AccountID, Account.Name,ContactID, contact.Name,Status, priority from case];                    } catch (Exception e) {             throw new AuraHandledException(e.getMessage());         }     } } --------Create LWC------- <template>     <lightning-card  variant="Narrow"  title="Case List" icon-name="standard:case">         <div class="slds-m-around_small">             <lightning-datatable                 key-field="id"                 data={result}                 show-row-number-column                 hide-checkbox-column                 columns={columnsList}

Get Record based on Specific Date in SOQL using IN Operator

 We can use IN operator to put a filter on multiple dates while using the Day_Only function. Get specific date of records using IN operator with Day_Only Function  List<Account> lstofacc = [SELECT Id, Name, CreatedDate FROM Account WHERE Day_Only(CreatedDate) IN (2022-01-24, 2022-01-25)]; System.debug(accList); bind variables as well: Date d1 = Date.parse('01/24/2022'); Date d2 = Date.parse('01/25/2022'); List<Account> accList = [SELECT Id, Name, CreatedDate FROM Account WHERE Day_Only(CreatedDate) IN (:d1, :d2)]; System.debug(accList);

Get my org’s url using Salesforce Formula field (Text Type)

  Get my org’s url: The $Api.Partner_Server_URL_530 variable returns the endpoint of your Salesforce org. This formula is saying “Starting from the left of the entire URL, return the characters all the way until the position of “/services”. LEFT({!$Api.Partner_Server_URL_530},FIND("/services", {!$Api.Partner_Server_URL_530}))

number of Saturdays between those 2 dates. Create formula field

FLOOR(( End_Date__c -  Start_Date__c )/7) + IF(OR (WEEKDAY(Start_Date__c )=7, WEEKDAY(End_Date__c )=7, WEEKDAY(Start_Date__c )>WEEKDAY(End_Date__c )),1,0) If you want the number of Sundays: FLOOR(( End_Date__c -  Start_Date__c )/7) + IF(OR (WEEKDAY(Start_Date__c )=1, WEEKDAY(End_Date__c )=1, WEEKDAY(Start_Date__c )>WEEKDAY(End_Date__c )),1,0) This is easily changed for any day of the week. You only need to change the "WEEKDAY" number (1 for Sunday, 2 for Monday, 3 for Tuesday, etc) in this part: WEEKDAY(Start_Date__c )=1, WEEKDAY(End_Date__c )=1

What is Saml and Oauth and Authentication flow in salesforce

Difference between SAML and OAuth Overview of SAML 1. The user makes a request to Force.com for a specific resource. 2. Force.com detects the user needs to authenticate and redirects the user to their SAML Identity Provider. 3. The user accesses their IdP and authenticates. 4. Once authenticated, the IDP sends a SAML Response back to Salesforce.com. 5. Force.com processes the SAML assertion and logs the user in. Overview of OAuth 1. The OAuth Client makes an authorization request. 2. The Authorization Server authenticates the user. 3. The user authorizes the application. 4. The application is issued an OAuth token. Difference between Web server OAuth flow, User agent flow OAuth Authentication flow and Username-Password OAuth Authentication flow Web server OAuth flow  Typically used for web applications where server-side code needs to interact with Force.com APIs on the user’s behalf, for example DocuSign. Trust that the web server is secure to protect the consumer secret. Client applic