Posts

Showing posts from March, 2018

Reverse the string without using any temporary variable?

1. We can use XOR logic for swapping the variables. public String reverseString(String str) {       char[] a = str.toCharArray();       int len = a.length-1;       int half = a.length/2;            for  ( int  i = 0; i < half; i++)        {             a[i] ^= a[len - i];             a[len - i] ^= a[i];             a[i] ^= a[len - i];        }         return String.valueOf(a); } 2.  Using built-in reverse() method of the StringBuilder class.     public void reverseString(String input)     {         StringBuilder input1 = new StringBuilder();         // append a string into StringBuilder input1         input1.append(input);         // reverse StringBuilder input1         input1 = input1.reverse();         // print reversed String         for (int i=0; i<input1.length(); i++)             System.out.print(input1.charAt(i));     }            

How to Build REST API Using PHP

Image
Create REST API in PHP API stands for Application Programming Interface and the idea behind API is to connect different applications irrespective of their platforms to share information. Generally, API takes requests from different applications, processes it and gives back the response. What is REST API? REST stands for Representational State Transfer and it means that the request and the response should contain a representation of the information i.e., should be in a certain format. So basically, the requests must use proper HTTP methods and the response must be in a proper format like JSON or XML instead of plain text. REST API is nothing but a normal API with a set of principles. We need to follow a set of rules while creating and consuming REST API. The rules include the following : 1. Use appropriate HTTP methods while performing API calls. The following are the four primary HTTP methods which should be used to send and receive API requests.       a. GET   

Explain about “Too Many SOQL Error: 101”

“System.LimitException: Too many SOQL queries: 101”   This error occurs when you exceed SOQL queries governor limit. The actual limit is “you can run up to a total of 100 SOQL queries in a single call or context”. How to resolve this “Error: System.LimitException: Too many SOQL queries: 101” To fix the issue, change your code so that the number of SOQL fired is less than 100. If you need to change the context, you can use @future annotation which will run the code asynchronously. Avoid SOQL queries that are   inside FOR loops . Follow the key coding principals for Apex Code: 1. Avoid SOQL queries inside For loop. trigger accountTestTrggr on Account (before insert, before update) {   //This queries all Contacts related to the incoming Account records in a    // single SOQL query.   //This is also an example of how to use child relationships in SOQL   List<Account> accountsWithContacts = [select id, name, (select id, salutation,     description, firstnam

SOQL (Salesforce Object Query Language)

SOQL: SOQL (Salesforce Object Query Language) retrieves the records from the database by using a SELECT keyword.  SOQL allows you to specify the source object (such as Account), a list of fields to retrieve, and conditions for selecting rows in the source object. SOQL doesn’t support all advanced features of the SQL SELECT command. The syntax of SOQL,  SELECT  one or more fields   FROM object  WHERE  filter statements and, optionally, results are ordered. SOQL query is enclosed between square brackets. For example,   Account a = [Select ID, Name from Account where Name=’acc1′];   In the above query “a” variable stores the ID, Name of the all accounts with a name “acc1”. For Parent-Child SOQL: I have Contact   as  a Parent object & Account as a Child object. for(Contact c : [select id,accountId from Contact where Contact.AccountId =: ' 0010K00001cqUdv ']){ for(Account ac : [select name,description from Account where id =: c.accountId

Role Hierarchies in Salesforce

Image
What is Role Hierarchy? A role hierarchy works together with sharing settings to determine the levels of access users have to your Salesforce data.  Users assigned to roles near the top of the hierarchy (normally the CEO, executives, and other management) get to access the data of all the users who fall directly below them in the hierarchy.  Each role in the hierarchy just represents a level of data access that a user or group of users needs. The role hierarchy enables these behaviors: A manager always has access to the same data as his or her employees, regardless of the org-wide default settings. Users who tend to need access to the same type of records can be grouped together. Depending on your sharing settings, roles can control the level of visibility that users have into your Salesforce data.   Create a Role Hierarchy: From Setup, use the Quick Find box to find  Roles . Just under the company name, click  Add Role . In the  Label  text box, enter  CEO. In th