Adarsh Singh
IndividualForum Replies Created
-
Adarsh
MemberMarch 21, 2018 at 11:23 am in reply to: How to get all the field names of an object using SOQL?Hi Kapil,
you may use this,
String ObjId = stdController.getId();
DescribeSObjectResult describeResult = Id.valueof(ObjId).getSObjectType().getDescribe();
List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() );
String query =' SELECT Account.Name,' +String.join( fieldNames, ',' ) +' FROM ' +describeResult.getName() +' WHERE ' +' id = :ObjId ' +' LIMIT 1 ';
List<Contact> records = Database.query( query );Hope it helps 🙂
-
Adarsh
MemberFebruary 26, 2018 at 12:59 pm in reply to: How can we insert a dynamic value in the Email Body of an Email Template in Salesforce?Hi Suryadeep,
Yes, it is possible through 'VisualForce Email Template' type. you may pass dynamic values in this kind of email templates.
Hope it helps 🙂
-
Adarsh
MemberFebruary 21, 2018 at 9:46 am in reply to: How to find all required fields of sobject in Salesforce?Hi ankit,
you may use following code.
Map<String, Schema.SObjectType> m = Schema.getGlobalDescribe();
Schema.SObjectType s = m.get('Contact');
Schema.DescribeSObjectResult r = s.getDescribe();
Map<String,Schema.SObjectField> fields = r.fields.getMap();for(String field : fields.keyset()) {
Schema.DescribeFieldResult describeResult = fields.get(field).getDescribe();
if (describeResult.isCreateable() && !describeResult.isNillable() && !describeResult.isDefaultedOnCreate()) {
System.debug(field);
}
}hope it helps 🙂
-
Adarsh
MemberFebruary 20, 2018 at 5:45 am in reply to: Window.location.href is not working in Microsoft edgeHello Ajay,
According to your post, my understanding is that the window.location.href not worked in IE 8 also.
I think the issue is likely due to the value of your variables. If they contain special or invalid characters, those needs to be passed through 'encodeURIComponent' before being assigned to window.location.href.
Ex.
// encodes characters such as ?,=,/,&,:
console.log(encodeURIComponent('?x=шеллы'));
// expected output: "%3Fx%3D%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"console.log(encodeURIComponent('?x=test'));
// expected output: "%3Fx%3Dtest"You can also use the following methods to check whether it works.
Window.navigate();
Winodw.history.back();
Self.location.href;
Top.location;
hope it helps 🙂
-
Hi Uday,
Test Methods are static in Salesforce because you do not call the test methods explicitly when you run a class for execution.
When you run your apex tests these methods needs to be executed whether they are called or not which is why we make them static so they can be run while the class executes.
A static method doesn’t require an instance of the class in order to run. They’re created with every object instantiated from the class in which they’re declared.
Hope it helps 🙂
-
Adarsh
MemberJanuary 16, 2018 at 1:34 pm in reply to: What is the difference between testMethod and @isTest in Salesforce?Hello Ankit,
While creating a Test Method both act same, but @isTest is the enhanced version of 'TestMethod' keyword.
In case of best practice, we always use @isTest annotation for creating a Test method.
Hope it helps 🙂
-
Adarsh
MemberJanuary 16, 2018 at 8:48 am in reply to: What are the actions in Salesforce that don't invoke Triggers?Hello Subhendu,
There are some system bulk operations don't invoke triggers. Some examples include:
Cascading delete operations. Records that did not initiate a delete don't cause trigger evaluation.
Cascading updates of child records that are reparented as a result of a merge operation
Mass campaign status changes
Mass division transfers
Mass address updates
Mass approval request transfers
Mass email actions
Modifying custom field data types
Renaming or replacing picklists
Managing price books
Changing a user's default division with the transfer division option checked
Changes to the following objects:
BrandTemplate
MassEmailTemplate
Folder
Update account triggers don't fire before or after a business account record type is changed to person account (or a person account record type is changed to business account.)Hope it helps 🙂
-
Hi Shubham,
When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order:
1. Loads the original record from the database or initializes the record for an upsert statement.
2. 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.
3. Executes all before triggers.
4. 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.
5. 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.
6. Saves the record to the database, but doesn't commit yet.
7. Executes all after triggers.
8. Executes assignment rules.
9. Executes auto-response rules.
10.Executes workflow rules.
11.If there are workflow field updates, updates the record again.
12.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.
13.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.
14.Executes escalation rules.
15.Executes entitlement rules.
16.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.
17.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.
18.Executes Criteria Based Sharing evaluation.
19.Commits all DML operations to the database.
20.Executes post-commit logic, such as sending the email.Note - During a recursive save, Salesforce skips steps 8 (assignment rules) through 17 (roll-up summary field in the grandparent record).
Hope it helps 🙂
-
Adarsh
MemberJanuary 16, 2018 at 8:30 am in reply to: What are Patch Versions in Salesforce? How and why do we use them?Hello Subhendu,
A patch version enables a developer to change the functionality of existing components in a managed package while ensuring that subscribers experience no visible changes to the package. Patches should be considered as minor upgrades to a Managed - Released Managed - Released package and only used for fixing bugs or other errors.
Patch versions can only be created for Major Releases. Subscribers can receive patch upgrades just like any other package version. However, you can also distribute a patch by using push upgrades.
When you create a patch, the patchNumber on a package's Version Number increments by one. For example, suppose you release a package with the version number 2.0. When you release a patch, the number changes to 2.0.1. This value can't be changed manually.
Every patch is developed in a patch development organization, which is the organization where patch versions are developed, maintained, and uploaded. To start developing a patch, you need to create a patch development organization. To do this, see Create and Upload Patches. Patch development organizations are necessary to permit developers to make changes to existing components without causing incompatibilities between existing subscriber installations.
Hope it helps 🙂
-
Adarsh
MemberJanuary 12, 2018 at 1:00 pm in reply to: How to find child relationship name in Salesforce? -
Adarsh
MemberJanuary 12, 2018 at 12:50 pm in reply to: What is the difference between Custom Metadata and Custom Setting in Salesforce and how both are different from Custom object?Hello Piyush,
What is metadata?
Metadata describes data. If you’ve ever defined your own custom object or custom fields, you are probably already familiar with the concept. Say you wanted to add a field to the Account object. You would need to configure properties such as its name, data type, field length and whether or not it can be left blank. This field definition is metadata.Custom metadata types extend this concept. In fact, the interface for creating custom metadata types and custom metadata records is almost identical to that of creating custom objects and custom object records. In Apex, custom metadata types can be treated as SObjects and respond to SOQL queries the same way SObjects would.
Custom Metadata vs Custom Objects
Custom metadata records can be queried using SOQL, but the platform internally caches the metadata records and can retrieve them more quickly than it retrieves SObject records. Querying custom metadata also doesn’t count towards SOQL limits, which is good news for performance and throughput in enterprise organizations.Custom Metadata vs Custom Settings
Custom metadata records can be packaged, which is not the case for either custom objects or custom settings. You have greater control over the visibility of custom metadata types; you can hide the custom metadata types themselves or just hide specific records. You can also control whether or not users can update record values on a field by field basis.These are major selling points for adopting custom metadata types. Package developers often want to ship default records with their managed packages. Prior to custom metadata types, they would have spent considerable development effort writing post-install scripts to create the data. They would also have to ensure the application coped gracefully with the data not existing; either because it hasn’t yet been created or because a user deleted it.
Custom metadata records can also be pushed from sandboxes to production orgs via changesets. This allows you to follow platform best practices; testing out changes in a sandbox before migrating them via changesets into the production org.
Hope it helps 🙂
-
Adarsh
MemberJanuary 12, 2018 at 12:42 pm in reply to: What is Custom Metadata Type in Salesforce? How is it different from Custom Objects and Custom Settings?Hello Subhendu,
Custom Object - In Salesforce, you're able to create a custom object to store a particular set of data where users can create and manage that data all under a tab.
Custom Setting - 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.
Custom Metadata - Custom metadata is customizable, deployable, packageable, and upgradeable application metadata. First, you create a custom metadata type, which defines the form of the application metadata. Then you build reusable functionality that determines the behavior based on metadata of that type. Similar to a custom object or custom setting, a custom metadata type has a list of custom fields that represent aspects of the metadata.
Custom metadata types generally were known as metadata of metadata. The main advantage to using the custom metadata types is you can add both definition and records in the package or changeset. These are same as the custom object and custom setting that resides in Application Cache instead of Org Data Storage.Unlike custom setting metadata use __mdt in its API name.
Advantages of Custom Metadata:
1. Metadata are deployable! No more annoying configuration after deployment, which you have to do with Custom Settings. You don’t need to create Apex classes to generate your default Custom Setting records.
2. They have WAY more options that Custom Settings: picklist fields, long text areas (in Spring ’17), page layouts, and validation rules.
3. The beauty that is Metadata Relationships! You can create lookups between Custom Metadata objects. Additionally, you can create an Object Definition lookup.
4. Custom Settings have the same permission to edit the records and to edit the configuration. Both can be done with the “Configure Application” permission. With Custom Metadata, you can edit the records with “Configure Application” but you require “Author Apex” to edit the configuration.
Hope it helps 🙂
-
Adarsh
MemberJanuary 12, 2018 at 8:06 am in reply to: Why we cannot perform DML operation on SET type collection variable in Salesforce?Hello Kapil,
Yes, we can't perform DML operation on Set collection -
1) List -> Ordered(Allows indexing), Allow duplicacy and Allow DML.
List<Integer> lstArr = new List<Integer>{1, 2, 3};
system.debug(lstArr[1]); //Valid1) Set-> Unordered(Does not allows indexing) and did't Allow duplicacy.
Set<Integer> setArr= new Set<Integer>{1, 2, 3};
system.debug(setArr[1]); //Not validFor DML operation - In the case of sets ,we can't use DML over sObjects. in that we need to add all Data in set to list and go for DML once again.
Hope it helps 🙂
-
Adarsh
MemberJanuary 12, 2018 at 6:58 am in reply to: In salesforce, which are the objects where we can not use DML Statements?Hello Ankit,
Yes, there are many objects in salesforce which do not support any DML operation over there.
However, some standard objects don’t support DML operations although you can still obtain them in queries. They include the following:
1.AccountTerritoryAssignmentRule
2.AccountTerritoryAssignmentRuleItem
3.ApexComponent
4.ApexPage
5.BusinessHours
6.BusinessProcess
7.CategoryNode
8.CurrencyType
9.DatedConversionRate
10.NetworkMember (allows update only)
11.ProcessInstance
12.Profile
13.RecordType
14.SelfServiceUser
15.StaticResource
16.Territory2
17.UserAccountTeamMember
18.UserTerritory
19.WebLinkHope it helps 🙂
-
Hello Ankit,
There are basically two types of triggers.
1. Before triggers are used to update or validate record values before they’re saved to the database.
2. After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDate field) and to affect changes in other records. The records that fire the after trigger is read-only.and there are following types are events in triggers -
1. before insert
2. before update
3. before delete
4. after insert
5. after update
6. after delete
7. after undelete -
Adarsh
MemberJanuary 12, 2018 at 6:34 am in reply to: Can we have two methods in a class having same name and Webservice keyword with their declaration in Salesforce?Hello Subhendu,
NO, Within Salesforce we can't define two methods with the same name in a class. just because SOAP and WSDL do not provide good support for overloading methods. Consequently, Apex does not allow two methods marked with the web service keyword to have the same name. Web service methods that have the same name in the same class generate a compile-time error.
Hop it helps 🙂
-
Adarsh
MemberJanuary 11, 2018 at 2:20 pm in reply to: What is the difference between database.querylocator and Iterator list in Salesforce? What are their use cases?Hi Shubhendu,
As per our DataSet which is going to be executed, we need to decide this.
Database.querylocator - If we need the filtered record in our DataSet, means if you want to run the batch on records that can be filtered by SOQL then QueryLocator is preferable.A maximum of 50 million records can be returned in the Database.QueryLocator object
Iterator list - An iterator traverses through every item in a collection. For example, in a while loop in Apex, you define a condition for exiting the loop, and you must provide some means of traversing the collection, that is, an iterator. In the following example, the count is incremented by 1 every time the loop is executed (count++) :
Hope it helps 🙂
-
Adarsh
MemberJanuary 11, 2018 at 10:22 am in reply to: How to Validate string that is Numeric in AngularJs ?Hi,
You may use “return event.keyCode“ or there is a script, may it helps you.
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script>
var app = angular.module('app', []);
app.directive('numbersOnly', function () {
return {
require: 'ngModel',
link: function (scope, element, attr, ngModelCtrl) {
function fromUser(text) {
if (text) {
var transformedInput = text.replace(/[^0-9]/g, '');if (transformedInput !== text) {
ngModelCtrl.$setViewValue(transformedInput);
ngModelCtrl.$render();
}
return transformedInput;
}
return undefined;
}
ngModelCtrl.$parsers.push(fromUser);
}
};
});
</script>
<div ng-app="app" class="container">
<p><input type="text" ng-model="val" numbers-only class="form-control" /></p>
</div>
</html> -
Adarsh
MemberJanuary 11, 2018 at 7:58 am in reply to: How to Validate string that is Numeric in AngularJs ?Hello Piyush,
If we talking about only this requirement, then I think this is the simplest and fastest way for allowing the Number input only.
<input type="text" id="NumOlny" placeholder="Enter a Number" onkeypress='return event.charCode >= 48 && event.charCode <= 57' required>
Hope it helps 🙂
-
Adarsh
MemberJanuary 10, 2018 at 1:49 pm in reply to: Refresh a particular output panel in some specific interval of time in Salesforce Visualforce PageHello Piyush,
There is a remarkable attribute within <apex:actionPoller> component is "enabled". With the use of this attribute, you may achieve your requirement.
Visual Force Page -
<apex:page controller="Referesh_A_Certain_At_Sertain_TimeCtrl">
<style>
.Processing{
position: fixed;
background: url('/img/loading32.gif');
background-repeat: no-repeat;
background-position: center;
width: 100%;
height: 100%;
z-index: 10004;
left: 0%;
top: 0%;
}
</style>
<apex:form >
<apex:actionStatus id="idStatus" startStyleClass="Processing" ></apex:actionStatus>
<apex:actionPoller action="{!increment}" rerender="count" interval="5" enabled="{!IF(count < 0,false,true)}" status="idStatus" /><apex:outputPanel id="count">
{!IF(count < 0,false,true)}
{!count}
</apex:outputPanel>
</apex:form>
</apex:page>Controller -
public class Referesh_A_Section_At_Certain_TimeCtrl{
public Decimal count {get; set;}
public Referesh_A_Section_At_Sertain_TimeCtrl(){
count = 0;
}
public void increment(){
count++;
}
}Hope it helps 🙂