Ads

Thursday 23 May 2013

Inserting Attachments using Apex Dataloader in Salesforce?


Inserting Attachments using Apex Dataloader in Salesforce

Once I came to know we can able to extract the Notes and attachments from an object using Dataloader, I thought importing the attachment is also the same and we can do it very easily in the same manner but I was wrong.


Let us see how we can do this using dataloader,but before that please recall 
How to Import/Export Notes and Attachment through DataLoader in Salesforce

For importing or inserting an attachment to an object (say Account) we need the following details in the CSV file that we are going to use in the Data loader.

PARENTID
NAME
CONTENTTYPE
BODY
OWNERID


PARENTID:
This is nothing but the Salesforce ID of the Parent object record(Say AccountID).


NAME: 
Name is the name of the attachment file.


CONTENTTYPE:

The File Format eg: Doc,txt,xls,pdf..

BODY:
This one plays an important role while importing an attachment.
We must give the Path of the attachment in the local Machine.
Make sure the File must follow with its extensions i.e .pdf,.doc.xls, etc

Example: C:\Program Files\salesforce.com\Data Loader\Test1\Attachments\TestDoc.doc



OWNERID:

Thursday 16 May 2013

Dynamic Dashboard in Salesforce?


  1. Dashboard which is running under current logged in user permission are known as “dynamic Dasboard”. 
  2. At the most 3 dynamic dashboards can be built
  3. Available in Unlimited, Enterprise and developer edition. 
  4. Dynamic dashboard cannot be scheduled for refresh. It must be scheduled manually.

How to create One to One relationship in Salesforce?

In Salesforce, we have One to Many relationship and Many to Many relationship.

To achieve One to One relationship in Salesforce, kindly follow the below steps

Objects: Interest, Employee.
Relationship: Interest is Master and Employee is Detail. 

1. Create a Roll up Summary field on Interest object to find the number of employees(Count).


2. Create a trigger in Employee object to check whether Number Of Employees is equal to one. If it is one, then throw an error, else allow the user to create.

Trigger:

trigger oneToOne on Employee__c (before insert, before update)
{
    for(Employee__c e : trigger.New)
    {
        String empId = e.Interest__c;
        Interest__c i = [SELECT Number_of_employees__c FROM Interest__c WHERE Id =: empId];
        Decimal empStrength = i.Number_Of_Employees__c;
        if(empStrength == 1)
        {
            e.addError('Already an employee has been associated with this interest');
        }
    }
}


Output:

Record types in Salesforce?

Record types allow you to offer different business processes, picklist values, and page layouts to different users based on their profiles. Record types can be used in various ways, for example:
  • Create record types for opportunities to differentiate your regular sales deals from your professional services engagements and offer different picklist values for each.
  • Create record types for cases to display different page layouts for your customer support cases versus your billing cases.

Custom Multi-Select picklist field in Visualforce?


There are several scenarios, where in we might have used input field for getting multi-select picklist field. What if you can’t really use an input field, here is the example code which will solve these type of problems.
Mutli-Select
VFPage Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<apex:page controller="multiselect">
    <apex:form >
        <apex:panelGrid columns="3" id="abcd">
            <apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!unselectedvalues}" />
            </apex:selectList>
                <apex:panelGroup >
                    <br/>
                    <apex:image value="{!$Resource.multiselected}">
                        <apex:actionSupport event="onclick" action="{!selectclick}" reRender="abcd"/>
                    </apex:image>
                    <br/><br/>
                    <apex:image value="{!$Resource.multiunselected}">
                        <apex:actionSupport event="onclick" action="{!unselectclick}" reRender="abcd"/>
                    </apex:image>
                </apex:panelGroup>
            <apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!SelectedValues}" />
            </apex:selectList>
        </apex:panelGrid>
    </apex:form>
</apex:page>
Controller Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class multiselect {
    Set<String> originalvalues = new Set<String>{'A','B','C','D','E','F','G'};
    Public List<string> leftselected{get;set;}
    Public List<string> rightselected{get;set;}
    Set<string> leftvalues = new Set<string>();
    Set<string> rightvalues = new Set<string>();
     
    public multiselect(){
        leftselected = new List<String>();
        rightselected = new List<String>();
        leftvalues.addAll(originalValues);
    }
     
    public PageReference selectclick(){
        rightselected.clear();
        for(String s : leftselected){
            leftvalues.remove(s);
            rightvalues.add(s);
        }
        return null;
    }
     
    public PageReference unselectclick(){
        leftselected.clear();
        for(String s : rightselected){
            rightvalues.remove(s);
            leftvalues.add(s);
        }
        return null;
    }
    public List<SelectOption> getunSelectedValues(){
        List<SelectOption> options = new List<SelectOption>();
        List<string> tempList = new List<String>();
        tempList.addAll(leftvalues);
        tempList.sort();
        for(string s : tempList)
            options.add(new SelectOption(s,s));
        return options;
    }
    public List<SelectOption> getSelectedValues(){
        List<SelectOption> options1 = new List<SelectOption>();
        List<string> tempList = new List<String>();
        tempList.addAll(rightvalues);
        tempList.sort();
        for(String s : tempList)
            options1.add(new SelectOption(s,s));
        return options1;
    }
}