Salesforce Certified Application Architect

Monday 30 December 2013

HTTP Success Codes : & REST API Headers

When a request is successful, the response header contains an HTTP code, and the
response body contains a Boolean success value.
200 : The request has been successfully processed.
201 : The request has been successfully processed and the
resource has been created.
204 : The request has been successfully processed, but no content
is returned in the response body. This code is returned after a
resource is successfully deleted.

HTTP Methods
REST API supports the following HTTP methods:
GET : Retrieves information, such as basic resource summary
information.
HEAD : Retrieves resource metadata.
PATCH:  Updates a record.
POST : Creates a new object.
DELETE : Deletes a record

=======================================================================
REST API Headers:
REST API supports the following headers:


Header Description Example:

Content-Type: Specifies whether the request is formatted as JSON or XML. Content-Type: application/json

Authorization :Used to authenticate the request. Authorization: OAuth sessionId
X-Pretty-Print Formats the response in a more readable format with line breaks and
indentation.

X-PrettyPrint:1: Formats the response in a more readable format with line breaks and
indentation.

Accept :Indicates the resource format which can be either JSON or XML. Accept: application/xml

X-Sfdc-PackageVersion : Specifies the package version under which context an API call is made. x-sfdc-packageversion-namespace: 2.0

REST HTTP Error Codes : Nice Points .

HTTP Error Codes:

When errors occur, the response header contains an HTTP code, and the response body
typically contains the error code, the message accompanying that error, and the field or
object where the error occurred.

300
The value used for an external ID exists in more than one
record. The response body contains the list of matching
records.

400
The request could not be understood, usually because the
JSON or XML body has an error.

401 The session ID or OAuth token used has expired or is invalid.
The response body contains the message and errorCode.

403 The request has been refused. Verify that the logged-in user
has appropriate permissions.

404 The requested resource could not be found. Check the URI for
errors, and verify that there are no sharing issues.

405 The method specified in the Request-Line is not allowed for
the resource specified in the URI.

415 The entity specified in the request is in a format that is not
supported by specified resource for the specified method.

500 An error has occurred within Force.com, so the request could
not be completed. Contact salesforce.com Customer Support.

CRUD (Create, Read, Update, Delete) – Force.com

Controls object-level security of data. These are standard sObject and field methods

isCreateable() Returns true if instances of this object can be created by
the current user, false otherwise.

isAccessible() Returns true if the current user can see instances of this
object type, false otherwise.

isUpdateable() Returns true if instances of this object can be updated by
the current user, false otherwise.

isDeleteable() Returns true if instances of this object can be deleted by
the current user, false otherwise.

Sharing Keywords – Force.com

Controls record-level security of data. These keywords are used in Apex class declarations.

with sharing : Operate with the calling user’s sharing rights.
Recommended.

without sharing : Operate without the calling user’s sharing rights.
Generally only
recommended for classes doing reporting or data
aggregation.

<unspecified sharing> : Inherit sharing from calling class. Not recommended for
Visualforce controllers or Web services.

Custom Setting Methods

Special objects and field methods that support a “protected” mode for storing sensitive
information like encryption keys.

getAll():  Returns a map of the data sets defined for the custom setting. List
custom settings only.

getInstance() : Returns the “lowest level” custom setting data set for the specified
dataset name, user ID, Profile ID, or current user (depending on
parameters and setting type). Identical to getValues() for List
custom settings.

getValues() : Returns only the custom setting data set for the specified dataset
name, user ID, Profile ID, or current user (depending on parameters
and setting type).

getOrgDefaults() : Returns the custom setting data set for the organization. Hierarchy
custom settings only.

Force.com Email Services Size Limitations

Apex Email Services – What are the different size limits for Email Services

There are a number of limits on what data and data sizes can be used for Email Services. This post will explain how some of these limits work.
The max email message size for a complete email message including attachments is 10MB
Emails which are below 10MB will be accepted by our mail server
Email which are above 10MB will be rejected and an email response sent back to the sender

There are two separate parts of an email body
Text Body of the email can max be 100KB
HTML body of the email can max be 100KB

There are 2 types of attachments which can be retrieved via Email Services, they are exposed as an array of text attachments and an array of binary attachments.
Text attachments can be 100KB each
Binary attachments can be up to 5MB per attachment

