Cloning

Clone
DeepClone
If a list is cloned, it duplicates it and has reference.
If a list is DeepCloned, it duplicates and doesn’t have any reference.
Primitive data types are supported.
Primitive data types are not supported.
Parameters:
Not applicable
Parameters:
Boolean opt_preserve_id – Whether cloned sObjects records ids are maintained.

Boolean opt_preserve_readonly_timestamps– Whether cloned sObjects records read only system fields like createdDate, LastModifiedDtate, etc are   maintained.

Boolean opt_preserve_autonumbe– Whether cloned sObjects records auto number fields are maintained.
Sample Code:
Account Account1= new Account(Name='Test1');
Account Account2= new Account(Name='Test2');
List<Account> AccountList = new List<Account>{Account1, Account2};

List<Account> listDuplicate = new List<Account>();
listDuplicate = AccountList.clone();

AccountList.get(0).Name = 'Testing1';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);

Now AccountList.get(0).Name and listDuplicate get(0).Name will be ‘Testing1’.

listDuplicate.get(0).Name = 'Testing2';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);

Now AccountList.get(0).Name and listDuplicate get(0).Name will be ‘Testing2’.
Sample Code:
Account Account1= new Account(Name='Test1');
Account Account2= new Account(Name='Test2');
List<Account> AccountList = new List<Account>{Account1, Account2};

List<Account> listDuplicate = new List<Account>();
listDuplicate = AccountList.deepClone();

AccountList.get(0).Name = 'Testing1';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);

Now AccountList.get(0).Name will be ‘Testing1’ and listDuplicate get(0).Name will be ‘Test1’.

listDuplicate.get(0).Name = 'Testing2';
system.debug(AccountList.get(0).Name + ',' + listDuplicate.get(0).Name);

Now AccountList.get(0).Name will be ‘Testing1’ and listDuplicate get(0).Name will be ‘Testing2’.

Synchronous and Asynchronous Calls with the AJAX Toolkit

AJAX Toolkit allows to issue synchronous or asynchronous calls. Asynchronous calls allow the client side process to continue, waiting for a call back from the server. To issue an asynchronous call, you must include an additional parameter with the API call, referred to as a callback function. Once the result is ready, the server invokes the callback method with the result.


Synchronous syntax:

sforce.connection.method("arg1","arg2", ...);
e.g:
sforce.connection.login("MyName@MyOrg.com","myPassword1");
 
Asynchronous syntax:

method("arg1","arg2", ..., callback_method);
For example:

var callback = {onSuccess: handleSuccess, onFailure: handleFailure};
function handleSuccess(result) {}
function handleFailure(error) {}
sforce.connection.query("Select name from Account", callback);

Field Dependency

A dependent relationship that causes the values in a picklist or multi-select picklist to be dynamically filtered based on the value selected by the user in another field.
  1.  • The field that drives filtering is called the "controlling field." Standard and custom checkboxes and picklists (Multi-select picklist not allowed) with at least one and less than 300 values can be controlling fields. 
  2.  • The field that has its values filtered is called the "dependent field." Custom picklists and multi-select picklists can be dependent fields. 

 

Basic HTTP access Authentication :

HTTP Basic Auth (or Basic access authentication) is a widely used protocol for simple username/password authentication.

Warning! Please note that when using Basic auth, your password is being sent to the server, and therefore this should be considered safe only over HTTPS.

Client side:

When the user agent wants to send the server authentication credentials it may use the Authorization field.

The Authorization field is constructed as follows:

  1. The username and password are combined with a single colon.
  2. The resulting string is encoded using the RFC2045-MIME variant of Base64, except not limited to 76 char/line.
  3. The authorization method and a space i.e. "Basic " is then put before the encoded string.

For example, if the user agent uses Aladdin as the username and OpenSesame as the password then the field is formed as follows:

 Aladdin:OpenSesame | base64  

.. yields a string 'QWxhZGRpbjpPcGVuU2VzYW1l' that is used like so:

Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l

-----------------------------------------------------------------

Server side:

When the server wants the user agent to authenticate itself towards the server, it must respond appropriately to unauthenticated requests.

Unauthenticated requests should return a response whose header contains a HTTP 401 Unauthorized status and a WWW-Authenticate field.[5]

The WWW-Authenticate field for basic authentication (used most often) is constructed as following:

WWW-Authenticate: Basic realm="User Visible Realm"

See more...

What is governor limit in salesforce?

