Check Multi Currency Salesforce Org in Apex
Sample Code:
Boolean isMultiCurrencyOrg = UserInfo.isMultiCurrencyOrganization(); System.debug('MultiCurrencyOrg-' + isMultiCurrencyOrg);
Sample Code:
Boolean isMultiCurrencyOrg = UserInfo.isMultiCurrencyOrganization(); System.debug('MultiCurrencyOrg-' + isMultiCurrencyOrg);
Sample Code:
Date dt = System.today(); Integer numberOfDays = Date.daysInMonth(dt.year(), dt.month()); Date lastDayOfMonth = Date.newInstance(dt.year(), dt.month(), numberOfDays); System.debug('lastDayOfMonth-' + lastDayOfMonth);
A custom object with two master-detail relationships is called Junction Object. Junction objects are used to create many to many relationships between objects. A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa. One Object can have only two Master-Detail relationships.
For example, Let us assume that we have two custom objects – A and B. To provide the many to many relationship between A and B, we will need to create one more object let’s say it would be C, it will be called as junction object.
The first master-detail relationship you create on your junction object becomes the primary relationship. This affects the following for the junction object records:
Look and feel: The junction object’s detail and edit pages use the color and any associated icon of the primary master object.
Record ownership: The junction object records inherit the value of the Owner field from their associated primary master record. Because objects on the detail side of a relationship do not have a visible Owner field, this is only relevant if you later delete both master-detail relationships on your junction object.
Division: If your organization uses divisions to segment data, the junction object records inherit their division from their associated primary master record. Similar to the record ownership, this is only relevant if you later delete both master-detail relationships.
Note:
Sample Code:
List<String> brandNameList = new List<String>{'Apple','Microsoft','Lenovo','Samsung','Sony'}; String allBrands = String.join(brandNameList,','); system.debug('All Brands-' + allBrands);
@RemoteAction
methods in an Apex controller or extension.Using Visualforce Remote Objects:
Using Visualforce Remote Objects consists of two parts:
Your page then uses the data access functions to respond to user interaction, including form submissions or controls changes, or in response to timers, or pretty much anything you can write in JavaScript. Although Remote Objects supports only create, select, update, and delete operations, it’s quite flexible in how it does so.
Visualforce Tags:
apex:remoteObjects : Use this component, along with child apex:remoteObjectModel
and apex:remoteObjectField
components, to specify the sObjects
and fields to access using Visualforce Remote Objects. These components generate models in JavaScript that you can use for basic create, select, update, and delete operations in your client-side JavaScript code.
apex:remoteObjectModel : Defines an sObject
and its fields to make accessible using Visualforce Remote Objects. This definition can include a shorthand name for the object, which you can use in JavaScript instead of the full API name. This is especially useful if your organization has a namespace or if you’re packaging an app, and makes your code more maintainable.
apex:remoteObjectField : Defines the fields to load for an sObject
. Fields defined using this component, instead of the fields attribute of apex:remoteObjectModel
, can have a shorthand name, which allows the use of a “nickname” for the field in client-side JavaScript code, instead of the full API name. Use as child of apex:remoteObjectModel
.
Here is an example to Create a Contact Using Visualforce Remote Objects:
Visualforce Page:
<apex:page > <!-- Remote Objects definition to set accessible sObjects and fields --> <apex:remoteObjects jsNamespace="RemoteObjectModel"> <apex:remoteObjectModel name="Contact" fields="Id,FirstName,LastName,Phone"> </apex:remoteObjectModel> </apex:remoteObjects> First Name : <input type="text" name="fname" id="fname"/><br/><br/> Last Name : <input type="text" name="lname" id="lname"/><br/><br/> Phone : <input type="text" name="phn" id="phn"/><br/><br/> <p> <button class="btn" onclick="create()"> Create Contact </button> </p> <script> function create(){ var ct = new RemoteObjectModel.Contact({ FirstName: document.getElementById("fname").value, LastName: document.getElementById("lname").value, Phone: document.getElementById("phn").value }); ct.create(createCallback); } function createCallback(err, ids){ if (err) { displayError(err); } else{ alert("Successfully Created Record with Id :"+ ids); document.getElementById("fname").value=""; document.getElementById("lname").value=""; document.getElementById("phn").value = ""; } } </script> </apex:page>
Best Practices for Using Remote Objects :
Visualforce Remote Objects is an effective tool for quickly adding simple data operations to Visualforce pages. Remote Objects isn’t always the right tool for the job, though, so it’s important to understand how Remote Objects works and when to use a different tool, such as JavaScript remoting.
Think carefully about what your page or application needs to do, and then choose the right tool for the job. Sometimes that tool isRemote Objects, and sometimes it’s something else.
Advantages of Using Remote Objects :
@RemoteAction
methods(@RemoteAction
annotated methods needs to be static so you had to take special precaution as it didn’t supported View state. This hurdle is completely removed now.)