Attachments are presented to the Apex code of an Email Service in two different forms:
Attachments that are labeled as "text" are presented as an Apex String and can be a maximum of 100KB each. A "text" attachment is any attachment whose Mime type is "text/*". For example "text/plain", "text/html", etc.
Attachments that are not labeled as "text" are presented as an Apex Blob and can be up to 5MB per attachment.
When all the elements, text body, HTML body, text attachments and binary attachments are added together the total size of the email message has to be below 10MB
Attachments that are themselves an email are presented to the Apex code of an Email Service in two different forms:
The "raw" text of the entire embedded email, including all headers, Mime delimiters, Mime encoded attachments, etc. is presented to your Apex code in the binary attachments list as a Blob. This attachment has a Mime type of "message/rfc822". Often attachments of this Mime type can be discarded by the Email Service.
Attachments to the embedded email are "pulled out" and stored in the text and binary attachment lists of the main email as if they had been directly attached.
If the message size limit is reached, a bounced notification email will be sent back to the sender, showing that the message size is above the acceptable limit we have in place.

Why Get Salesforce.Com Certified?

Earning a credential from salesforce.com demonstrates that you have skills and confidence. Keeping that certification up-to-date shows that you're schooled on the latest technologies.
  • Certified Salesforce developers are sought after like never before. There's been 159% growth in demand for Salesforce talent since 2008 (Hire On-Demand 2012).
  • Since many companies search specifically for credentials, getting certified can open doors in your career and allow you to compete for more complex projects.
  • Companies who use certified cloud developers have smoother deployments which allows you to build customer confidence.
  • Maintaining your certification ensures that you are on top of new Salesforce functionality as it rolls out 3x per year.

Developer Certification Study Guide

Using Certificates with SOAP Services

TestSample.TestSamplePort stub = new TestSample.TestSamplePort ();

stub.clientCert_x =
'MIIGlgIBAzCCBlAGCSqGSIb3DQEHAaCCBkEEggY9MIIGOTCCAe4GCSqGSIb3DQEHAaCCAd8EggHb'+
'MIIB1zCCAdMGCyqGSIb3DQEMCgECoIIBgjCCAX4wKAYKKoZIhvcNAQwBAzAaBBSaUMlXnxjzpfdu'+
'6YFwZgJFMklDWFyvCnQeuZpN2E+Rb4rf9MkJ6FsmPDA9MCEwCQYFKw4DAhoFAAQU4ZKBfaXcN45w'+
'9hYm215CcA4n4d0EFJL8jr68wwKwFsVckbjyBz/zYHO6AgIEAA==';

// Password for the keystore
stub.clientCertPasswd_x = 'passwd';

String input = 'This is the input string';
String output = stub.EchoString(input);

Upsert Statement..

The upsert DML operation creates new sObject records and updates existing sObject records within a single statement, using an optional custom field to determine the presence of existing objects.


This example performs an upsert of a list of accounts.
List<Account> acctList = new List<Account>();
// Fill the accounts list with some accounts

try {
    upsert acctList;
} catch (DmlException e) {
   
}
This next example performs an upsert of a list of accounts using a foreign key for matching existing records, if any.

List<Account> acctList = new List<Account>();
// Fill the accounts list with some accounts

try {
    // Upsert using an external ID field
    upsert acctList myExtIDField__c;
} catch (DmlException e) {
   
}

Apex Trigger Tip: Using One Trigger Per Object To Control Logic.

 How you can control the order of execution on trigger logic when you have multiple Apex triggers operating on the same object and event.  So if you have “UpdateAccountWithCase” and “UpdateAccountAfterOpportunity” as two examples, how do you know your Account will be updated with case related information before the opportunity data?
The answer is you don’t – at least not if you’ve got triggers separated out into multiple classes for a single object.  For this reason, and a few others, I’ve seen many companies utilize one trigger per data object that simply controls the flow of logic while calling the execution in other classes.  So instead of:
trigger UpdateAccountWithCase on Account (before insert, before update) {
/* execution logic */
}
trigger UpdateAccountAfterOpportunity on Account (before insert, before update) {
/* execution logic */
}
You would have one trigger, which examines the incoming event and hands off the relevant data to other classes:
trigger AccountTrigger (before insert, before update) {
if(Trigger.isBefore && Trigger.isInsert) {
UpdateAccountWithCase.handleAccount(Trigger.new);
UpdateAccountAfterOpportunity.handleAccount(Trigger.new);
}
}

