Ads

Friday 14 February 2014

Dev 401 Winter 14 Release Questions?

1. What is a capability of historical trending? Choose 2 answers
a. Historical trending can track number, formula, and checkbox fields.
b. Historical trending reports show changed values in different colors.
c. Historical trending can be enabled for all standard and custom objects.
d. Historical trending reports can be filtered to show only records that have changed.

      ANS: B, D

2. What is a capability of embedded analytics?  Choose 2 answers
a. An embedded chart can be filtered to show data for the record on which it appears.
b. Report charts can be used to show data from tabular, summary, and joined reports.
c. An embedded chart can be used to share report data from a personal folder.
d. Report charts can be embedded on page layouts for standard and custom objects.

     ANS:  A, D

3. What is a capability of Salesforce Identity? Choose 2 answers
a. Require users to enter a time-based token in addition to login credentials when accessing Salesforce.
b. Require users to have a High Assurance session to access Reports, Dashboards, and Connected Apps.
c. Require users to use a time-based token when logging into Salesforce outside the trusted IP ranges.
d. Require users to have a High Assurance session to edit, modify, or delete selected objects.
   
    ANS:  A, D


4. How can an administrator or developer restrict users from seeing other users in the organization?
a. Set the organization-wide default for the User object to Private.
b. Create a sharing rule to prevent users from seeing other users.
c. Enable the "Restrict Access to Users" permission for all users.
d. Disable manual sharing for the User object

      ANS: A

5. What is a capability of site.com? Choose 3 answers
a. View the site in different resolutions using live mode.
b. Use workflow rules to automate site publishing.
c. Export the style sheet from a site.
d. Create version of the site in multiple languages.
e. Import existing HTML pages into a site.

      ANS: A, D, E

Tuesday 17 September 2013

Using static resource Dynamically in Salesforce?

Let’s suppose we have an archive in static resource with name “Contact” and you want to use this static resource on a page that displays Contact Photos dynamically. Assumption is that the images are stored with same name as product codes.
Code:

//Declare an apex variable which gets the Contact code from an apex property
<apex:variable var="contact_photo" value="{!contactPhoto}.jpg"/>
<img src="{!URLFOR($Resource.Products,contact_photo)}')" alt="" />

Email Services in Salesforce?

Email services are automated processes that use the Apex classes to process the contents, headers, and attachments of inbound email.
For example, you can create an email service that automatically creates contact records based on contact information in messages. Each email service has one or more email service addresses that can receive messages for processing.
To use the email services, click Your Name ➤ Setup ➤ Develop ➤ Email Services.
Given below email service class inserts Contact which is declare in setting of Email Services.

Class for Email Services:
global class ProcessJobApplicantEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    Contact contact = new Contact();
    contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' '));
    contact.LastName = email.fromname.substring(email.fromname.indexOf(' '));
    contact.Email = envelope.fromAddress;
    insert contact;

    System.debug('====> Created contact '+contact.Id);

    if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
      for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
        Attachment attachment = new Attachment();
        // attach to the newly created contact record
        attachment.ParentId = contact.Id;
        attachment.Name = email.binaryAttachments[i].filename;
        attachment.Body = email.binaryAttachments[i].body;
        insert attachment;
      }
    }
     return result;
  }
}

Test Class for Email Service:
@isTest
private class EmailTest{
static testMethod void testMe() {

  // create a new email and envelope object
  Messaging.InboundEmail email = new Messaging.InboundEmail() ;
  Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

  // setup the data for the email
  email.subject = 'Test Job Applicant';
  email.fromname = 'FirstName1 LastName1';
  env.fromAddress = 'raees.sabir@accenture.com';

  // add an attachment
  Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfile.txt';
  attachment.mimeTypeSubType = 'text/plain';

  email.binaryAttachments =
    new Messaging.inboundEmail.BinaryAttachment[] { attachment };

  // call the email service class and test it with the data in the testMethod
  ProcessJobApplicantEmail emailProcess = new ProcessJobApplicantEmail();
  emailProcess.handleInboundEmail(email, env);

  // query for the contact the email service created
  Contact contact = [select id, firstName, lastName, email from contact
    where firstName = 'FirstName1' and lastName = 'LastName1'];

  System.assertEquals(contact.firstName,'FirstName1');
  System.assertEquals(contact.lastName,'LastName1');
  System.assertEquals(contact.email,'raees.sabir@accenture.com');

  // find the attachment
  Attachment a = [select name from attachment where parentId = :contact.id];

  System.assertEquals(a.name,'textfile.txt');
 }
}

