profileId for Chatter Answers member signup

For profileId, we have to pass the Salesforce id of any profile in ChatterAnswersRegistration visualforce page.

Sample Code:

<chatteranswers:registration profileId="00e90000000X5DdAAK"/>

How to add Chatter Answers in Visualforce page?

chatteranswers:allfeeds tag is used to add Chatter Answers in Visualforce page.

Sample code:

<apex:page showHeader="false" >
      <chatteranswers:allfeeds communityId="09a90000000d1Af"/>
</apex:page>


here communityId is the Zone community id.


Output:


Cannot change Referece To error in Salesforce

Cannot change Referece To error in Salesforce occurs when lookup or master detail relationship has been modified.

If Account__c was initially created as lookup to Account object and later if it is mapped to some other object and if you try to move it to another organization, Cannot change Referece To error occurs.

In order to get rid of this, delete the field in the organization and then try to move from another organization.

Cheers!!!

DEV 401 training Videos

How to assign adjust width for columns in apex:panelGrid in Salesforce?

In order to assign adjust width for columns in apex:panelGrid, we have to create different CSS styles for columns and we have to assign it to "columnClasses" attribute.

Sample Code:

<apex:page >

<style type="text/css">
    .col1 {width:100px; text-align:center;}
    .col2 {width:150px; text-align:center;}
    .col3 {width:200px; text-align:center;}       
</style>

<apex:pagemessages />
<apex:form >
    <apex:panelGrid columns="3" columnClasses="col1, col2, col3" border="1" cellpadding="5" cellspacing="5">
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
        <apex:outputText >Sample</apex:outputText>
    </apex:panelGrid>
</apex:form>
</apex:page>


Output:


How to move Roles, Profiles, Reports, etc from one organization to another in Salesforce using Eclipse?

1. Right click the Project in Eclipse.

2. Click "Properties".


3. Click "Add/Remove" button.


4. Select the Components.


5. Right click the component you want to move.

6. Select "Deploy to Server" option.


7. Enter the username and password of destination organization.


8. Select the destination for Archive file.


9. Select the deployment plan.


10. Click Validate button to validate.


11. Click "Next" button to deploy the component.


After deploying:

AggregateResult in Salesforce

AggregateResult in Salesforce is used to find Sum, Min, Max and Avg. It is similar to Aggregate function in SQL.

Using Aggregate Result, we cannot fetch data. It is mainly used to find Sum, Min, Max and Avg.

Sample Code:

Visualforce page:

<apex:page controller="Sample" sidebar="false" action="{!show}">
<apex:pagemessages />
<apex:form >
    <apex:pageBlock >
        <apex:pageblockTable value="{!SummaryList}" var="r">           
            <apex:column headerValue="Account Name" value="{!r.AcctName}"/>
            <apex:column headerValue="Number of Contacts" value="{!r.Total}"/>
        </apex:pageblockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>


Apex Controller:

public with sharing class Sample {
    public List<AggregateResult> Result {get;set;}   
    public List<Summary> SummaryList {get;set;}
    public List<Account> AcctList;
    public Map<Id, Account> IdAccount;
    List<Id> Ids;
   
    public void show() {
        SummaryList = new List<Summary>();
        Result = new List<AggregateResult>();
        Ids = new List<Id>();
        AcctList = new List<Account>();
        IdAccount = new Map<Id, Account>();
       
        Result = [SELECT Count(Id) Total , AccountId FROM Contact WHERE AccountId != null GROUP BY AccountId];              
       
        for(AggregateResult a : Result) {  
            Ids.add((Id)a.get('AccountId'));
        }
       
        AcctList = [SELECT Name FROM Account WHERE Id IN : Ids];
       
        System.debug('Account List' + AcctList);
       
        for(Account a : AcctList) {
            IdAccount.put(a.Id, a);           
        }
       
        System.debug('Ids and Accounts are ' + IdAccount);
               
        for(AggregateResult a : Result) {
            Account TempAcct = new Account();           
            TempAcct = IdAccount.get((Id)(a.get('AccountId')));
            system.debug('Account Name is ' + TempAcct.Name);
            SummaryList.add(new Summary(a, TempAcct.Name));               
        }   
    }
   
    public class Summary {
        public Integer Total {get;set;}
        public String AcctName {get;set;}
       
        public Summary(AggregateResult a, String AccountName) {
            Total =  (Integer)a.get('Total');
            AcctName = AccountName;
        }
    }
}


Output:


Cheers!!!

How to create a notes under a record dynamically in Salesforce?

Sample Code:

        Member__c e = [SELECT Id, Comments__c FROM Member__c WHERE Id = 'a00U000000352lq'];
        Note n = new Note();
        n.body = e.Comments__c;  //Comments__c is TextArea field
        n.parentId = 'a00U000000352lq'; //Id of the record
        n.title = 'Sample Note';
        insert n;

How to convert Set to List in Salesforce?

Sample Code:

        Set<Integer> i = new Set<Integer>();
        i.add(1);
        i.add(2);
        i.add(3);
       
        List<Integer> s = new List<Integer>();
        s.addAll(i);

ApexPages.Severity supported values

Confirm/Success: 

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Confirm,'Sample Success Message'));


Warning:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Warning,'Sample Warning Message'));


 Informational:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Sample Informational Message'));


Error:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'Sample Error Message'));


You do not have access to any Chatter Answers zones error

We should enable "Available for Chatter Answers" check box to fix this issue.

Check the below link to fix this

http://www.infallibletechie.com/2013/07/chatter-answers-in-salesforce.html

Cheers!!!

Chatter Answers in Salesforce

Enabling Chatter Answers:

1. Go to Setup --> Build --> Customize --> Chatter Answers --> Settings.





2. Click "Edit" button.


3. Select "Enable" check box.

4. Click "Save" button.



Configuring Email Notifications for Chatter Answers:


1. Go to Setup --> Build --> Customize --> Chatter Answers --> Email Notification Settings.



2. Click "Edit" button.



3. Select the required options.

4. Click "Save" button.




Viewing Question Tab:

1. Go to Question tab.




2. Click "New" button.



3. Select Zone.




4. Create a Question and click "Save" button.





5. Click "Answer" link to answer and click "Answer Customer & Zone" to save it.


6. Click "Best Answer" link to make it as the best answer.


Output:


Setting Q&A:

1. Go to Setup --> Build --> Customize --> Chatter Settings --> Zones.


2. Click "Edit" link.


3. Enable "Chatter for Answers" check box.


4. Go to Q&A tab.


Output:


How to get contact's State, City, Country fields in Visualforce page?

Other Address Fields:
  1. OtherStreet
  2. OtherPostalCode
  3. OtherCity
  4. OtherCountry
  5. OtherState
Mailing Address Fields:
  1. MailingStreet
  2. MailingCity
  3. MailingCountry
  4. MailingState
  5. MailingPostalCode

Sample Code:

Visualforce page:

<apex:page controller="Sample" sidebar="false">
<apex:form >
    <apex:pageblock mode="edit">
        <apex:pageblockSection title="Contact Information">
            <apex:inputField value="{!cont.FirstName}"/>
            <apex:inputField value="{!cont.Lastname}"/>
            <apex:pageblockSectionItem >
                Address
                <apex:inputField value="{!cont.OtherStreet}"/> 
            </apex:pageblockSectionItem> 
            <apex:pageblockSectionItem >
                Postal Code
                <apex:inputField value="{!cont.OtherPostalCode}"/> 
            </apex:pageblockSectionItem>            
            <apex:pageblockSectionItem >
                Postal City
                <apex:inputField value="{!cont.OtherCity}"/> 
            </apex:pageblockSectionItem>           
            <apex:pageblockSectionItem >
                Postal Country
                <apex:inputField value="{!cont.OtherCountry}"/> 
            </apex:pageblockSectionItem>                         
            <apex:inputField value="{!cont.Email}"/>               
            <apex:inputField value="{!cont.Phone}"/>   
            <apex:inputField value="{!cont.MobilePhone}"/>                                
            <apex:inputField value="{!cont.OtherPhone}"/>               
            <apex:inputField value="{!cont.Birthdate}"/> 
        </apex:pageblockSection>       
        <apex:pageblockButtons location="bottom" >
            <apex:commandButton value="Save"/>
            <apex:commandButton value="Cancel"/>
        </apex:pageblockButtons>
    </apex:pageblock>
</apex:form>
</apex:page>


Apex Controller:

public with sharing class Sample
{
    public Contact cont {get;set;}
}


Output:



Trigger to send a pdf along with email in Salesforce

Trigger:

trigger sendEmail on Employee__c (after insert, after update)  {   
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    for(Employee__c e : trigger.new) {  
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.setContentType('application/pdf');
        attach.setFileName('Employee.pdf');
       
        String body;
       
        body = '<html><h1 style=\"text-align:center;\">Employee Information</h1><br/><br/><table align=\"center\"><tr><td>Employee Name</td><td>' + e.Name + '</td></tr><tr><td>Age</td><td>' + e.Age__c + '</td></tr><tr><td>State</td><td>' + e.State__c + '</td></tr><tr><td>City</td><td>' + e.City__c + '</td></tr></table></html>';
        System.debug('HTML is ' + body);
       
        attach.Body = Blob.toPDF(body);
               
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] { e.Email__c });
        mail.setSubject('PDF Generation');
        mail.setHtmlBody('PFA');
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });    
       
        mails.add(mail); 
    }
    if(!mails.isEmpty()) {
        Messaging.SendEmail(mails);
    }
}


Generated PDF:


Cheers!!!

Salesforce Summer '13 Release Exam Important Topics

  1. Sandbox Templates
  2. Salesforce Communities
  3. Enhanced Site.com features
  4. Force.com Canvas
  5. Enhanced Report and Dashboard folder sharing feature
  6. Actions
  7. User Interface features

Sandbox Templates in Salesforce

Sandbox templates provide control over the objects copied to your sandbox. You can create a sandbox template that defines the object data you want in your sandbox. When you create or refresh a Full sandbox, you’ll have the option to use your sandbox template.

Sandbox templates are only available for use with a Full sandbox.

Sandbox data templates allow you to pick specific objects and data to copy to your Full Sandbox, so you can control the size and content of each sandbox. Sandbox data templates are only available for use with a Full Sandbox.

When you create a sandbox data template, you select the object data (standard and custom) to copy. All of the records for the selected objects are copied to the new sandbox.

Some objects are included even before you’ve selected anything because they’re required in any organization. The template starts with all of the required objects and metadata for a Configuration Only sandbox, and then adds the object data you selected in the template. Other objects are added automatically when you select objects that are dependent on them. As you configure the template, the Copy Statistics panel shows you an estimate of how much data would be copied to a sandbox based on this template.

As you change the schema of the objects in your organization, Salesforce updates the template by adding or subtracting the related, included objects. For example, if Object A is a master of Object B, and you add Object B to a template, Salesforce requires Object A in the template, and adds Object A.

1. Go to Setup --> Administer --> Data Management --> Sandboxes --> SandboxTemplates tab.

2. Click New Sandbox Template or click Edit next to an existing template you want to modify.


3. Enter a name and description for the sandbox template.

4. To add objects to the template, select the checkbox for each object you want from the available Objects list. The Object Details section shows you the objects to be added automatically with the one you’ve selected.

5. To remove objects from the template, deselect the checkbox for the object in the available Objects list. If you remove an object you previously selected, dependent objects you didn’t explicitly select are removed. If you attempt to remove an object with dependent objects, you’ll receive a warning requesting a confirmation of the removal. Once you confirm your choice, those objects will also be removed.

6. Click Save.


Actions in Salesforce

Actions let you use Chatter in new ways, like create records directly in the feed.

Enabling Actions in Salesforce:

1. Go to Setup --> Customize --> Chatter --> Settings.

2. Click "Edit" button.

3. Select "Enable Publisher Actions" checkbox.

4. Click "Save" button.


Types of Actions in Salesforce:

1. Object Specific Actions:

          Creating Actions for particular Object. Action button will be available only for that object.

1. Go to Setup --> Customize --> Any Object --> Buttons, Links, and Actions.

2. Click "New Action" button.



3. Fill in the details and click "Save" button.


4. Select the fields for layouts and click "Save" button.


5. Go to the object and add the Action button to the page layout and click "Save" button..


Output:



2. Global Actions:

          Creating Actions in general. Action button will be available for all objects.


1. Go to Setup --> Create --> Global Actions and click "New Action" button.


2.  Fill in the details and click "Save" button.


3.  Select the fields for layouts and click "Save" button.


4. Go to Customize --> Any Object --> Page Layouts and add the New Action button created.


Output: