Tag Archives: Force.com

Salesforce Relationships Among Objects

Master-Detail Relationship (1:N) :
A parent-child relationship in which the master object controls certain behaviors of the detail object:

  • When a record of the master object is deleted, its related detail records are also deleted.
  • The Owner field on the detail object is not available and is automatically set to the owner of its associated master record. Custom objects on the detail side of a master-detail relationship cannot have sharing rules, manual sharing, or queues, as these require the Owner field.
  • The detail record inherits the sharing and security settings of its master record.
  • The master-detail relationship field is required on the page layout of the detail record.
  • By default, records can’t be re-parented in master-detail relationships. Administrators can, however, allow child records in master-detail relationships on custom objects to be re-parented to different parent records by selecting the Allow re-parenting option in the master-detail relationship definition.

We can define master-detail relationships between custom objects or between a custom object and a standard object. However, the standard object cannot be on the detail side of a relationship with a custom object. In addition, we cannot create a master-detail relationship in which the User or Lead objects are the master.

When we define a master-detail relationship, the custom object on which you are working is the detail side. Its data can appear as a custom related list on page layouts for the other object.

Many-To-Many Relationship (N:N):

We can use master-detail relationships to model many-to-many relationships between any two objects. A many-to-many relationship allows each record of one object to be linked to multiple records from another object and vice versa. For example, We may have a custom object called “Bug” that relates to the standard case object such that a bug could be related to multiple cases and a case could also be related to multiple bugs. To create a many-to-many relationship, simply create a custom junction object with two master-detail relationship fields, each linking to the objects you want to relate.

Note: Custom objects with two master-detail relationships are supported in API version 11 and later.

Lookup Relationship (1:N):

This type of relationship links two objects together, but has no effect on deletion or security. Unlike master-detail fields, lookup fields are not automatically required. When we define a lookup relationship, data from one object can appear as a custom related list on page layouts for the other object. See the Salesforce online help for details.

Salesforce Tips & Tricks

  • If you wanted to query ‘accountId, account.name’ fields in a query just specify ‘account.name’ which will retrieve ‘accountId’ automatically.
  • SOQL query can be ORDER BY 32 fields.
  • SOQL/SOSL statements cannot exceed 10,000 characters.
  • SOQL query can’t run more than 120 seconds.
  • For best performance, SOQL queries must be selective, particularly for queries inside of triggers. To avoid long execution times, non-selective SOQL queries may be terminated by the system. Developers will receive an error message when a non-selective query in a trigger executes against an object that contains more than 100,000 records. To avoid this error, ensure that the query is selective.
  • The maximum number of records that an event report returns for a user who is not a system administrator is 20000; for system administrators is 100000.
  • Inbound Email Services: Maximum Number of Email Messages Processed (Includes limit for On-Demand Email-to-Case) is number of user licenses multiplied by 1000, up to a daily maximum of 1,000,000.
  • Inbound  Email Services: Maximum Size of Email Message (Body and Attachments) is 10 MB.
  • Apex Limit: Maximum number of characters for a class is 1 million.
  • Apex Limit: Maximum number of characters for a trigger is 1 million.
  • Apex Limit: Maximum amount of code used by all Apex code in an organization1 is 3 MB.
  • Apex Limit: Default timeout of callouts (HTTP requests or Web services calls) in a transaction is 10 seconds.
  • Apex Limit: Maximum size of callout request or response (HTTP request or Web services call) is 3 MB.
  • Apex Limit: Maximum SOQL query run time before the transaction can be canceled by Salesforce is 120 seconds.
  • Apex Limit: Maximum number of class and trigger code units in a deployment of Apex is 5,000.
  • Apex Limit: For loop list batch size is 200.

Salesforce where clause of field1 = field2 of same object

You might wanted to bring your records like Select id from Account where Column1 = Column2, which is not possible in Salesforce.
For this you have to create a formula field as Text and then populate this field as TRUE if the column1 = column2 else populate the value as FALSE.
Finally you can write a query as:

select id from Account where formulafield = 'TRUE'

Picklist Without None Value in Visualforce Page

Controller:

public class Sample{
    
    public Account acc {get;set;}
    public List<SelectOption> typeOptions {get;set;}
    
    // Constructor called when page is accessed.
    public Sample() {
        
        acc = new Account();        
        typeOptions = new List<SelectOption>();
        
        //Use DescribeFieldResult object to retrieve status field.
        Schema.DescribeFieldResult typeFieldDescription = Account.Type.getDescribe();
        
        //For each picklist value, create a new select option
        for (Schema.PickListEntry pl:typeFieldDescription.getPicklistValues()){
            typeOptions.add(new SelectOption(pl.getValue(),pl.getLabel()));
            
            //Obtain and assign default value
            if (pl.defaultValue){
                acc.Type= pl.getValue();
            }  
        }     
    }
}

Visualforce Page:

<apex:page controller="Sample">
    Please select account type:
    <br/>
    <apex:form >
        <apex:selectList size="1" value="{!acc.Type}">
            <apex:selectOptions value="{!typeOptions}"/>
        </apex:selectList>
    </apex:form>
</apex:page>

Output:

How to show more records in related list in Salesforce?

When viewing a record detail page (e.g. Contact detail) the related lists (e.g. Cases related list) shows a limited number of related records at a time.

download (1)

So, if you have more than 5 (by default) Cases tagged to an Contact, in the Contact detail page, you will see Show m more » | Go to list (n+) ». By default a will be 5 and b is total number of the records.

You can scroll down to the bottom of page, and look for Always show me more records per related list or Always show me fewer / more records per related list if you have click more before (even in previous login).
Always show me more records:

download (2)

Always show me fewer / more records:

download (3)

Clicking more or fewer increases and decreases the default number 5 (by default) of related list records displayed for all object record detail pages for the logged in user. If you notice, when you click more or fewer link, in the URL, Salesforce will add parameters rowsperlist=m (e.g. https://ap1.salesforce.com/0039000000ojedc?rowsperlist=10), this parameter will show related list up to 10 records for all related list.
Note: This change will be permanent for the logged in user for all tab, and can increase the related list records up-to 100.