How to use apex variable for total records in Visualforce?

Scenario:

 I came across a issue where visualforce does not allow one to Count or Sum records in a page.
One solution would be to add more code to the controller to do a count of the records. Which is ok.
A simple solution is to use the apex variable function in Visualforce.

Solution:
Lets do it off Contacts
In your Apex Controller : Create a SOQL query as is:
public class countcontroller{
            public List<Contact> queryResult {get;private set;}
            public String qryString {get;set;}
            public PageReference query(){
            qryString =  'SELECT Name, Email, Phone from Contact';
            queryResult = Database.query(qryString);
             return null;
       }
}

Pretty Simple and Straight Forward.
Now for the VF Page and Magic:
You will see I use the apex variable function to do a couple of things:

create a variable run the query inside that variable counting all the records by 1 within a repeat tag calling the variable with the total Kind of like a for Loop but in Visualforce instead of controller.

<apex:page standardcontroller="Contact" extensions="countcontroller">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr height="5">
    <td width="35%" class="outsideround_head" align="right">
        Total Contacts Returned:&nbsp;
    </td>
    <td width="8%" class="outside_round_head_value">
        <apex:variable var="call" value="{!0}" />
        <apex:repeat var="countitall" value="{!queryResult}" >
        <apex:variable var="call" value="{!call+1}"/>
        </apex:repeat>
        <apex:outputText value="{!call}"/>
    </td>
</tr>
</table>
</apex:page>

GROUP BY - Count Method in Apex Controller?

Scenario:

We Need to do Total of Opportunities  Based on Stages. 

Thought Process:
What are the columns involved? Answer: StageName and Count or Total
What methods will we utilize to achieve these results? Answer: Group By SOQL Statement with Count.
What UI to built this neat logic? Answer: Apex Controller and VisualForce Page
Need to achieve this type of reporting for the user:


Solution:
Use Eclipse IDE or SOQL Explorer to create your SOQL Statement.
SELECT StageName, Count(Name) ce FROM Opportunity GROUP BY StageName
Second create  Apex Controller name what you like I named it TTL_Lesson, with your logic
public class TTL_Lesson{
public class OppStageHolder {
    public String OPP {get; set;}
    public Integer TTL_Opp {get; set;}
public OppStageHolder (){}
}
//Results will be placed within this List
public List queryResults{ get; set; }

//Your Page
public PageReference TTL() {

AggregateResult[] groupedResults = [SELECT StageName,
     Count(Name) ce FROM Opportunity
     GROUP BY StageName];
System.Debug('zzavg ' + groupedResults.size());
//Define your List
queryResults = new List();

for (AggregateResult ard : groupedResults)  {  
    OppStageHolder myObject = new OppStageHolder();  
    myObject.OPP = String.valueOf(ard.get('StageName'));  
    myObject.TTL_Opp = (Integer) ard.get('ce');      
    queryResults.add(myObject);  
}
return Page.TTL;
}

}

Now create your VF Page to call this and display it whenever the user clicks on this page:

<apex:page controller="TTL_Lesson" action="{!TTL}" showHeader="false" sidebar="false">
    <apex:dataTable value="{!queryResults}" var="a" id="theTable" border="2" cellpadding="1" cellspacing="1" bgcolor="#A9D0F5" >
                <apex:column >
                        <apex:facet name="header">Stage</apex:facet>
                        <apex:outputText value="{!a.OPP}"/>
                </apex:column>              
                <apex:column >
                        <apex:facet name="header">&nbsp;&nbsp;&nbsp;Count</apex:facet>
                        <apex:outputText value="{!a.TTL_Opp}"/>
                </apex:column>
    </apex:dataTable>
</apex:page>

Friday 23 August 2013

Winter ’14 Release Developer Preview

Summer is fading and fall will soon be here. Question: do you know what the best part of fall is? That’s right, the winter release of Salesforce.com. The Winter ’14 release of Salesforce.com is right around the corner and that means once again I get the distinct pleasure of reviewing some of the new developer features that have been added. There are a large number of new features in the Winter ’14 release that developers will enjoy and in this post I’ll highlight a few of, what I feel, are the more pertinent points that developers will be interested in.

