affiliate_link

Sunday, May 18, 2014

SOQL and SOSL Queries - Apex

The same way database systems support a query language for data retrieval, the Force.com peristence layer also provides two query languages.
  • Salesforce Object Query Language (SOQL) is a query-only language. While similar to SQL in some ways, it's an object query language that uses relationships, not joins, for a more intuitive navigation of data. This is the main query language that is used for data retrieval of a single sOobject and its related sObjects. You'll see an example in a minute.
  • Salesforce Object Search Language (SOSL) is a simple language for searching across all multiple persisted objects simultaneously. SOSL is similar to Apache Lucene.
You can write queries directly in Apex without much additional code since Apex is tightly integrated with the database.

SOQL QUERY EXAMPLES

A SOQL query is enclosed between square brackets. This example retrieves an sObject (a record from the database) that has the name field value equal to ‘Pencils’:
sObject s = [SELECT Id, Name FROM Merchandise__c WHERE Name='Pencils'];
This next example retrieves all matching merchandise items, assuming that there are zero or more merchandise items, and assigns them to a list. It shows how you can include a variable in a SOQL query by preceding it with a colon (:).
String myName = 'Pencils';
Merchandise__c[] ms = [SELECT Id FROM Merchandise__c WHERE Name=:myName];
Execute the following code to retrieve the first matching merchandise item and assign its Total_Inventory__c field to a variable:
Double totalInventory = [SELECT Total_Inventory__c 
                         FROM Merchandise__c 
                         WHERE Name = 'Pencils'][0].Total_Inventory__c;
System.debug('Total inventory: ' + totalInventory);
This is what you’ll get in the output.
Total inventory: 1000.0

SOSL QUERY EXAMPLE

SOSL statements evaluate to a list of lists of sObjects, where each list contains the search results for a particular sObject type. Here's an example that searches all field across all Merchandise__c and Inventory_Statement__c sObjects. Execute the following:
List<List<SObject>> searchList = [FIND 'Pencil*' IN ALL FIELDS RETURNING 
                                  Merchandise__c (Id, Name), Invoice_Statement__c];
Merchandise__c[] merList = ((List<Merchandise__c>)searchList[0]);
Invoice_Statement__c[] invList = ((List<Invoice_Statement__c>)searchList[1]);
System.debug('Found ' + merList.size() + ' merchandise items.');
System.debug('Found ' + invList.size() + ' invoice statements.');
You’ll get something similar to this in the output.
Found 1 merchandise items.
Found 0 invoice statements.
 
Reference: http://salesforceonlinetrainings.blogspot.com/2012/08/soql-and-sosl-queries.html

What is Scrum?


Scrum is an iterative and incremental agile software development framework for managing software projects and product or application development. It defines "a flexible, holistic product development strategy where a development team works as a unit to reach a common goal". It challenges assumptions of the "traditional, sequential approach" to product development. Scrum enables teams to self-organize by encouraging physical co-location or close online collaboration of all team members and daily face to face communication among all team members and disciplines in the project.

Reference: http://en.wikipedia.org/wiki/Scrum_%28software_development%29

Salesforce Enterprise vs Partner Web Services

  • Enterprise Web Services WSDL—Used by enterprise developers to build client applications for a single Salesforce organization. The enterprise WSDL is strongly typed, which means that it contains objects and fields with specific data types, such as int and string. Customers who use the enterprise WSDL document must download and re-consume it whenever their organization makes a change to its custom objects or fields or whenever they want to use a different version of the API. 
  •  Partner Web Services WSDL—Used for client applications that are metadata-driven and dynamic in nature. It is particularly—but not exclusively—useful to salesforce.com partners who are building client applications for multiple organizations. As a loosely typed representation of the Salesforce data model that works with name-value pairs of field names and values instead of specific data types, it can be used to access data within any organization. This WSDL is most appropriate for developers of clients that can issue a query call to get information about an object before the client acts on the object. The partner WSDL document only needs to be downloaded and consumed once per version of the API. 

Ajax vs Query

AJAX is a technique to do an XMLHttpRequest (out of band Http request) from a web page to the server and send/retrieve data to be used on the web page. AJAX stands for Asynchronous Javascript And XML. It uses javascript to construct an XMLHttpRequest, typically using different techniques on various browsers.

According to Wikipedia
Ajax (Asynchronous JavaScript and XML)[1] is a group of interrelated Web development techniques used on the client-side to create asynchronous Web applications. With Ajax, Web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required; JSON is often used instead (see AJAJ), and the requests do not need to be asynchronous.[2]
Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and allow the user to interact with, the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.
Ref: http://en.wikipedia.org/wiki/Ajax_(programming)

jQuery (website) is a javascript framework that makes working with the DOM easier by building lots of high level functionality that can be used to search and interact with the DOM. Part of the functionality of jQuery implements a high-level interface to do AJAX requests. jQuery implements this interface abstractly, shielding the developer from the complexity of multi-browser support in making the request.

SOAP vs REST Webservices

SOAP (Simple Object Access Protocol) and REST (Representational State Transfer) both are used as interfaces to the Web Services.

REST Advantages
1. Limited Bandwidth and Resources
2. Totally Stateless Operations
3. Caching Issues

SOAP Advantages
1. Reliable Messaging (SOAP 1.2 offers additional reliability and security)
2. Formal Contracts (Both provider and consumer have to agree on the exchange format)
3. Stateful Operations (Security, Transaction, Coordination)

Sunday, May 11, 2014

Htaccess tips

1. Make all your files extension .htm instead of .php

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\.htm$ /$1.php [NC,L] 

2. Remove file extensions. for example www.website.com/page.php will show as www.website.com/page

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]

3. Force File Download
Instead of opening files in the web browser it forces these files types to download

<FilesMatch "\.(mov|mp3|jpg|pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>




Reference: http://wiki.dreamhost.com/Htaccess_tricks