Monday, July 27, 2015

SalesForce Release Updates in 15 for Administrators & Developers

Hi Friends,

Today I am sharing some of the main SalesForce Release Updates in 15 for Administrators & Developers:

Administrative Changes:
---------------------------------

1.) Number of Custom Profiles Allowed:
To ensure better performance, your organization can have up to 1,500 custom profiles per user license type. If your organization has
too many custom profiles, consider using permission sets to grant additional permissions and access settings to the users who need
them.

2.) End of Support for JavaScript, iFrames, CSS, and Other Advanced Markup in HTML Area Home Page Components:
We are now enforcing the ban on unsupported code in HTML Area home page components. JavaScript, CSS, iframes, and other
unsupported markup is now removed when you edit and save an HTML Area home page component. A cleaned version is saved,
and all unsupported content is lost.

3.) Administrators Can Log in as Any User

4.) There are many changes in Process Builder like Reference System-Provided Values, After you deactivate a process, you no longer have to wait 12 hours before you delete it and improved the Process Builder user interface so it’s easier to manage versions, find and reference fields, create Chatter messages and more.

5.) There are many changes in Visual WorkFlow like Verify Picklist Values in a Flow, Verify Multi-Select Picklist Values in a Flow, After you deactivate a process, you no longer have to wait 12 hours before you delete it, Reference Global Variables in a Flow.

6.) Access Data Across Multiple Organizations with the Lightning Connect Salesforce Connector

Developer Console Changes:
--------------------------------------

1.) Work with Lightning Resources in the Developer Console: To create Lightning resources, you must use a Developer Edition organization that has a namespace prefix.

Visualforce Changes:
-----------------------------

1.) Add Data Access to Your Visualforce Pages with Remote Objects (Generally Available)


-  in: in, used for finding a value that matches any of a set of fixed values. Provide values as an array, for example, ['Benioff', 'Jobs', 'Gates'].

- nin: not in, used for finding a value that matches none of a set of fixed values. Provide values as an array, for example, ['Benioff', 'Jobs', 'Gates'].

- Here’s a query definition that searches for records that match any of several last names.

{
where:
{
LastName: { in: ['Benioff', 'Jobs', 'Gates'] }
}
}

2.) Customize Visualforce Maps with Custom Markers

icon="{! URLFOR($Resource.MapMarkers, 'moderntower.png') }" />

3.) Enrich Visualforce Maps with Info Windows:

4.) Accessibility: “*” Annotation in Labels for Required Fields Restored

5.) PageReference getContent() and getContentAsPDF() Methods Behave as Callouts

Apex Code Changes:
----------------------------

1.) Submit and Monitor Jobs for Asynchronous Execution with the Queueable Interface:

Getting an ID for your job: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the new job. This ID corresponds to the ID of the AsyncApexJob record. You can use this ID to identify your job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.

Chaining jobs: You can chain one job to another by starting a second job from a running job. Chaining jobs is useful if you need to do some processing that depends on another process to have run first.

Example
This example is an implementation of the Queueable interface. The execute method in this example inserts a new account.

public class AsyncExecutionExample implements Queueable {
public void execute(QueueableContext context) {
Account a = new Account(Name='Acme',Phone='(415) 555-1212');
insert a;
}
}

To add this class as a job on the queue, call this method:
ID jobID = System.enqueueJob(new AsyncExecutionExample());

AsyncApexJob jobInfo = [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE Id=:jobID];

Testing Queueable Jobs:

@isTest
public class AsyncExecutionExampleTest {
static testmethod void test1() {
// startTest/stopTest block to force async processes
// to run in the test.
Test.startTest();
System.enqueueJob(new AsyncExecutionExample());
Test.stopTest();
// Validate that the job has run
// by verifying that the record was created.
// This query returns only the account created in test context by the
// Queueable class method.
Account acct = [SELECT Name,Phone FROM Account WHERE Name='Acme' LIMIT 1];
System.assertNotEquals(null, acct);
System.assertEquals('(415) 555-1212', acct.Phone);
}
}

Note: The ID of a queueable Apex job isn’t returned in test context—System.enqueueJob returns null in a running test.

Chaining Jobs:

public class AsyncExecutionExample implements Queueable {
public void execute(QueueableContext context) {
// Your processing logic here
// Chain this job to next job by submitting the next job
System.enqueueJob(new SecondJob());
}
}

Queueable Apex Limits:

• The execution of a queued job counts once against the shared limit for asynchronous Apex method executions.
• You can add up to 50 jobs to the queue with System.enqueueJob in a single transaction.
• The maximum stack depth for chained jobs is two, which means that you can link a job only once and have a maximum of two jobs in the chain.
• When chaining jobs, you can add only one job from an executing job with System.enqueueJob.

