General Use cases
- johnsontitus
- May 29, 2020
- 3 min read
Updated: Jun 5, 2020
A case is entered and submitted on an external web form. It gets created on Salesforce.
On Salesforce there should be a mechanism to find out whether there are any matching records based on contact name or email address.
Solution:
Process builder that gets invoked on case creation, calls the @invocableMethod on apex that will execute a SOSL - find {name or email} in all Fields returning Opportunity(<fields>), contact(<fields>), case(<fields>)
Use case - a trigger on an object should update a field only if a specific field has changed.
Solution - Use the before update trigger, extract the new and old value of the specific field by using Trigger.new and Trigger.oldmap.get(<id of the sobject>) respectively.
Perform the field update only if the old and new values are different.
Use case - to run a flow that fires when the user is closing the case but the user does not have edit permission on a field involved in the flow as a result it throws an error.
How to overcome the error without changing the field level security?
Solution - change the flow to run in system context with sharing mode will ignore user permission and field level security.
Use case - to access data from legacy systems such as SAP, Microsoft and Oracle in real time.
For eg, to connect to the order management system where each order is related to Account in Salesforce.
Solution -
Use Salesforce connect to connect to the order management system.
Create an external ID field i.e. Customer ID on Account which is the parent object.
Create external object to represent the external data source - orders and orderdetails.
Create indirect lookup relationship on the child external object using its field Customer ID that would related to the parent object - Account and its external ID field - Customer ID.
For eg, orders with Customer ID - 2 will relate to the external id(ie. Customer ID of the Account) with value 2.
To display the orderdetails(External Object) as a related lists in orders(External object), create an external lookup relationship on the child object on the field - orderID which is the foreign key in orderdetails.
Note - External ID field is created on the parent and indirect lookup or external lookup relationship field is created on the child object.
Use case - prevent the user from deleting a contact not associated to an Account
Solution:
Create a trigger on contact(before delete)
{
for(Contact c : Trigger .old){
if(c.Accountid == null){
c.addError('cannot delete as it has no associated account');
}
}
}
Use case - to process 50000 items from a search result
Solution -
public with sharing class myClass{ private String myString; public myClass(String searchString) { myString = searchString; } private string getQueryString() { return 'SELECT Id, Name FROM Account LIMIT 50000'; } public List<Account> getSearchResults() { List<Account> searchResults = new List<Account>(); for(List<Account> accts : Database.Query(getQueryString())) { // Each loop processes 200 items for(Account a : accts) { if (a.Name != null && a.Name.contains(myString)) { searchResults.add(a); } } } return searchResults; } }
Use case - to validate an address on the account page using an external web service.
Solution - use visualforce page to call the web service and deploy the page on a button which can be set on the account page
Use case - to track product that are most often faulty when technician conducts field repair.
Field work is tracked using work order and work order line item.
Solution - in the work order line item use asset that has the product linked to it.
Use case - A custom UI is required for the Opportunity page in LEX.
Solution - Build a custom Lightning component and add it to the record page using App Builder.
Use case - The opportunity with the highest amount in the entire org needs to be displayed on an opportunity when its created.
Solution - Use Apex trigger to trigger when the opportunity is created.
Use case - The existing opportunity detail page needs to be replaced with a new highly customized page that uses a different format.
Solution - An existing record detail page can be overridden with a Visualforce page.
Use case - A contact record needs to be created based on contact information in email messages received.
Solution - Use the Apex email service.
Use case - A community page needs to display UI that utilizes data from multiple objects.
Solution - A custom lightning component can be developed.
Use case - A list of opportunities that have not been modified in the last seven days needs to be displayed in the app.
Solution - A custom lightning component can be developed .

Comments