Saturday, 18 November 2017

Vue JS In Salesforce

Arpit Sharma

Now MIT Developer come up with new Javascript framework under MIT License i.e Vue.js. It is cross platform framework and written in javascript. Vue.js is a progressive framwork means Reliable, Fast, Engaging. It can be easily integrated with existing projects. It can also used to create single page application with Support Libraries and Modern Tooling.

Prerequisite

To Learn Vue.Js Developer need to intermediate knowledge of Javascript, CSS, HTML.

How to Use in Vue.js in Salesforce - 

1. Download Vue.js from here.
2. Upload into static Resource.
3. Create new Page Named VueJsExample add following code 
  • First we give id to element in HTML.
  • Then in JS set that element to be app using Id with help of Vue.js capabality.
  • Then set properties of app.

<apex:page>
   <apex:includeScript value="{!$Resource.vuejs}"/>
   <div id="app">
      <p>{{ message }}</p>
   </div>
   <script>
      var app = new Vue({
          el: '#app',
          data: {
          message: 'Salesforce With View.js'
          }
      })
   </script>
</apex:page>


Now we have created first vue app In this example if change value of app.message dynamically then message value automatically change in html same as angular.





Saturday, 30 September 2017

VisualForce - loadOnReady attribute on apex:includeScript

Arpit Sharma


Salesforce provide us apex:includeScript tag to include script on visual force page.


In this post we will discuss about loadOnReady attribute of apex:includeScript tag.

Role of loadOnReady attribute in apex:includeScript - 

1. loadOnReady attribute have two value i.e false and true.

2. Default value of this attribute is false.

3. If value of this attribute is false then script load immediately.

4. If value of this attribute is true then script will load when page is ready.


Let us take an example to understand loadOnReady attribute

1. When loadOnReady attribute is false then we get angular at both place outside of onload and inside the on onload.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<apex:page >
  <!-- External Scripts -->
      <apex:includeScript loadOnReady="false" value="{!$Resource.angular_js_script}" />
  <!-- External Scripts -->
  <script>
      alert(typeof angular);//we will get angular here.
      window.onload = function(){
          alert(typeof angular);// we will get angular here.
      }
  </script>
  
</apex:page>

2. When loadOnReady attribute is true then we get angular only in inside the on load.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<apex:page >
  <!-- External Scripts -->
      <apex:includeScript loadOnReady="false" value="{!$Resource.angular_js_script}" />
  <!-- External Scripts -->
  <script>
      alert(typeof angular);//we will get undefined here means angular is not loaded here.
      window.onload = function(){
          alert(typeof angular);// we will get angular here.
      }
  </script>
  
</apex:page>

References - Salesforce docs

Saturday, 23 September 2017

A useful String method : normalizeSpace

Arpit Sharma


Salesforce release a very good method of string which is required in string manipulation during development i.e normalizeSpace().

Functionality of normalizeSpace Method - This method normalizes the following white space characters: space, tab, new line, carriage return, and form feed.

Remove leading white space characters, trailing white space characters, and repeating white space characters from string.

Example of normalizeSpace Method -

1
2
String unnormalizeString = ' Salesforce       \t  \n   \r  \f Normalize Example ';
System.assertEquals('Salesforce Normalize Example',unnormalizeString.normalizeSpace());//return true

Explanation of normalizeSpace Example 

1. In above example unnormalizeString string variable contains space on starting, space on end, multiple spaces in between and spacial character (tab (\t), new line (\n), carriage return (\r), and form feed (\f)).

2. In second line we have applied normalizeSpace() method on unnormalizeString string to remove all spaces and special character, so over statment will successfully passed without failing assert statement.It means string is normalized completely

So this is all about string normalization method.

Let me know if you have any suggestion, doubt, question.




Tuesday, 19 September 2017

Can We Set The Owner Of Record To User Who Does Not Have Object Permission?

Arpit Sharma


In this tutorial we will see, can we set the owner of a record to a user who does not have object permission?

Salesforce provide us a feature to change owner of record but one question come in my mind, can we change owner if user does not have object permission?

So I try below example

1. Created two user u1 and u2.
2. Created one object TestOwner.
3. Given all permission to profile of u1 for TestOwner object.
4. Removed all permission from profile of u2 for TestOwner object.
5. Login to user u1 and created record of TestOwner.
6. Now try to set owner of record to u2.
7. Salesforce stop me change the owner of record to u2 and display message i.e new owner of the record must have at least “Read” permission on TestOwner.

So to change owner of record, new user must have at least read permission on profile for object of that record.