Governor limit are run time limits/exceptions enforced by the apex runtime.Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources.


  1. Per-Transaction Apex Limits
  2. Per-Transaction Certified Managed Package Limits
  3. Force.com Platform Apex Limits
  4. Static Apex Limits
  5. Size-Specific Apex Limits
  6. Miscellaneous Apex Limits
  7. Push Notification Limits



function to show dialog/popup box using script

function showSimpleDialog()

var sd = new SimpleDialog("Test"+Dialogs.getNextId(), false); 
var rurl = '/{!Contact.Id}/e?retURL=%2F{!Contact.Id}&RecordType=01261000000Xnij&00N6100000DOeVX=Active'; 

sd.setTitle("Alert"); 
sd.createDialog(); 
window.parent.sd = sd; 
sd.setContentInnerHTML("<form action="+rurl+" method='POST'><p align='center'><img src='/img/msg_icons/warning32.png' style='margin:0 5px;'/></p><p align='center'>The related contact must have an active campaign response.Please add a response and afterwards,update the contact status to 'completed' before creating the opportunity.</p><p align='center'><button class='btn' onclick='window.parent.sd.hide(); return false;'>Cancel</button></p></form>"); 
sd.show(); 
}





 Sent with Mailtrack

Setting Read-Only Mode for Controller Methods

Visualforce controller methods can, with some important limitations, use the Apex ReadOnly annotation, even if the page itself isn't in read-only mode.
Visualforce controller methods with the @ReadOnly annotation automatically take advantage of read-only mode. However, restrictions on the @ReadOnly annotation means that, for Visualforce controller methods, a read-only method must also have the @RemoteAction annotation. The @RemoteAction annotation requires that the method be:
  • Either global or public
  • static

Enabling read-only mode by using the @ReadOnly annotation must be done on the top level method call. If the top level method call doesn't have the@ReadOnly annotation, the normal restrictions on maximum queried rows are enforced for the entire request, even if secondary methods are annotated with @ReadOnly.

Using the @ReadOnly annotation on a controller method allows you to retrieve a larger collection of records as the result of a Visualforce expression. However, it doesn't increase the maximum number of items in a collection for iteration components. If you want to iterate over larger collections of results, you need to enable read-only mode for the entire page.

ReadOnly Annotation

The @ReadOnly annotation allows you to perform unrestricted queries against the Force.com database. All other limits still apply. It's important to note that this annotation, while removing the limit of the number of returned rows for a request, blocks you from performing the following operations within the request: DML operations, calls to System.schedule, calls to methods annotated with @future, and sending emails.

The @ReadOnly annotation is available for Web services and the Schedulable interface. To use the @ReadOnly annotation, the top level request must be in the schedule execution or the Web service invocation. For example, if a Visualforce page calls a Web service that contains the @ReadOnly annotation, the request fails because Visualforce is the top level request, not the Web service.

Visualforce pages can call controller methods with the @ReadOnly annotation, and those methods will run with the same relaxed restrictions.

Collection Size Error when accessing Visualforce page

Visualforce is not designed to display more than 1000 records on the same page. Generally speaking, if your SOQL's are returning more than 1000 records and you attempt to display these records on a VF page, you will receive this error.

You can implement two solutions for this issue:

1- You can either limit the number of records you are trying to display to be less than 1000 or use pagination to display the records in different pages

2- You can use the @ReadOnly annotation on the method that retrieves the records or on the entire visualforce page. You can find more information about this here.

Deleting Files from an Organization

The package.xml file is a project manifest that lists all the components to retrieve or deploy. Although you can use package.xml to add components, it’s not sufficient to delete them. 
To delete files, create a delete manifest that’s called destructiveChanges.xml. The format of the delete manifest is the same as package.xml, except that wildcards aren’t supported

The following sample destructiveChanges.xml file names a single custom object to be deleted:
1<?xml version="1.0" encoding="UTF-8"?>
3    <types>
4        <members>MyCustomObject__c</members>
5        <name>CustomObject</name>
6    </types>
7</Package>
To deploy the destructive changes, you must also have a package.xml file that lists no components to deploy, includes the API version, and is in the same directory as destructiveChanges.xml:
1<?xml version="1.0" encoding="UTF-8"?>
3    <version>38.0</version>
4</Package>
Note
  • To bypass the Recycle Bin, set the purgeOnDelete option to true.
  • If you try to delete some components that don’t exist in the organization, the rest of the deletions are still attempted.

Counters