Reference: This example uses the great search component provided by Avinava Maiti. His blog is here
http://blogforce9.blogspot.com/
Problem:
Using a standard lookup field on the user object, Salesforce does not allow you to lookup a user who is of the license type 'Chatter Free'.
Solution:
Although you cannot use a standard UI to update the user lookup field with a chatter free user, you can update the field through the API. This means that we could use a visualforce page to populate the lookup field.
Assumptions:
We will use a custom type ahead advanced search component.
We will use a custom field 'Chatter Free user lookup' on the account object.
STEP 1:
Install the autocomplete search component from here
http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000009KusM
STEP 2:
Create the following apex class
STEP 3: Create the following visualforce page:democustomlookup
STEP 4: Create a new custom button on the account object.
STEP 5:
Add this custom button to the page layout and you are done.
RESULT:
http://blogforce9.blogspot.com/
Problem:
Using a standard lookup field on the user object, Salesforce does not allow you to lookup a user who is of the license type 'Chatter Free'.
Solution:
Although you cannot use a standard UI to update the user lookup field with a chatter free user, you can update the field through the API. This means that we could use a visualforce page to populate the lookup field.
Assumptions:
We will use a custom type ahead advanced search component.
We will use a custom field 'Chatter Free user lookup' on the account object.
STEP 1:
Install the autocomplete search component from here
http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000009KusM
STEP 2:
Create the following apex class
STEP 3: Create the following visualforce page:democustomlookup
STEP 4: Create a new custom button on the account object.
STEP 5:
Add this custom button to the page layout and you are done.
RESULT:
Relationship between objects are created when you create a field of type Look-up... Of course, Salesforce standard objects come with their own built-in relationships.. Let's categorize relationships into two categories...
Now, that's all what we know.. But at the database level there is much more to be explored..
Standard Relationship
Standard relationships are the one's that come pre-built between Standard objects in Salesforce.
Let's understand the Account-Contact relationship.. In Contact you can find a field called Account.. This field establishes the relationship.. When you view a Contact record you will see the Account Name populated in this field... But guess what, that is not actually stored in the database..
The ID of the Account is stored in the look-up field. Hence, all look-up fields would store the ID.
Here is how the actual database fields are....
AccountId - This stores the ID of the Account.
Account -- This stores the relationship of the Account.
So, here come's the interesting part. By using the "Account" relationship you can access any field of the associated Account.
And what more, you can retrieve data from a relationship to a relationship as well...
So, they can be multi-level....
What's the advantage??
The better you understand relationships, the better you can construct complex nested queries and try to minimize the number of queries used.
Custom Relationship:
This is same as the standard relationship except that the naming convention has some differences...
THE __c and __r :
In our same example, if we create a custom Account look-up field on Contact and name it as CustomAccount... then accessing the relationship is as follows...
CustomAccount__c --> Equivalent of AccountId, holds the ID of the Account.
CustomAccount__r --> Equivalent of Account, holds the relationship
Our example query will modify as below..
Wondering how i came to know about this and where will you find more details on this????
Go to Setup--> Develop --> API and click on "Generate Enterprise WSDL"
The WSDL shows the actual way data is stored, the actual field names, the actual relationships etc...
- Standard Relationship
- Custom Relationship
Now, that's all what we know.. But at the database level there is much more to be explored..
Standard Relationship
Standard relationships are the one's that come pre-built between Standard objects in Salesforce.
Let's understand the Account-Contact relationship.. In Contact you can find a field called Account.. This field establishes the relationship.. When you view a Contact record you will see the Account Name populated in this field... But guess what, that is not actually stored in the database..
The ID of the Account is stored in the look-up field. Hence, all look-up fields would store the ID.
Here is how the actual database fields are....
AccountId - This stores the ID of the Account.
Account -- This stores the relationship of the Account.
So, here come's the interesting part. By using the "Account" relationship you can access any field of the associated Account.
[Select Account.Name,Account.BillingCity from Contact]
And what more, you can retrieve data from a relationship to a relationship as well...
[Select Account.Name,Account.BillingCity,Account.Owner.Name from Contact]
So, they can be multi-level....
What's the advantage??
The better you understand relationships, the better you can construct complex nested queries and try to minimize the number of queries used.
Custom Relationship:
This is same as the standard relationship except that the naming convention has some differences...
THE __c and __r :
In our same example, if we create a custom Account look-up field on Contact and name it as CustomAccount... then accessing the relationship is as follows...
CustomAccount__c --> Equivalent of AccountId, holds the ID of the Account.
CustomAccount__r --> Equivalent of Account, holds the relationship
Our example query will modify as below..
[Select CustomAccount__r.Name,CustomAccount__r.BillingCity,CustomAccount__r.Owner.Name from Contact]
Wondering how i came to know about this and where will you find more details on this????
Go to Setup--> Develop --> API and click on "Generate Enterprise WSDL"
The WSDL shows the actual way data is stored, the actual field names, the actual relationships etc...