Run More Future Methods and Callouts:

- The execution limits of future methods and callouts in an Apex transaction have increased to 50 methods and 100 callouts respectively. These limit increases enable you to do more with Apex without having to be restricted by the previous limits. For example, you might have transferred much of your long-running code to future methods that you call and run asynchronously from your main class. If you did many of these future calls in your class, you might have hit the limit of 10 future calls in one transaction. With the increased limit of 50 calls, you can make many more future calls without likely hitting this limit.

The following limits have increased.
Maximum number of methods with the future annotation allowed per Apex invocation changed From 10 To 50

Maximum number of callouts (HTTP requests or Web services calls) in a transaction changed From 10 To 100

Run More Tests in Sandbox and Developer Organizations:

The test execution limit for asynchronous tests has increased and you can now run twice as many tests in large sandbox or Developer Edition organizations.
For sandbox and Developer Edition organizations, the following test execution limit for asynchronous tests has increased.

Maximum number of test classes that can be queued per 24-hour period is changed to the greater of 500 or 20 multiplied by the number of test classes in the organization

There are some changes in Apex Trigger and Apex Support for some standard objects
There are some updates in some Methods and Properties and Added New Classes and Methods too

Refer Page: 257 in "SalesForce Winter-15 Release Notes" PDF for the Trigger and Apex Support for New Object & List of Added Classes and Methods and Updates

In Summer-15 Release Notes: Apex Changes:
1.) New Code Coverage Calculation for Multiline Statements
2.) Iteration Order for Maps and Sets Is Now Predictable
3.) Receive Debug Logs Predictably
4.) Location and Distance Variables Allowed in SOQL and SOSL Queries in Apex
5.) Reduced Access for Apex Classes Using with sharing Keyword
6.) See Apex Method Parameters at a Glance

Lightning Changes:
--------------------------

Force.com Canvas Apps Don’t Work in Salesforce1 if Lightning Components are Enabled
You can’t use Force.com Canvas apps in Salesforce1 if you enable Lightning components. Any Force.com Canvas apps in your organization will no longer work in Salesforce1 if you enable Lightning components.

Limited Set of Out-of-the-Box Components: The beta includes a very limited set of components.
Namespace Prefix Required: Your organization must have a namespace prefix required to develop Lightning components.

Open Source Aura Framework

The Lightning Component framework is built on the open source Aura framework. Aura is open sourced at https://github.com/forcedotcom/aura. You can build general-purpose Web apps hosted on your own server. Your apps can be completely independent of Salesforce and your data in Salesforce.

Note that the open source Aura framework has features and components that are not currently available in the Lightning Component framework. We are working to surface more of these features and components for Salesforce developers.

Person Accounts Are Now Packagable in managed and unmanaged packages.

1.) Standalone Lightning Apps (Generally Available)
2.) Some Changes in Lightning Components and Events, you could refer for the list to "SalesForce Summer-15 Release Notes" PDF

Thanks,

Amit Goyal

Friday, July 24, 2015

Automatically Submit Multiple Records to Approval through Apex

Hi Friends,

Today I am sharing one code snippet with you to automatically submit multiple records to approval process through apex.

Firstly you need to setup the approval process on which object you want to submit the records for Approval.

Than through your Apex Controller or Trigger you could process the records and send that for Approval.

//Create a List of Approval.ProcessSubmitRequest
List requests = new List();

// Process your List on which you need to send the records for Approval, It could be direct list or you could process the list from you inner query or whatever list you want to process, In my example I have used the list of Opportunity from a trigger:

for(Opportunity opp: Trigger.New){
// Create a instance of Approval.ProcessSubmitRequest to add that to the list initialized above
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();

// Set the comment you want to add
req.setComments('Submitting request for approval');

// Set the object-id in the Approval.ProcessSubmitRequest instance
req.setObjectId(opp.Id);

//Add the instance to the list initialized above, before the for loop
requests.add(req);
}

// We need to capture the result of the approval, so initialize a list of Approval.ProcessResult
Approval.ProcessResult[] processResults = null;

// Apply Exception Handliing
try {
// The command Approval.process will submit all your record for Approval
processResults = Approval.process(requests);
}catch (System.DmlException e) {
System.debug('Exception Is ' + e.getMessage());
}

Point to Notice:
Sometimes our trigger doesn't submit our records for approval, so that time we need to check, whatever records we are submitting for Approval through our code, are they meeting the entry-level criteria successfully which we have defined in our approval process, so we have to apply the conditions and have to test it carefully.

You could ask me for any topic or any help if you need something specific, I will be happy to help you.

Thanks,

Amit Goyal