Monthly Archive April 2018

Bynayakdillip

How to get size of items in an array?

JavaScript Array length Property
length:it returns size(no.of items ) of an array

Example:-

[html]
var languageArray=[‘c#’,’c’,’java’];
//its diplay like c#,c,java
alert(languageArray);

//remove last item using pop method
var arraylength=languageArray.length;
alert(arraylength);
[/html]
//it will print 3(no of items in languageArray is 3)

Bynayakdillip

How to remove last item to an array?

JavaScript Array Pop() Method

Pop(): it helps to remove last item(element) from an array and returns the final array.

Example:-
[html]
var languageArray=[‘c#’,’c’,’java’];
//its diplay like c#,c,java
alert(languageArray);

//remove last item using pop method
languageArray.pop();
alert(languageArray);
[/html]

//it will print c#,c,java

Bynayakdillip

How to append item to an array?

JavaScript Array push() Method

Push():-Its helps to add a new item at the end of the array.use the push() method/function to append an array

Example:-

[html]
//Array of programing language
var languageArray=[‘c#’,’c’,’java’];
//its diplay like c#,c,java
alert(languageArray);

//Append new value to the array

languageArray.push(‘salesforce’);

alert(languageArray);
[/html]
//it will print c,c#,java,Salesforce

Note: You also push object type in an array its depend upon your requirement.

Bynayakdillip

Var and Let in Javascript

Var and Let in Javascript

Var:-Dynamic data type in javascript
let:-dynamic data type in javscript

Difference between Var and Let
The difference is “let” is visible only in the for() loop and var is visible to the whole function.

when you use Let

[html]
<script>
var iPLTemsList = [‘CSK’, ‘DD’, ‘KXIP’, ‘KKR’,’MI’,’RCB’,’SRH’,’RR’];
for(let ipl in iPLTemsList){
alert(iPLTemsList[ipl]);
}
alert(ipl);
</script>
[/html]

//JavaScript error: Uncaught ReferenceError: ipl is not defined on line 6

when you use var

[html]
<script>
var iPLTemsList = [‘CSK’, ‘DD’, ‘KXIP’, ‘KKR’,’MI’,’RCB’,’SRH’,’RR’];
for(Var ipl in iPLTemsList){
alert(iPLTemsList[ipl]);
}
alert(ipl);//Display 7
</script>
[/html]

Also, If you Redeclaration var and let, var will let you re-declare the same variable in the same scope. On the other hand, let will not:
[html]
‘use strict’;
let i= 3;
let i = 5; // SyntaxError: Identifier ‘i’ has already been declared
[/html]

[html]
‘use strict’;
var i = 3;
var i = 5; // No problem, `i` is replaced.
[/html]

Advantages of using let over var within a function.the difference is that let is block-scoped and var is not.

Note:-Experts always recommend solely using let everywhere, if it is available in your environment.

Bynayakdillip

JavaScript Arrays

Before learning Javascript Array.

Why did you learn javascript?
Javascript has become an essential web technology along with HTML and CSS.You must Learn javascript if you want to get into web development with using Any Technology (.Net MVC, PHP, Java, Salesforce, Dynamic CRM)

let’s discuss something about javascript Array.

An array is a collection of same type data(means integer, string etc) values.we can store many values and retrieve values as per index.Also, you can store lists an array.

How to create arrays

Synatax:
[html]
var arrayOFLanguages=["","","",….];//var dynamic type it holds different data type like Integer,String,Char,List etc
[/html]

Example:
[html]
var arrayOfRollNumbers=[1,2,3,4,5,6];//it store integer value of roll numbers
[/html]

[html]
Var arrayOfNames=[‘Dillip’,’Kunal’];//It store string value of Names
[/html]

For Accessing Particular Value
[html]
Var rollNumber=arrayOfRollNumbers=[0];//it display 1
[/html]
[html]
var name=arrayOfNames[1];//it display kunal(Retrive Records by index.Index always start with 0.
)
[/html]

Methods in Array

Push
Pop
Length
Concat
Sort
Reverse
Delete
ToString

Bynayakdillip

Introduction to salesforce survey(spring 18)

salesforce survey(spring 18)

  • 1.its available in spring 18
  • 2.Component available for community builder
  • Let’s create a survey for creating the survey you need to enabled survey

    setup–>Survey–>survey setting–>Enabled

    After the Enabled survey, you need to visit all tab its showing survey Tab.

    After clicking the survey tab you need to click New survey

    survey–>New Survey

    it redirects to survey builder

    You need to give survey name and put all the question then your thank you page.

    After creating all the steps you need to active same then on the top, there is link send button its help you send the URL .

    Here my result
    Beer Survey(surveyName=beer_drinking_survey)






    Bynayakdillip

    How to consume third party Rest API From salesforce

    Rest API:Representational State Transfer

    Let’s discuss some stubs about salesforce Integration.

    How to consume third-party Rest API From salesforce.

    here I am going to explain how we send request from salesforce to third-party rest API. Then
    get a response from third-party API.

    the simplest request is a GET request(HTTP Method).

    GET–>GET methods help retrieve data from identified by a URL.

    Example:-

    First, need to add your third party REST API to the remote site settings in salesforce org .Once done, we need create apex code to retrieve records.

    I have found below Third party URL for testing point of view

    https://jsonplaceholder.typicode.com/

    Step:-1

    setup–>Remote Site Setting

    Step:-2

    Add URL

    https://jsonplaceholder.typicode.com

    Step:3
    I. Open the Developer Console from the Setup gear (Setup gear icon).
    II. On the Developer Console, select Debug | Open Execute Anonymous Window.
    [html]
    Http http=new Http();
    HttpRequest request=new HttpRequest();
    request.setEndpoint(‘https://jsonplaceholder.typicode.com/users’);
    request.setMethod(‘GET’);
    HttpResponse response=http.send(request);
    if(response.getStatusCode()==200)
    {
    list<object> results=(list<object>)JSON.deserializeUntyped(response.getBody());

    for(object user:results)
    {
    system.debug(‘user’+user);
    }
    }
    [/html]
    III. Select code, and then click Execute.
    IV. After the debug log opens, select Debug Only to view the output of the System.debug statements.
    The user detail of user is displayed.




    Class Example:-
    [html]
    public class jsonplaceholderAPI {

    public static list<object> GetUsers()
    {
    Http http=new Http();
    HttpRequest request=new HttpRequest();
    request.setEndpoint(‘https://jsonplaceholder.typicode.com/users’);
    request.setMethod(‘GET’);
    HttpResponse response=http.send(request);
    list<object> results=new list<object>();
    if(response.getStatusCode()==200)
    {
    results=(list<object>)JSON.deserializeUntyped(response.getBody());

    }
    return results;
    }
    }
    [/html]

    Bynayakdillip

    Access Modifiers in apex

    Apex has four access modifiers

    Private
    Public
    Protected
    Global

    Private :If you define private that you don’t want outside code to call(like within class).in other words, methods used by the
    public methods of your class.

    Note: If you do not specify an access modifier, the method or variable is private.

    Public :If you define public that use within class as well as outside the class means any code anywhere can access
    the public .

    protected : if you define protected it access to any inner class and to the classes that extend the defining apex
    class.

    global:if you define global it can used by apex code that has access to the class .not just the apex code in
    the same application it also access outside of the application like Rest API/SOAP API.