Saurabh Gupta
IndividualForum Replies Created
-
Saurabh
MemberApril 21, 2017 at 2:26 pm in reply to: What is Trigger.old and when do you normally use it?Hi Manpreet
Trigger.old
Returns a list of the old versions of the sObject records. Note that this sObject list is only available in update and delete triggers.
We normally use it when we :
Need to check if any field is update in the DML Activity then do another update, like if account name gets changed then update related opportunity name
Hope it may helps
-
Saurabh
MemberApril 21, 2017 at 2:22 pm in reply to: How many Maximum Records can be migrated using Data loader?Hi Suraj
You can load 50,000 to 5,000,000 records by using Data Loader. If you need to load more than 5,000,000 records, i recommend you work with a Salesforce.com partner.
Hope it may help you
-
Saurabh
MemberApril 21, 2017 at 2:09 pm in reply to: Where to use Trigger.new and Where to use Trigger.newMap?Hello Suraj
According to the docs, Trigger.new returns a list, which are ordered, and Trigger.newMap returns a map - which are unordered. The docs specifically state you should not rely on the ordering of a map's elements.
What to use depends on what you're doing - if you have an ID of an object you need to do something with, using the map makes more sense as you can use newMap.get(). Otherwise you'd have to loop over all the elements in Trigger.new and look for a matching ID. Similarly, if you have multiple loops over each item the trigger is operating on, the list returned by Trigger.new may be the better bet.
suppose you have a custom object Custom_obj__c
Trigger.New means it is a List<Custom_obj__c>
and
Trigger.NewMap means it is a map<Id, Custom_obj__c>
In before insert context your Trigger.NewMap always be null because in before context records is not submitted to database so Id is not generated that's why in before insert we don't useTrigger.NewMapBut in After insert Id is generated so We can use Trigger.NewMap
In case of before and After update since id is already generated in Insert event.
SO we can use Trigger.NewMap in before and After update
-
Saurabh
MemberApril 20, 2017 at 2:38 pm in reply to: What is the Sequence of Salesforce Triggers and Order of Execution?Hi Suraj
Salesforce Order of Execution: When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order.
"Before Salesforce executes these events on the server, the browser runs JavaScript validation if the record contains any dependent picklist fields. The validation limits each dependent picklist field to its available values. No other validation occurs on the client side."
On the server, Salesforce:Loads the original record from the database or initializes the record for an upsert statement.
Loads the new record field values from the request and overwrites the old values.If the request came from a standard UI edit page, Salesforce runs system validation to check the record for:Compliance with layout-specific rules
Required values at the layout level and field-definition level
Valid field formats
Maximum field length
When the request comes from other sources, such as an Apex application or a SOAP API call, Salesforce validates only the foreign keys. Prior to executing a trigger, Salesforce verifies that any custom foreign keys do not refer to the object itself.Salesforce runs user-defined validation rules if multiline items were created, such as quote line items and opportunity line items.
Executes all before triggers.
Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
Saves the record to the database, but doesn't commit yet.
Executes all after triggers.
Executes assignment rules.
Executes auto-response rules.
Executes workflow rules.
If there are workflow field updates, updates the record again.
If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
Executes processes.If there are workflow flow triggers, executes the flows.The pilot program for flow trigger workflow actions is closed. If you've already enabled the pilot in your org, you can continue to create and edit flow trigger workflow actions. If you didn't enable the pilot in your org, use the Flows action in Process Builder instead.
Executes escalation rules.
Executes entitlement rules.
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.
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.
Executes Criteria Based Sharing evaluation.
Commits all DML operations to the database.
Executes post-commit logic, such as sending email.For further information information you can refer to:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
-
Saurabh
MemberApril 20, 2017 at 2:30 pm in reply to: Difference between Communities and Sites in Salesforce?Hi Suraj,
Community Builder
It is an intuitive, convenient tool for customizing your community. Community Builder lets you create a community based on a preconfigured template, and then apply branding, edit pages, update your template, and publish changes all from one user-friendly interface.
You can use Community Builder when you want to achieve:
- Use one of the self-service templates—Koa, Kokua, or Customer Service (Napili)—to easily create a responsive self-service community.
- Use the Aloha template to create a configurable App Launcher.
- Design pixel-perfect, branded pages.
- Create public pages that anyone can access, or add private pages that you can add as a tab within your community.
- Build and iterate quickly using drag-and-drop reusable page elements.
- Use ready-made forms to create web-to-lead forms or gather customer feedback.
- Create data-driven pages, such as product catalogs or other listings, using your organization’s data.
- Set a home page and set up multilingual support for your community in Site.com Studio, a Web content management system that provides extra configuration options. Site.com Studio is easily accessible from Community Management.
Force.com Sites
Suitable for developers with experience using Visualforce, Force.com Sites lets you build custom pages and Web applications by inheriting Force.com capabilities including analytics, workflow and approvals, and programmable logic. So if you are looking to create sites programmatically using Apex and APIs, Force.com Sites is the product for you. Here’s what you can achieve with Force.com:- Create public, branded pages that anyone can access.
- Leverage Visualforce to create private pages that you can add as a tab within your community.
- Write your own controllers, or extensions to controllers, using Apex code.
- Create custom login or self-registration pages.
- Build dynamic web applications, such as an event management application.
For more information you can refer to https://help.salesforce.com/articleView?id=siteforce_vs_sites.htm&language=en_US&type=0
Hoping it may help you
-
Hi Suraj
Salesforce provides a WSDL (Web Service Description Language) file. They are called "Enterprise WSDL" and "Partner WSDL". A WSDL is an XML-document that contains a standardized description on how to communicate using a web service (the Salesforce API is exposed as a web service). The WSDL is used by developers to aid in the creation of Salesforce integration pieces. A typical process involves using the Development Environment (eg, Eclipse for Java, or Visual Studio for .Net) to consume the WSDL and generate classes that are then referenced in the integration.
The primary differences between the two WSDL that we provide are:
Enterprise WSDL:
a) The Enterprise WSDL is strongly typed.
b) The Enterprise WSDL is tied (bound) to a specific configuration of Salesforce (ie. a specific organization's Salesforce configuration).
c) The Enterprise WSDL changes if modifications (e.g custom fields or custom objects) are made to an organization's Salesforce configuration.For the reasons outlined above, the Enterprise WSDL is intended primarily for Customers.
Partner WSDL:
a) The Partner WSDL is loosely typed.
b) The Partner WSDL can be used to reflect against/interrogate any configuration of Salesforce (ie. any organization's Salesforce configuration).
c) The Partner WSDL is static and hence does not change if modifications are made to an organization's Salesforce configuration.For the reasons outlined above, the Partner WSDL is intended primarily for Partners.
To download a WSDL file when logged into Salesforce:
1. Click Setup | Customize | Develop | API
2. Click the link to download the appropriate WSDL.
3. Save the file locally, giving the file a ".wsdl" extension.
- This reply was modified 4 years, 10 months ago by Forcetalks.
-
Saurabh
MemberApril 20, 2017 at 2:18 pm in reply to: What are the types of custom settings in Salesforce?Hi Manpreet
Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, flows, Apex, and the SOAP API.
There are two types of custom settings:
List Custom Settings
A type of custom setting that provides a reusable set of static data that can be accessed across your organization. If you use a particular set of data frequently within your application, putting that data in a list custom setting streamlines access to it. Data in list settings does not vary with profile or user, but is available organization-wide. Examples of list data include two-letter state abbreviations, international dialing prefixes, and catalog numbers for products. Because the data is cached, access is low-cost and efficient: you don't have to use SOQL queries that count against your governor limits.Hierarchy Custom Settings
A type of custom setting that uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. However, querying custom settings data using Standard Object Query Language (SOQL) doesn't make use of the application cache and is similar to querying a custom object. To benefit from caching, use other methods for accessing custom settings data such as the Apex Custom Settings methods.
Hope it may helps
-
Saurabh
MemberApril 20, 2017 at 1:41 pm in reply to: What are the types of email templates available in salesforce.com?Hi Suraj
Types of email templates available in salesforce.com are
- Text
- HTML (with letter head)
- Custom HTML (without letter head)
- Visual Force
-
Saurabh
MemberApril 20, 2017 at 6:57 am in reply to: Is there any Standard feature to track Opportunity Line Item in Salesforce?Hi Suraj
Salesforce does not provide any standard feature for history tracking on opportunity line items but by using custom object and trigger we can get to this solution
First you need to create custom object as i created opportunity_Tracking__c
trigger opportunitytracking on OpportunityLineItem(After insert, After update) {
List<opportunity_Tracking__c> hisTrackList = new List<opportunity_Tracking__c>();
//
// Iterate through the OpportunityLineItems and create the History Tracking Record.
//
for (Integer i=0; i < Trigger.new.size(); i++) {OpportunityLineItems newCM = Trigger.new[i];
if(Trigger.isInsert) {
hisTrackList.add(new opportunity_Tracking__c(OpportunityLineItem_Record_Id__c = newCM.Id,
Object_Name__c = 'OpportunityLineItem',
Field_Name__c = 'Status',
Previous_Value__c = '',
Current_Value__c = newCM.Status,
Modified_Date_Time__c = System.now(),
Modified_By__c = UserInfo.getUserId()
));
} else if(Trigger.old[i].Status != newCM.Status){
OpportunityLineItem oldCM = Trigger.old[i];
hisTrackList.add(new opportunity_Tracking__c(OpportunityLineItem_Record_Id__c = newCM.Id,
Object_Name__c = 'OpportunityLineItem',
Field_Name__c = 'Status',
Previous_Value__c = oldCM.Status,
Current_Value__c = newCM.Status,
Modified_Date_Time__c = System.now(),
Modified_By__c = UserInfo.getUserId()
));
}
}
if(!hisTrackList.isEmpty()) {
insert hisTrackList;
}
}Hope it may help you:
-
Saurabh
MemberApril 20, 2017 at 5:27 am in reply to: How to setup Field Level Security (FLS) for Person Account Fields?Hi Suraj
Field Level Security (FLS) of Person Account fields ar controlled by Contact Fields. So, if you want to setup FLS of Person Account Fields navigate to fields of Contact and it will be reflected on Person Account
Hoping this answer may help you:
-
Saurabh
MemberApril 19, 2017 at 3:47 pm in reply to: What are the different data types that a standard field record name can have in Salesforce?Hi Manpreet
A standard field record name can have data type of either auto number or text field with a limit of 80 chars.
For generating auto numbers, the format needs to be specified while defining the field and after that for every record that is added, the number will get auto generated. For example:-
Sr No-{1}
Sr No-{2}
Sr No-{3}Hope it may help:
-
Saurabh
MemberApril 18, 2017 at 1:55 pm in reply to: How can you expose an Apex class as a REST WebService in Salesforce?Hi Manpreet
you can expose your Apex class and methods so that external applications can access your code and your application through the REST architecture. This is done by defining your Apex class with the @RestResource annotation to expose it as a REST resource. You can then use global classes and a WebService callback method.
Invoking a custom Apex REST Web service method always uses system context. Consequently, the current user’s credentials are not used, and any user who has access to these methods can use their full power, regardless of permissions, field-level security, or sharing rules.
Developers who expose methods using the Apex REST annotations should therefore take care that they are not inadvertently exposing any sensitive dataLook at the below piece of code for instance:-
global class AccountPlan {
webservice String area;
webservice String region;
//Define an object in apex that is exposed in apex web service
global class Plan {
webservice String name;
webservice Integer planNumber;
webservice Date planningPeriod;
webservice Id planId;
}
webservice static Plan createAccountPlan(Plan vPlan) {
//A plan maps to the Account object in salesforce.com.
//So need to map the Plan class object to Account standard object
Account acct = new Account();
acct.Name = vPlan.name;
acct.AccountNumber = String.valueOf(vPlan.planNumber);
insert acct;
vPlan.planId=acct.Id;
return vPlan;
} }Hope it may help
-
Saurabh
MemberApril 18, 2017 at 11:41 am in reply to: What are the advantages of using Handler classes in Trigger?Hi Suraj
It is always a best practice to write a single trigger on object and process all operation in apex class (we called it as handler) instead of writing logic in trigger. In handler you can specify the order of event based on different context variables. If you write many triggers in on object,
then you cannot control the order in which triggers gets executed.For best practice, use below suggestion:
1. Pass all trigger context variables to static method (say "OperationManager")in handler class.
2. Create different static methods for different operations which you need to perform.
3. Control the order of different operation in "OperationManager" static method based on context variables.
4. Also you can create different apex classes and call them from "OperationManager" static method.For example, below is modified code as per best practice.
Apex trigger code:trigger JobTrigger on Job__c (after delete, after insert, after undelete, after update, before delete, before insert, before update)
{
String errMsg = JobTriggerHandler.OperationManager(trigger.new, trigger.old, trigger.newMap,trigger.oldMap,
trigger.isBefore,trigger.isAfter,trigger.isInsert,trigger.isUpdate,trigger.isDelete, trigger.isUndelete,trigger.isExecuting);// If error occured, then display it to user
if (errMsg != null) {
if (trigger.isInsert || trigger.isUpdate || trigger.isUndelete) { trigger.new[0].addError(errMsg); } else { trigger.old[0].addError(errMsg); }
}
}Apex class(Handler):
public with sharing class JobTriggerHandler {
// Main entry point for this handler.
public static String OperationManager(list<Job__c> newList, list<Job__c> oldList, map<Id, Job__c> newMap,map<Id, Job__c> oldMap,
boolean isBefore,boolean isAfter, boolean isInsert, boolean isUpdate,boolean isDelete,boolean isUndelete, boolean isExecuting) {
String errMsg;
try {
// Only run a method if previous methods didn't fail
//As you want to perform operation on before insert and before update
if (isBefore && (isUpdate || isInsert) && errMsg == null) {
// Find hourly rate by calling static method defined below
errMsg = computeHourlyRate(newList);
}
//here you can call any other static methods or some other class method to perform desired operations
//keep on adding the other logic which needs to be processed through trigger
//through context variables you can control their execution
} catch (Exception ex) {
errMsg = ex.getMessage() + ' at ' + ex.getLineNumber().format();
}
return errMsg;
}//Below method will compute hourly rate
public static String computeHourlyRate(list<Job__c> newList) {
String errMsg;
try {
Set<Id> AccID = new Set<Id>();
Set<String> JobType = new Set<String>();
Map<String,Rate_card__c> RateCardMap = new Map<String,Rate_card__c>();
for (Job__c Job: newList){
AccID.add(Job.Account__c);
JobType.add(Job.Type__c);
}
For(Rate_Card__c RateCard : [SELECT Id, Hourly_Rate__c, Account__c, Type__c FROM Rate_card__c WHERE Account__c IN: AccID]){
RateCardMap.put(RateCard.Account__c + RateCard.Type__c, RateCard);
}
For (Job__c Jobs: newList){
if(RateCardMap.containsKey(Jobs.Account__c+Jobs.Type__c)){
Jobs.Hourly_Rate__c = RateCardMap.get(Jobs.Account__c + Jobs.Type__c).Hourly_Rate__c;
}
}
} catch (Exception ex) { errMsg = ex.getMessage(); }
return errMsg;
}
}Hope it may help you:
-
Saurabh
MemberApril 18, 2017 at 10:52 am in reply to: Difference between slds-has-flexi-truncate and slds-truncate?Hi Suraj
Difference between Slds-has-flexi-truncate and Slds-truncate is given below:
Slds-truncate
- Usage: It can be applied to:- Any element
- Outcome:Creates truncated text
- Required:No, optional element or modifier
- Comments:Truncation will occur at the parent width if a width is not specified
Slds-has-flexi-truncate
- Usage:It can be applied to:.slds-col
.slds-col--padded - Outcome:Allows truncation in nested flexbox containers
- Required:No, optional element or modifier
- Comments:This class is placed on a parent element that contains a flexbox element containing .slds-truncate. For example — for a media object that is nested in a grid column and contains truncation — the grid column would require this class.
Hope it may help you:
-
Saurabh
MemberApril 17, 2017 at 3:20 pm in reply to: What is the difference between Process Builder and Workflow?Hi Suraj
In short, you can do everything you can do with workflows using process builder as well, except for sending outbound messages with point&click. With process builder, you can also update all child records starting from the parent record, which is not possible with workflows (only vice versa is possible using cross object field updates). I've heard rumors that process builder will replace workflows in the future, which seems a logical step to take for sfdc.
Hope it may help you:
-
Hi Manpreet
Ajax components are nothing but tags start with <apex:action> like
<apex:actionPoller>
<apex:actionFunction>
<apex:actionSupport>
<apex:actionRegion>
<apex:actionStatus>Hope this may help you
-
Saurabh
MemberApril 17, 2017 at 1:56 pm in reply to: Remove 'updated' from users in Account object through batch apex.Hi Manpreet
As far i understand your problem you can try to Run the below code in developer console
List<Account> acc =[SELECT Id, Name FROM Account];
for(Account a : acc)
{
a.Name = a.Name.removeEnd('Updated');
update a;
}Hoping it will help you:
-
Saurabh
MemberApril 17, 2017 at 12:47 pm in reply to: What are the Exception handling types in sfdc except try catch block?Hi Manpreet
All exceptions support built-in methods for returning the error message and exception type. In addition to the standard exception class, there are several different types of exceptions
Visualforce
If you have a custom controller or controller extension for a Visualforce page, you can handle exceptions just as in the examples above. To show the error on a Visualforce page, you can use the ApexPages.message class to create a message for display. Here's an example of a message created in a controller:ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'my error msg');
ApexPages.addMessage(myMsg);Sending an Email on exception
In addition to displaying the message to the user via page messages, you can also notify the developer by email if you like. Here's an example:try{
update account;
} catch (DMLException e){
ApexPages.addMessages(e);Messaging.SingleEmailMessage mail=new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'[email protected]'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('Apex error message');
mail.setSubject('Error from Org : ' + UserInfo.getOrganizationName());
mail.setPlainTextBody(e.getMessage());
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}You could use this technique to ensure that error messages are sent to an error mailing list for example.
Logging in a custom object
If you get enough emails already, another option would be to use a future method to write a custom object that could catch the error details. Your try-catch would look something like this:
try{
throw new MyException('something bad happened!');
} catch (MyException e){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'my error msg');
futureCreateErrorLog.createErrorRecord(e.getMessage());
}Your future class would look something like this.
global class futureCreateErrorLog {
@future
public static void createErrorRecord(string exceptionMessage){
myErrorObj__c newErrorRecord = new myErrorObj__c();
newErrorRecord.details__c = exceptionMessage;
Database.insert(newErrorRecord,false);
}
}For more information about Exception in salesforce you can refer to this link:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_exception_methods.htm
For more information about Exception handling in salesforce you can refer to this link:https://developer.salesforce.com/page/An_Introduction_to_Exception_Handling
Hoping this may help you:
-
Saurabh
MemberApril 17, 2017 at 12:25 pm in reply to: In Batch class execute method default limit is 200.How can i Change this in salesforce?Hi Suraj
You can use the Database.executeBatch(sObject className, Integer scopeSize) method to set the new batch size.
But you need to be sure that the scopeSize should less than 200.
Database.executeBatch(sObject className, 50 ) would set the batch size to 50 instead of 200
Hoping this may help you
-
Saurabh
MemberApril 13, 2017 at 1:43 pm in reply to: Is there any other way to access object in Salesforce Visualforce page than using controller?Hi Suraj,
Yes You can use remote object. Visualforce Remote Objects are proxy objects that enable basic DML operations on sObjects directly from JavaScript. Remote Objects remove some of the complexity from JavaScript remoting by reducing the need for @RemoteAction methods in an Apex controller or extension.
-
Saurabh
MemberApril 13, 2017 at 1:41 pm in reply to: Difference between apex:pageMessage and apex:pageMessages in Salesforce Visualforce?Hi Suraj,
apex:pagemessage is used to show single message only
apex:pagemessages is used to show messages based on some condition
-
Saurabh
MemberApril 12, 2017 at 5:20 pm in reply to: Objects available in the Salesforce Business Process?Hi Manpreet
Allows you to track separate sales, support, and lead lifecycles
across different divisions, groups, or markets
Available Business Processes:
– Sales Processes – Create different sales processes that include some or all of the picklist values available for the Opportunity Stage field
– Support Processes – Create different support processes that include some or all of the picklist values available for the Case Status field
– Lead Processes – Create different lead processes that include some or all of the picklist values available for the Lead Status field
– Solution Processes – Create different solution processes that include some or all of the picklist values available for the Solution Status fieldHope it help you:
-
Saurabh
MemberApril 12, 2017 at 5:50 am in reply to: I want to count related Contact in a Account.How can i do this in salesforce Apex Code?Hi Suraj,
public class AccountProcessor {
static public Integer count;
@future public static void countContacts(Set<Id> AcctId ){
List<Account> Acclist=[select name,AccountNumber from Account where Id in:AcctId];
if(Acclist.size()>0){
for(Account A:Acclist){
count=0;
count=[select count() from Contact where AccountId=:A.Id];
A.Number_of_Contacts__c=count;//[select count() from Contact where AccountId=:A.Id];
update(A);
}
}where Number_of_Contacts__c is the custom Field on Account which store the Number of Related Contact in Account.
Hope this will Help You
-
Saurabh
MemberApril 12, 2017 at 5:47 am in reply to: Salesforce Error: Invisible Future Method in Test Class?Hi Suraj,
In order to make the future method visible in Test Class you need to make the Future method public.Use this Syntax
@future public static void countContacts(Parameter)
Hope this will help you.
Thanks
-
Hi Manpreet
Salesforce users can see their limit form setup easily by simply clicking data.com administration/Users. From the data.com users section, the users can see their monthly limit and exactly how many records are exported during the month.
Hope it may help you: