Sunday, December 3, 2017

Apex: Get all required fields of an sObject

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);
    }
}


Share This:    Facebook Twitter

Saturday, December 2, 2017

Sunday, November 19, 2017

Saturday, November 18, 2017

Javascript: Pattern to create instance-specific private data


To make a property private, just make it local to the constructor. Any outside code trying to access age variable will result in an undefined. But the outside code can still call the property that accesses this private variable using the public function getAge.
function Person(name) {

   // Define a variable only accessible inside of the Person constructor
   var age = 25;

   this.name = name;

   this.getAge = function() {
      return age;
   };

   this.growOlder = function() {
      age++;
   };
}

var person = new Person("Nicholas");

console.log(person.name);     // "Nicholas"
console.log(person.getAge()); // 25

person.age = 100;
console.log(person.getAge()); // 25

person.growOlder();
console.log(person.getAge()); // 26

Share This:    Facebook Twitter

Javascript: Predict the value of this argument


this is determined by the calling context, the way in which function is called.

Calling standalone functions directly

When a function is executed as a simple object function directly, this refers to the global object.
function foo() {
   console.log('Hello World!');
   console.log(this);
}

foo();


Calling functions as property of an object reference

Here we have created an object obj, and there is a property on it which is a function. The function is being called as a property on the object. Here this refers to the object obj itself.
var obj = {};

obj.foo = function() {
   console.log('Hello World!');
   console.log(this);
}

obj.foo();

Calling standalone functions using 'new' keyword

When a function is called using the new keyword, this always refer to the newly created object, an empty object.
function foo() {
   console.log('Hello World!');
   console.log(this);
}

new foo();

Share This:    Facebook Twitter

Total Pageviews

My Social Profiles

View Sonal's profile on LinkedIn

Tags

__proto__ $Browser Access Grants Accessor properties Admin Ajax AllowsCallouts Apex Apex Map Apex Sharing AssignmentRuleHeader AsyncApexJob Asynchronous Auth Provider AWS Callbacks Connected app constructor Cookie CPU Time CSP Trusted Sites CSS Custom settings CustomLabels Data properties Database.Batchable Database.BatchableContext Database.query Describe Result Destructuring Dynamic Apex Dynamic SOQL Einstein Analytics enqueueJob Enterprise Territory Management Enumeration escapeSingleQuotes featured Flows geolocation getGlobalDescribe getOrgDefaults() getPicklistValues getRecordTypeId() getRecordTypeInfosByName() getURLParameters Google Maps Governor Limits hasOwnProperty() Heap Heap Size IIFE Immediately Invoked Function Expression Interview questions isCustom() Javascript Javascript Array jsForce Lightning Lightning Components Lightning Events lightning-record-edit-form lightning:combobox lightning:icon lightning:input lightning:select LockerService Lookup LWC Manual Sharing Map Modal Module Pattern Named Credentials NodeJS OAuth Object.freeze() Object.keys() Object.preventExtensions() Object.seal() Organization Wide Defaults Override PDF Reader Performance performance.now() Permission Sets Picklist Platform events Popup Postman Primitive Types Profiles Promise propertyIsEnumerable() prototype Query Selectivity Queueable Record types Reference Types Regex Regular Expressions Relationships Rest API Rest Operator Revealing Module Pattern Role Hierarchy Salesforce Salesforce Security Schema.DescribeFieldResult Schema.DescribeSObjectResult Schema.PicklistEntry Schema.SObjectField Schema.SObjectType Security Service Components Shadow DOM Sharing Sharing Rules Singleton Slots SOAP API SOAP Web Services SOQL SOQL injection Spread Operator Star Rating stripInaccessible svg svgIcon Synchronous this Token Triggers uiObjectInfoApi Upload Files VSCode Web Services XHR
Scroll To Top