Visualforce:
The enhancements to Visualforce in this release are around improving the developer experience of building HTML5 apps along with some other core improvements and new tools.
• <apex:input>is a new, HTML5-friendly, general purpose input component that adapts to the data expected by a form field. It uses the HTML type attribute to allow client browsers to display type-appropriate user input widgets,
• The HTML5<datalist>element specifies a list of auto-complete options to associate with an <input type=”text” /> element.
• A Visualforce page’s view state can be viewed now in the developer console.
• We’re piloting a new feature that allows a Visualforce page’s view state to be stored on the server rather than the client thus preventing the need to send it back and forth with each request and response. This could help improve performance where low bandwidth or high latency could cause problems (think mobile). As with most features we release in pilot, you’ll need to request to have this one activated.

Sandboxes:
We’re making some interesting changes to sandboxes in this release as well. These changes significantly help with testing and life cycle management. I think developers will also like the data limits increase.
• Configuration Only sandboxes have been renamed to Developer Pro sandbox and the storage limit on them has been increased to 1GB.
• Developer Sandboxes have had their storage limit increased to 200MB.

Developer Console:
As always with each release we try to make it easier to manage the code in your applications. We’ve continued that with some of the following additions to the Developer Console.
• You can now create and edit JavaScript, XML, CSS and plain text in static resources with the Static Resource Editor. If you’ve ever managed static resources I’m sure you’ll agree with me that this is one of those hallelujah features that developers are going to use a lot.
• We’ve included a history panel that lists the last ten SOQL queries making query reuse easier. Also worth noting is the query editor now supports SOSL as well.

**UPDATE**

It was brought to my attention after I posted this that I forgot one of the cooler enhancements to the Developer Console. We now can search across the entire codebase. There’s a flow-diagram view of a transaction, which shows how workflow and triggers are timed relative to one another. This will be tremendously helpful in debugging complex or large code bases. This can also be used with declarative and programatic logic.

**

Apex Code:
As usual we’ve continued adding features to and improving on the world’s first cloud programming language. There are a ton of additions to Apex. Here are a just a few.
• There is no more code statement limit. Although we’ve removed this limit, we haven’t removed the safety mechanism it provided. Instead we’ve limited the CPU time for transactions. The limits are now 10,000ms for synchronous Apex and 60,000ms for asynchronous Apex.
• The Topic and Topic Assignment objects now support triggers.
• New Database methods improve record merging functions.

API:
I think the biggest announcement that developers have been waiting for API wise is the availability of our Analytics API. We introduced a limited pilot in summer 13 and now the Analytics REST API is generally available. The Analytics API lets you integrate Salesforce report data into your apps programmatically and has several resources that let you query metadata, and record details. Not to be outdone, the team has also added features to the REST API, SOAP API, Metadata API, Streaming API, Bulk API and the Tooling API. A big change here is the introduction of flexible limits for both the SOAP and REST API. Flexible limits allow you to excede API request limit by up to 50% within the limit timeframe.

Miscellaneous Updates:
I’ve created this last category to lump a few things together that don’t really fit anything I’ve mentioned above nor are there enough of to warrant a separate category of their own.
• Have you ever been stymied by or frustrated by the fact you couldn’t use the User object in workflow? Well be frustrated no more, there’s a new beta feature that allows the User object to be used in workflow rules.
• Advanced setup search is now beta. With it enabled you can search for Setup pages, custom profiles, permission sets, public groups, roles, and users from the sidebar in Setup.
• We introduced the custom state and country picklist beta in summer 13. They’re now generally available.







Thursday 22 August 2013

Salesforce converted currency in report?

In Salesforce, there is a field type "currency", as a standard field for example Amount in Opportunity, and we can create custom field with data type is currency.

If you enable multi-currency in your Salesforce instance, if the currency is not in the Corporate currency, you will find the corporate currency show in parenthesis after the amount.

In report, you will find (converted) field for each currency field. You can add it into report as other normal field. But, you cannot add converted field as report filter (as of now).

Solution: use original currency as filter and add currency code. Example: USD 300, SGD 500, JPY 10,000 and etc.