Sunday 29 December 2013

Apex Callouts :

Whereas Apex Web Services allows an external application to invoke Apex methods through web services, Apex Callouts enable Apex to invoke external web services. This allows you to connect to 3rd party web services such as Google, Amazon, Facebook, and any other external web service.
There are two main ways to develop callouts with Apex: (a) Import a WSDL into Apex (b) HTTP (RESTful) Services classes.

Action Methods

Action methods perform logic or navigation when a page event occurs, such as when a user clicks a button, or hovers over an area of the page. Action methods can be called from page markup by using {! } notation in the action parameter of one of the following tags:

Using the Report Tab:

You can:

• Create reports or dashboards
• Access standard reports
• Organize and share items in folders
• Move items between folders
• Customize the list view
• Search and filter items
• Manage reports and dashboards
• Schedule and follow items



Uses of API & When To Use:

When to Use REST API

REST API provides a powerful, convenient, and simple REST-based Web services interface for interacting with Salesforce. Its advantages include ease of integration and development, and it’s an excellent choice of technology for use with mobile applications and Web projects. However, if you have a large number of records to process, you may wish to use Bulk API, which is based on REST principles and optimized for large sets of data.

When to Use SOAP API

SOAP API provides a powerful, convenient, and simple SOAP-based Web services interface for interacting with Salesforce. You can use SOAP API to create, retrieve, update, or delete records. You can also use SOAP API to perform searches and much more. UseSOAP API in any language that supports Web services.
For example, you can use SOAP API to integrate Salesforce with your organization’s ERP and finance systems, deliver real-time sales and support information to company portals, and populate critical business systems with customer information.

When to Use Chatter REST API

Chatter REST API provides programmatic access to Chatter feeds and social data such as users, groups, followers, and files. UseChatter REST API to integrate Chatter into a variety of applications such as mobile applications, intranet sites, and third-party Web applications. Chatter REST API is similar to APIs offered by other companies with feeds, such as Facebook and Twitter.

When to Use Bulk API

Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. You can use it to query, insert, update, upsert, or delete a large number of records asynchronously by submitting batches which are processed in the background by Salesforce.
SOAP API, in contrast, is optimized for real-time client applications that update small numbers of records at a time. Although SOAP API can also be used for processing large numbers of records, when the data sets contain hundreds of thousands of records, it becomes less practical. Bulk API is designed to make it simple to process data from a few thousand to millions of records.
The easiest way to use Bulk API is to enable it for processing records in Data Loader using CSV files. This avoids the need to write your own client application.

When to Use Metadata API

Use Metadata API to retrieve, deploy, create, update, or delete customizations for your organization. The most common use is to migrate changes from a sandbox or testing organization to your production environment. Metadata API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself.
The easiest way to access the functionality in Metadata API is to use the Force.com IDE or Force.com Migration Tool. These tools are built on top of Metadata API and use the standard Eclipse and Ant tools respectively to simplify the task of working with Metadata API. Built on the Eclipse platform, the Force.com IDE provides a comfortable environment for programmers familiar with integrated development environments, allowing you to code, compile, test, and deploy all from within the IDE itself. The Force.com Migration Tool is ideal if you want to use a script or a command-line utility for moving metadata between a local directory and a Salesforceorganization.

When to Use Streaming API

Use Streaming API to receive notifications for changes to data that match a SOQL query that you define.
Streaming API is useful when you want notifications to be pushed from the server to the client. Consider Streaming API for applications that poll frequently. Applications that have constant polling action against the Salesforce infrastructure, consuming unnecessary API call and processing time, would benefit from this API which reduces the number of requests that return no data.Streaming API is also ideal for applications that require general notification of data changes. This enables you to reduce the number of API calls and improve performance.

When to Use Apex REST API

Use Apex REST API when you want to expose your Apex classes and methods so that external applications can access your code through REST architecture. Apex REST API supports both OAuth 2.0 and Session ID for authorization.

When to Use Apex SOAP API

Use Apex SOAP API when you want to expose your Apex methods as SOAP Web service APIs so that external applications can access your code through SOAP. Apex SOAP API supports both OAuth 2.0 and Session ID for authorization.

When to Use Tooling API

Use Tooling API when you want to manage and deploy working copies of Apex classes and triggers and Visualforce pages and components, set checkpoints or heap dump markers, execute anonymous Apex, and access logging and code coverage information.

Which API Should I Use?

Salesforce provides programmatic access to your organization’s information using simple, powerful, and secure application programming interfaces.

API NameWhat It’s ForWhen to Use ItProtocolData FormatCommunication
REST APIAccessing objects in your organization using REST.You want to leverage the REST architecture to integrate with your organization. No WSDL requirement.
Well-suited for browser-based applications, mobile apps, and highly-interactive social applications.
RESTJSON, XMLSynchronous
SOAP APIIntegrating your organization’s data with other applications using SOAP.You have pre-existing middleware services that need to work with WSDLs and XML data.SOAP/WSDLXMLSynchronous
Chatter REST APIAccessing Chatter feeds and social data such as users, groups, followers, and files using REST.You want to integrateChatter into a variety of applications, such as mobile apps, intranet sites, and third-party Web applications.RESTJSON, XMLSynchronous (photos are processed asynchronously)
Bulk APILoading or deleting large numbers of records.You have over a million records to process and speed is a requirement.RESTCSV, XMLAsynchronous
Metadata APIManaging customizations in your organization and building tools that can manage the metadata model, not the data itself.You want to migrate changes, such as custom object definitions and page layouts, from asandbox to your production environment.SOAP/WSDLXMLAsynchronous
Streaming APIProviding a stream of data reflecting data changes in your organization.You need near real-time notifications of when records are created or updated.BayeuxJSONAsynchronous (stream of data)
Apex REST APIBuilding your own REST API in Apex. ExposesApex classes as RESTful Web services.You need to build custom JSON responses or you want to expose custom functionality that you implemented in Apex.RESTJSON, XML, CustomSynchronous
Apex SOAP APICreating custom SOAP Web services in Apex. Exposes Apex classes as SOAP Web services.You need to build custom XML responses or you want to expose custom functionality that you implemented in Apex .SOAP/WSDLXMLSynchronous
Tooling APIBuilding custom development tools forForce.com applications.You want to add functionality to your existing development and integration tools or you want to build specialized development tools for a specific application or service.REST and SOAPJSON, XML, CustomAsynchronous

Standard Interfaces (Subset):

Database.Batchable :

global (Database.QueryLocator | Iterable<sObject>)
 start(Database.BatchableContext bc) {}
global void execute(Database.BatchableContext BC, list<P>){}
global void finish(Database.BatchableContext BC){}

Schedulable:

global void execute(ScheduleableContext SC) {}

Messaging.InboundEmailHandler:

global Messaging.InboundEmailResult handleInboundEmail(Messaging.
inboundEmail email, Messaging.InboundEnvelope env){}

Comparable:
global Integer compareTo(Object compareTo) {}

Annotations

Annotation                                         Description                                                                 Example

@isTest :

Denotes classes that only 
contain code used for 
testing your application. 
These classes don’t count 
against the total amount 
of Apex used by your 
organization. 

@isTest private class MyTest {
 // Methods for testing 
}

@isTest(
OnInstall=true):

Denotes a test class or 
test method that executes 
on package installation

@isTest(OnInstall=true)
private class TestClass {

@isTest(
SeeAllData=true):

Denotes a test class or 
test method that has access
to all data in the organization
including pre-existing data
that the test didnt create.
The default is false


@isTest(SeeAllData=true)
private class TestClass {
}

@deprecated :

Denotes methods, classes, 
exceptions, enums, 
interfaces, or variables 
that can no longer be 
referenced in subsequent 
releases of the managed 
package in which they 
reside

@deprecated
public void limitedShelfLife() {
}

@readOnly :

Denotes methods that 
can perform queries 
unrestricted by the number 
of returned rows limit for a 
request

@readOnly:

private void doQuery() {
}

@remoteAction :

Denotes Apex controller 
methods that JavaScript 
code can call from a 
Visualforce page via 
JavaScript remoting. The 
method must be static and 
either public or global.

@remoteAction:
global static String getId(
 String s) {
}

@restResource :

Denotes a class that 
is available as a REST 
resource. The class must 
be global. The urlMapping 
parameter is your 
resource's name and is 
relative to https://instance.
salesforce.com/services/
apexrest/.

@restResource(urlMapping=
'/Widget/*')

global with sharing class
 MyResource() {
}

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...