salseforse interview questions-2
To demonstrate this, lets consider an example of Google Map.
Lets create a S-Control for the Google Map.
Now let’s first create a new S-Control:
Workflow is the automation of the following types of actions based on your organization’s processes:
Step 1 in creating workflow rule is selecting the object, on which the workflow will be created.
in step 2, Evaluation criteria have three options to choose:
So, in step 2 basically we create a criteria when the rule should run.
In step 3, we can specify the action what should happen if workflow criteria meets.
In this case, i have selected New Email Alert, below screen shot is self explanatory about the process.
We have to select the recipients for the email, in our case Email field have the email address of the student. We have also selected the newly created email template “Welcome to shivasoft”.
In this tutorial, we have covered how to create the Workflow rule criteria and action in salesforce.com.
In next part of tutorial, we will see how to create the trigger for our application.
This time we will see, how to create email templates in Salesforce.com
To create email template, go to Personal Setup | Email | My Templates and click on New Template.
In type of Email template, we can select HTML, HTML with Letter Head , Visual force or without letter Head.
You can create four different types of email templates:
Note : You cannot send a mass email using a Visualforce email template.
For Letter Head type, we first have to create the letterhead. So, Start with letterhead Creation:
After creating the Letterhead, I have created below Email Template:
As, you can see in above screen shot that Creating email template is very easy, you can use Object fields as a place holder.
In above email, Student name, Course , fees and Balance is Place holder which will be replaced on runtime.
To manage your personal email templates, click Setup | Email | My Templates. If you have permission to manage public email templates, click Setup | Communication Templates | Email Templates.

So, in this article i will first show you that how to create custom objects, how to relate them and what will happen if we delete master or child?
here i am going to assume that we want to relate A and B. Let us assume that we have two custom object - A and B.
To provide the many to many relationship between A and B, we will need to create one more object let’s say it would be C, it will be called as junction object.
So, start with creating Object A.
In same way, as shown in above image create B and C. For the simplicity of the example i have not added any field in Object A and B. By default Name field is provided by the salesforce on all objects.
We are going to use the object C as a junction object for A and B.
on object C, create “first Master-Detail” field and select object A as parent. This will be Primary Master – Detail relationship.
In next screen give the name of the field.
for the Master record A, i have used name “ChildOfA” and in same way for the Master record B – i used “ChildOfB”.
Untill now, we have created two fields on object C in which one refer to master record A and other will refer master record B as shown in below screen. Now we can create a tab for all the custom objects to add the record. First create record for A then B and for record C screen will look like below snap.
Few important points (Interview Questions of salesforce ):
See Also:
As the parent object is not the standard object, in this case the report will be in the “Other reports” section as shown in below image.
Hi hope, this article will help to find the cause and solution that where is the custom objects report in salesforce.
1. What is Apex
Ans: It is the in-house technology of salesforce.com which is
similar to Java programming with object oriented concepts and to write our own
custom logic.
2. What is S-Control ?
Ans: S-Controls are the predominant salesforce.com widgets which are completely based on Javascript. These are hosted by salesforce but executed at client side. S-Controls are superseded by Visualforce now.
Ans: S-Controls are the predominant salesforce.com widgets which are completely based on Javascript. These are hosted by salesforce but executed at client side. S-Controls are superseded by Visualforce now.
3. What is a Visualforce Page ?
Ans: Visualforce is the new markup language from salesforce, by using which, We can render the standard styles of salesforce. We can still use HTML here in Visualforce. Each visualforce tag always begins with “apex” namespace. All the design part can be acomplished by using Visualforce Markup Language and the business logic can be written in custom controllers associated with the Page.
Ans: Visualforce is the new markup language from salesforce, by using which, We can render the standard styles of salesforce. We can still use HTML here in Visualforce. Each visualforce tag always begins with “apex” namespace. All the design part can be acomplished by using Visualforce Markup Language and the business logic can be written in custom controllers associated with the Page.
4. Will Visual force still supports the merge
fields usage like S-control ?
Ans: Yes. Just like S-Controls, Visualforce Pages support embedded merge fields, like the {!$User.FirstName} used in the example.
Ans: Yes. Just like S-Controls, Visualforce Pages support embedded merge fields, like the {!$User.FirstName} used in the example.
5. Where to write Visualforce code ?
Ans: You can write the code basically in 3 ways.
Ans: You can write the code basically in 3 ways.
1.
setup->App Setup->Develop->Pages and create new
Visulaforce page.
2.
Setup -> My Personal Information -> Personal Information
-> Edit check the checkbox development mode. When you run the page like
this, https://ap1.salesforce.com/apex/MyTestPage. you will find the Page editor
at the bottom of the page. You can write you page as well as the controller
class associated with it, there it self.
3.
Using EclipseIDE you can create the Visulaforce page and write
the code.
6.What are Apex Governor Limits?
Governor limits are runtime limits enforced by the Apex runtime
engine. Because Apex runs in a shared, multitenant environment, the Apex
runtime engine strictly enforces a number of limits to ensure that code does
not monopolize shared resources. Types of limits that Apex enforces are
resources like memory, database resources, number of script statements to avoid
infinite loops, and number of records being processed. If code exceeds a limit,
the associated governor issues a runtime exception.
7. How to create and host S Control in
Salesforce ?To demonstrate this, lets consider an example of Google Map.
Lets create a S-Control for the Google Map.
Now let’s first create a new S-Control:
- Click on “Setup” which is located on the top right corner of the force.com page.
- Expand “Develop” item and click on “S-Controls”
- Hit “New Custom S-Control”
- Provide a Label “Google Map” and a description is you wished to
- The Type should be HTML since we want to create a HTML, Google API mash up
- Now it is time to enter the code for the S-Control
1 | <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> |
2 | <head> |
3 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
4 | <title>Google Maps JavaScript API Example: Advanced Directions</title> |
5 | <link href="/dCSS/Theme2/default/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" |
6 | rel="stylesheet"> |
7 | <link href="/dCSS/Theme2/default/custom.css" type="text/css" media="handheld,print,projection,screen,tty,tv" |
8 | rel="stylesheet"> |
9 |
10 | <script src=" http://maps.google.com/?file=api&v=2.x&key={YOUR KEY}" |
11 | type="text/javascript"></script> |
12 |
13 | <script src="/js/functions.js" type="text/javascript"></script> |
14 |
15 | <script type="text/javascript" src="/soap/ajax/13.0/connection.js"></script> |
16 |
17 | <style type="text/css"> |
18 | body { |
19 | font-family: Verdana, Arial, sans serif; |
20 | font-size: 11px; |
21 | margin: 2px; |
22 | } |
23 | table.directions th { |
24 | background-color:#EEEEEE; |
25 | } |
26 |
27 | img { |
28 | color: #000000; |
29 | } |
30 | </style> |
31 |
32 | <script type="text/javascript"> |
33 |
34 | var map; |
35 | var gdir; |
36 | var geocoder = null; |
37 | var addressMarker; |
38 | var dirFrom = '{!$Request.from}'; |
39 | var dirTo = '{!$Request.to}'; |
40 | var mapLocale = "" |
41 | var SControlID = '{!$Request.lid}'; |
42 | var SFrameIC = '{!$Request.ic}'; |
43 |
44 |
45 | function initValues() |
46 | { |
47 | mapLocale = "en_US"; |
48 |
49 | setInputFields(dirFrom,dirTo); |
50 | } |
51 |
52 | function setInputFields(from, to) |
53 | { |
54 | window.document.getElementById("fromAddress").value = from; |
55 | window.document.getElementById("toAddress").value = to; |
56 | } |
57 |
58 |
59 | function initialize() |
60 | { |
61 | initValues(); |
62 |
63 | if (GBrowserIsCompatible()) { |
64 | map = new GMap2(document.getElementById("map_canvas")); |
65 | map.addControl(new GSmallMapControl()); |
66 | map.addControl(new GMapTypeControl()); |
67 | gdir = new GDirections(map, document.getElementById("directions")); |
68 | GEvent.addListener(gdir, "load", onGDirectionsLoad); |
69 | GEvent.addListener(gdir, "error", handleErrors); |
70 |
71 | setDirections(dirFrom, dirTo, mapLocale); |
72 | } |
73 | } |
74 |
75 | function setDirections(fromAddress, toAddress, locale) { |
76 | if ((fromAddress) && (toAddress)) |
77 | gdir.load("from: " + fromAddress + " to: " + toAddress, |
78 | { "locale": locale }); |
79 | } |
80 |
81 | function handleErrors() |
82 | { |
83 | if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) |
84 | alert("No
corresponding geographic location could be found for one of the
specified addresses. This may be due to the fact that the address is
relatively new, or it may be incorrect.\nError code: " +
gdir.getStatus().code); |
85 | else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) |
86 | alert("A
geocoding or directions request could not be successfully processed,
yet the exact reason for the failure is not known.\n Error code: " +
gdir.getStatus().code); |
87 |
88 | else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) |
89 | alert("The
HTTP q parameter was either missing or had no value. For geocoder
requests, this means that an empty address was specified as input. For
directions requests, this means that no query was specified in the
input.\n Error code: " + gdir.getStatus().code); |
90 |
91 | // else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong |
92 | //
alert("The geocode for the given address or the route for the given
directions query cannot be returned due to legal or contractual
reasons.\n Error code: " + gdir.getStatus().code); |
93 |
94 | else if (gdir.getStatus().code == G_GEO_BAD_KEY) |
95 | alert("The
given key is either invalid or does not match the domain for which it
was given. \n Error code: " + gdir.getStatus().code); |
96 |
97 | else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) |
98 | alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code); |
99 |
100 | else alert("An unknown error occurred."); |
101 |
102 | } |
103 |
104 | function onGDirectionsLoad(){ |
105 | // Use this function to access information about the latest load() |
106 | // results. |
107 |
108 | // e.g. |
109 | // document.getElementById("getStatus").innerHTML = gdir.getStatus().code; |
110 | // and yada yada yada... |
111 | } |
112 | </script> |
113 |
114 | </head> |
115 | <body onload="initialize()" onunload="GUnload()"> |
116 | <div style="background-color: #CCCCCC"> |
117 | <form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false"> |
118 | <table> |
119 | <tr> |
120 | <th align="right"> |
121 | From: </th> |
122 | <td> |
123 | <input type="text" size="25" id="fromAddress" name="from" value="" /></td> |
124 | <th align="right"> |
125 | To: </th> |
126 | <td align="right"> |
127 | <input type="text" size="25" id="toAddress" name="to" value="" /></td> |
128 | <th align="right"> |
129 | Language: </th> |
130 | <th align="right"> |
131 | <select id="locale" name="locale"> |
132 | <option value="en" selected="selected">English</option> |
133 | <option value="fr">French</option> |
134 | <option value="de">German</option> |
135 | <option value="ja">Japanese</option> |
136 | <option value="es">Spanish</option> |
137 | </select> |
138 | </th> |
139 | <td> |
140 | <input name="submit" type="submit" value="Get Directions!" /></td> |
141 | </tr> |
142 | </table> |
143 | </form> |
144 | </div> |
145 | <div style="border-width: 1px; border-color: #000000; border-style: solid;"> |
146 | <div style="overflow: auto; width: 99.5%; height: 380px"> |
147 | <table class="directions" style="width: 100%; height: 100%"> |
148 | <tr> |
149 | <td valign="top" style="width: 275px;"> |
150 | <div id="directions" style="width: 275px; background-color: #ffffff;"> |
151 | </div> |
152 | </td> |
153 | <td valign="top"> |
154 | <div id="map_canvas" style="width: 100%; height: 375px; background-color: #ffffff;"> |
155 | </div> |
156 | </td> |
157 | </tr> |
158 | </table> |
159 | </div> |
160 | </div> |
161 | </body> |
162 | </html> |
8. Difference between Sandbox and
Development environment?
A test environment for salesforce.com is crucial to change control.
Salesforce.com provides the tools needed to test anything in a test
environment before you implement it in your live instance. You can
either test in a Sandbox environment or in a Developer environment. What
is the difference? I will share what I know…
Sandbox
The salesforce.com Sandbox environment is an exact copy of your salesforce.com instance. You can copy your live instance to a sandbox environment (but you have to perform manually from sandbox to developer edition) where you can test any changes, implementations, AppExchange apps or updates. It can also be your hands-on training environment without risking your live data.
You can either copy your configuration and data into a sandbox environment or just the configuration. It acts exactly like your live instance, but be careful if you have workflow rules or automations because they will work in the sandbox as well.
I know that this sounds wonderful and if you don’t have it, you are dying to know how to get it. The problem is the cost. If you are on Unlimited Edition, then cost is not a problem because it comes included. But for Enterprise, Professional or Group Editions, you have to pay… and the price is hefty; anywhere between 25k-50k per year. For a lot of companies, that is more than they are paying for their live salesforce.com instance. So how do you test salesforce.com without Sandbox? It is always suggested to develop application in sandbox instance then go for LIVE.
Developer Edition
Developer Edition was an edition created for development of integrations and apps, specifically for the AppExchange. It is also a great tool for testing/training in salesforce.com. What makes this a great tool is the fact that it is free. Anyone can get a Developer Edition of salesforce.com. It is a standard Enterprise Edition with very limited storage space. You cannot copy your configuration or data onto the Developer Edition, but you can customize it to match your instance’s look and feel. Once it is customized, you can use it for training, testing or anything else you want. It takes a little bit of work, but you can make it act and feel just like your live instance. The work is well worth it for the free price.
To get a copy of Developer Edition for yourself or your company go here. Play around with it. Get apps from the AppExchange. Do anything and everything that you have been scared to do your live system. If you come up with a clever way of using the system, post it on AppExchange and share your knowledge.
Sandbox
The salesforce.com Sandbox environment is an exact copy of your salesforce.com instance. You can copy your live instance to a sandbox environment (but you have to perform manually from sandbox to developer edition) where you can test any changes, implementations, AppExchange apps or updates. It can also be your hands-on training environment without risking your live data.
You can either copy your configuration and data into a sandbox environment or just the configuration. It acts exactly like your live instance, but be careful if you have workflow rules or automations because they will work in the sandbox as well.
I know that this sounds wonderful and if you don’t have it, you are dying to know how to get it. The problem is the cost. If you are on Unlimited Edition, then cost is not a problem because it comes included. But for Enterprise, Professional or Group Editions, you have to pay… and the price is hefty; anywhere between 25k-50k per year. For a lot of companies, that is more than they are paying for their live salesforce.com instance. So how do you test salesforce.com without Sandbox? It is always suggested to develop application in sandbox instance then go for LIVE.
Developer Edition
Developer Edition was an edition created for development of integrations and apps, specifically for the AppExchange. It is also a great tool for testing/training in salesforce.com. What makes this a great tool is the fact that it is free. Anyone can get a Developer Edition of salesforce.com. It is a standard Enterprise Edition with very limited storage space. You cannot copy your configuration or data onto the Developer Edition, but you can customize it to match your instance’s look and feel. Once it is customized, you can use it for training, testing or anything else you want. It takes a little bit of work, but you can make it act and feel just like your live instance. The work is well worth it for the free price.
To get a copy of Developer Edition for yourself or your company go here. Play around with it. Get apps from the AppExchange. Do anything and everything that you have been scared to do your live system. If you come up with a clever way of using the system, post it on AppExchange and share your knowledge.
13. When you can’t add Time dependent action
in Workflow rule?
You can’t add time-dependent actions to a rule if you choose Every time a record is created or edited.
You can’t add time-dependent actions to a rule if you choose Every time a record is created or edited.
- Tasks – Assign a new task to a user, role, or record owner.
- Email Alerts – Send an email to one or more recipients you specify.
- Field Updates – Update the value of a field on a record.
- Outbound Messages – Send a secure configurable API message (in XML format) to a designated listener.
- Assign follow-up tasks to a support rep one week after a case is updated.
- Send sales management an email alert when a sales rep qualifies a large deal.
- Change the Owner field on a contract three days before it expires.
- Trigger an outbound API message to an external HR system to initiate the reimbursement process for an approved expense report.
Step 1 in creating workflow rule is selecting the object, on which the workflow will be created.
in step 2, Evaluation criteria have three options to choose:
- When a record is created, or when a record is edited and did not previously meet the rule criteria: Choose this option to include new records and updates to existing records, unless the rule just ran and still meets the rule criteria. The rule is not re-triggered on edits that do not affect rule criteria. For example, if setting an opportunity rating to “Hot” causes the rule to run, with this option, the rule will run again only if the rating changes, then changes back to “Hot”—no matter how many times you edit the object.
- Only when a record is created: Choose this option to ignore updates to existing records.
- Every time a record is created or edited: Choose this option to include new records and updates to existing records and repeatedly trigger the rule, even if the record still meets the criteria. You cannot add time-dependent actions to the rule if you choose Every time a record is created or edited.
So, in step 2 basically we create a criteria when the rule should run.
In step 3, we can specify the action what should happen if workflow criteria meets.
In this case, i have selected New Email Alert, below screen shot is self explanatory about the process.
We have to select the recipients for the email, in our case Email field have the email address of the student. We have also selected the newly created email template “Welcome to shivasoft”.
In this tutorial, we have covered how to create the Workflow rule criteria and action in salesforce.com.
In next part of tutorial, we will see how to create the trigger for our application.
14. What are the types of email templates
available in salesforce.com?
1.
Text
2.
HTML with Letter Head
3.
Custom HTML
4.
Visual force
To create email template, go to Personal Setup | Email | My Templates and click on New Template.
In type of Email template, we can select HTML, HTML with Letter Head , Visual force or without letter Head.
You can create four different types of email templates:
- Text – All users can create or change text email templates. See Creating Text Email Templates.
- HTML with letterhead – Administrators and users with the “Edit HTML Templates” permission can create HTML email templates based on a letterhead. See Creating HTML Email Templates.
- Custom HTML – Administrators and users with the “Edit HTML Templates” permission can create custom HTML email templates without using a letterhead. You must either know HTML or obtain the HTML code to insert in your email template. See Creating Custom HTML Email Templates.
- Visualforce – Administrators and developers can create templates using Visualforce. Visualforce email templates allow for advanced merging with a recipient’s data, where the content of a template can contain information from multiple records, see Creating Visualforce Email Templates.
Note : You cannot send a mass email using a Visualforce email template.
For Letter Head type, we first have to create the letterhead. So, Start with letterhead Creation:
After creating the Letterhead, I have created below Email Template:
As, you can see in above screen shot that Creating email template is very easy, you can use Object fields as a place holder.
In above email, Student name, Course , fees and Balance is Place holder which will be replaced on runtime.
To manage your personal email templates, click Setup | Email | My Templates. If you have permission to manage public email templates, click Setup | Communication Templates | Email Templates.
1)Click on the name of any email template to go to the Viewing Email Templates page.
2)To edit or delete a template, click Edit or Del next to the template name in the list.
3)Click New Template to create any type of email template.
2)To edit or delete a template, click Edit or Del next to the template name in the list.
3)Click New Template to create any type of email template.
15. What are the different Salesforce.com
Editions and Limits?
Roll up summary field in salesforce calculates the Count, Sum, Min or Max of particular field of any child record. Thus, we can say that Roll up summary field can only be created on Master object.
Note : Roll up summary field can only be defined on the master object.
While your formula fields calculate values using fields within a single record, roll-up summary fields calculate values from a set of related records, such as those in a related list. You can create roll-up summary fields that automatically display a value on a master record based on the values of records in a detail record. These detail records must be directly related to the master through a master-detail relationship.
refer this page, to study more about the roll up fields.
The Roll up Summary field is basically of 4 types:
As, per our previous sessions on salesforce, lets create roll up field on object Course because this is the Master object.
I want to calculate total income from a course:
Go to App Setup | Create | Objects and click on New field and Select Roll up summary field.
In Step 2, enter the field name and help text etc.
For step 3, you will see below screen,
In above image, at 1 we have to select the child object, at 2 we have to select the field on which it should calculate.
In our case, Fees paid field is of Formula type which works on currency.
And in section 3 you ca specify weather this roll up summary field include all record or any specific record which comes under the criteria you specified.
So, after creation of Roll up field on Master object final look is shown below:
Salesforce Limits is a reference guide that covers a variety of
limits associated with Salesforce features
and products. However, Salesforce Limits doesn’t cover all limits and some limits may not apply to
your organization. Keep in mind that stated limits aren’t a
guarantee that the specified resource is available at its limit in
all circumstances. For example, some limits depend on load, performance,
and other system issues. In addition, Salesforce Limits doesn't include limits of:
1)User interface elements in the Salesforce application
2)Field lengths of Salesforce objects
3)Desktop integration clients
2)Field lengths of Salesforce objects
3)Desktop integration clients
All limits are subject to change at any time. Contact salesforce.com for more
information.
16. What is Roll up summary field in
Salesforce?
Roll up summary field in salesforce calculates the Count, Sum, Min or Max of particular field of any child record. Thus, we can say that Roll up summary field can only be created on Master object.
While your formula fields calculate values using fields within a single record, roll-up summary fields calculate values from a set of related records, such as those in a related list. You can create roll-up summary fields that automatically display a value on a master record based on the values of records in a detail record. These detail records must be directly related to the master through a master-detail relationship.
refer this page, to study more about the roll up fields.
The Roll up Summary field is basically of 4 types:
- Count
- Sum
- Min
- Max
As, per our previous sessions on salesforce, lets create roll up field on object Course because this is the Master object.
I want to calculate total income from a course:
Go to App Setup | Create | Objects and click on New field and Select Roll up summary field.
In Step 2, enter the field name and help text etc.
For step 3, you will see below screen,
In above image, at 1 we have to select the child object, at 2 we have to select the field on which it should calculate.
In our case, Fees paid field is of Formula type which works on currency.
And in section 3 you ca specify weather this roll up summary field include all record or any specific record which comes under the criteria you specified.
So, after creation of Roll up field on Master object final look is shown below:
17. What will happen if the Account is
deleted?
If the Account is deleted then Contact, Opportunity will also be
deleted from Salesforce which are related to that Account.
From the database perspective, check below image of child
relationships of Account:
If we use schema builder, released in Winter 12 it would look
like:
18. How many types of the relationship fields
available in Salesforce?
Ans :
1.
Master Detail
2.
Many to Many
3.
Lookup
4.
Hierarchical (It is available only on User Object, we cannot
create this relationship)
Use relationships to associate an object with other objects in Salesforce. For example, a relationship can link custom object records to standard
object records in a related list, such as linking a custom object
called “Bugs” to cases to track product defects associated
with customer cases. You can define different types
of relationships by creating custom relationship fields on an object.
Before you begin creating relationships, determine the type of relationship
that suits your needs.
There are different types of relationships between objects in Salesforce. Their differences include how they handle data deletion, sharing,
and required fields in page layouts:
- Master-detail
- This type of relationship closely links objects together such that the master record controls certain behaviors of the detail and subdetail record. For example, you can define a two-object master-detail relationship, such as Account—Expense Report, that extends the relationship to subdetail records, such as Account—Expense Report—Expense Line Item. You can then perform operations across the master—detail—subdetail relationship.
- Behaviors of master-detail relationships include:
- Deleting a detail record moves it to the Recycle Bin and leaves the master record intact; deleting a master record also deletes related detail and subdetail records. Undeleting a detail record restores it, and undeleting a master record also undeletes related detail and subdetail records. However, if you delete a detail record and later, separately, delete its master record, you cannot undelete the detail record, as it no longer has a master record to relate to.
- By default, records can’t be reparented in master-detail relationships. Administrators can, however, allow child records in master-detail relationships on custom objects to be reparented to different parent records by selecting the Allow reparenting option in the master-detail relationship definition.
- The Owner field on the detail and subdetail records is not available and is automatically set to the owner of the master record. Custom objects on the “detail” side of a master-detail relationship can't have sharing rules, manual sharing, or queues, as these require the Owner field.
- The security settings for the master record control the detail and subdetail records.
- The master-detail relationship field (which is the field linking the objects) is required on the page layout of the detail and subdetail records.
- The master object can be a standard object, such as Account or Opportunity, or a custom object.
- As a best practice, don't exceed 10,000 child records for a master-detail relationship.
- Many-to-many
- You 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, you 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.
- Lookup
- This type of relationship links two objects together. Lookup relationships
are similar to master-detail relationships, except they do not support
sharing or roll-up summary fields. With a lookup relationship, you
can:
- Link two different objects.
- Link an object with itself (with the exception of the user object; see Hierarchical). For example, you might want to link a custom object called “Bug” with itself to show how two different bugs are related to the same problem.
- When you create a lookup relationship, you can set these options:
- Make the lookup field required for saving a record, requiring it on the corresponding page layout as well.
- If the lookup field is optional,
you can specify one of three behaviors to occur if the lookup record
is deleted:
- Clear the value of this field This is the default. Clearing the field is a good choice when the field does not have to contain a value from the associated lookup record.
- Don’t allow deletion of the lookup record that’s part of a lookup relationship This option restricts the lookup record from being deleted if you have any dependencies, such as a workflow rule, built on the relationship.
- Delete this record also Available only if a custom object contains the lookup relationship, not if it’s contained by a standard object. However, the lookup object can be either standard or custom. Choose when the lookup field and its associated record are tightly coupled and you want to completely delete related data. For example, say you have an expense report record with a lookup relationship to individual expense records. When you delete the report, you probably want to delete all of the expense records, too.
- When you define a lookup relationship, you have the option to include a lookup field on the page layouts for that object as well as create a related list on the associated object's page layouts. For example, if you have a custom object called “PTO Requests” and you want your users to link a PTO request with the employee submitting the request, create a lookup relationship from the PTO Request custom object with the user object.
- If the parent record in a lookup relationship is deleted, the field history tracking for the child record does not record the deletion. For example, if a parent account is deleted, the Account History related list for the child account does not show the deletion.
- You can't delete an object or record in a lookup relationship if the combined number of records between the two linked objects is more than 100,000. To delete an object or record in a lookup relationship, first delete an appropriate number of its child records.
- Hierarchical
- This type of relationship is a special lookup relationship available only for the user object. It allows users to use a lookup field to associate one user with another that does not directly or indirectly refer to itself. For example, you can create a custom hierarchical relationship field to store each user's direct manager.
19. How to create many to many relationships
between object?
Creating many to many relationship in salesforce is little
tricky. You cannot create this type of relationship directly. Follow below
steps to create this type of relationship.
Create both objects which should be interlinked.
Create one custom object (also called as junction
object), which should have
autonumber as unique identification and create two master relationships for both objects, no need create tab for this
object.
Now on both object, add this field as related list.
In Interview for the salesforce technology, one common question asked
is how to implement the many to many relationship. If we answer that
using junction object then there next question comes
how ? explain it and after that, next question will be what happen if i
delete one master record ?So, in this article i will first show you that how to create custom objects, how to relate them and what will happen if we delete master or child?
here i am going to assume that we want to relate A and B. Let us assume that we have two custom object - A and B.
To provide the many to many relationship between A and B, we will need to create one more object let’s say it would be C, it will be called as junction object.
So, start with creating Object A.
In same way, as shown in above image create B and C. For the simplicity of the example i have not added any field in Object A and B. By default Name field is provided by the salesforce on all objects.
We are going to use the object C as a junction object for A and B.
on object C, create “first Master-Detail” field and select object A as parent. This will be Primary Master – Detail relationship.
In next screen give the name of the field.
for the Master record A, i have used name “ChildOfA” and in same way for the Master record B – i used “ChildOfB”.
Untill now, we have created two fields on object C in which one refer to master record A and other will refer master record B as shown in below screen. Now we can create a tab for all the custom objects to add the record. First create record for A then B and for record C screen will look like below snap.
Few important points (Interview Questions of salesforce ):
- One Object can have only two Master-Detail relationships.
- If we delete record A (First Master detail relationship is always primary) – then child record c will be deleted.
- If we delete record B then in this case also child record C will be deleted.
- If we delete record c then only C will be deleted , master record will not be deleted.
| To create a many-to-many relationship: | “Customize Application” |
You 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, you 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. When modeling a many-to-many relationship, you use a junction object to connect the two objects you want to relate
to each other.
- Junction Object
- A custom object with two master-detail relationships. Using a custom junction object, you can model a “many-to-many” relationship between two objects. For example, you 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.
Creating the many-to-many relationship consists of:
- Creating the junction object.
- Creating the two master-detail relationships.
- Customizing the related lists on the page layouts of the two master objects.
- Customizing reports to maximize the effectiveness of the many-to-many relationship.
Creating the Junction Object
To create the junction object:
- From Setup, click .
- Click New Custom Object.
- In the custom object wizard, consider these tips specifically
for junction objects:
- Name the object with a label that indicates its purpose, such as BugCaseAssociation.
- For the Record Name field, it is recommended that you use the auto-number data type.
- Do not launch the custom tab wizard before clicking Save. Junction objects do not need a tab.
Creating the Two Master-Detail Relationships
To create the
two master-detail relationships:
- Verify that the two objects you want to relate to each other already exist. For example, you may want to relate the standard case object to a custom bug object.
- On the junction object, create the first master-detail relationship
field. In the custom field wizard:
- Choose Master-Detail Relationship as the field type.
- Select one of the objects to relate to your junction object. For
example, select Case. The first master-detail relationship you create on your junction object becomes the primary relationship. This affects the following for the junction object records:
- Look and feel: The junction object's detail and edit pages use the color and any associated icon of the primary master object.
- Record ownership: The junction object records inherit the value of the Owner field from their associated primary master record. Because objects on the detail side of a relationship do not have a visible Owner field, this is only relevant if you later delete both master-detail relationships on your junction object.
- Division: If your organization uses divisions to segment data, the junction object records inherit their division from their associated primary master record. Similar to the record ownership, this is only relevant if you later delete both master-detail relationships.
- Select a Sharing Setting option. For master-detail relationship fields, the Sharing Setting attribute determines the sharing access that users must have to a master record in order to create, edit, or delete its associated detail records.
- For the Related List Label that will display on the page layout of the master object, do not accept the default. Change this to use the name of the other master object in your many-to-many relationship. For example, change this to Bugs so users will see a Bugs related list on the case detail page.
- On the junction object, create the second master-detail relationship.
In the custom field wizard:
- Choose Master-Detail Relationship as the field type.
- Select the other desired master object to relate to your junction object. For example, select Bug.
- Select a Sharing Setting option. For master-detail relationship fields, the Sharing Setting attribute determines the sharing access that users must have to a master record in order to create, edit, or delete its associated detail records.
- For the Related List Label that will display on the page layout of the master object, do not accept the default. Change this to use the name of the other master object in your many-to-many relationship. For example, change this to Cases so users will see a Cases related list on the bug detail page.
Customizing Many-to-Many Relationship Related Lists
For a many-to-many relationship in Salesforce, each master
object record displays a related list of the associated junction object
records. To create a seamless user experience, you can change the
name of the junction object related list on each of the master object
page layouts to have the name of the other master object. For example,
you might change the BugCaseAssociations related list to Cases on the bugs page layout and to Bugs on the cases page layout. You can further customize these related
lists to display fields from the other master object.
To customize the fields that display in the
junction object related list on each master object page layout:
- Edit the page layout of each master object that is related to the junction object. For example, to modify the BugCaseAssociations related list for case records, edit the page layout for cases from Setup by clicking .
- Edit the properties of the related list you want to modify. For example, on cases the BugCaseAssociations related list was renamed to Bugs, so select the Bugs related list.
- Add the fields to display in the related list. You can add fields
from the junction object itself, but more importantly, you can add
fields from the other master object. Each field is prefixed with its object name in the popup window. In the related list itself, only fields from the junction object are prefixed with the object name; fields from the other master object are not.
Customizing Reports for Many-to-Many Relationships
Many-to-many relationships provide two standard
report types that join the master objects and the junction object.
The report types are:
- “Primary master with junction object and secondary master” in the primary master object's report category.
- “Secondary master with junction object and primary master” in the secondary master object's report category.
23. How to delete the users data from
Salesforce?
Ans : To delete the Users Data go to Setup | Administration Setup |
Data Management | Mass Delete Record, from there select the objects like
Account, Lead etc and in criteria select the users name and delete all records
of that user related to particular object.
24. How to restrict the user to see any
record, lets say opportunity?
Ans : set up opportunity sharing to be private. If both users
are admins or have view all records on opportunity, then that overrides
private sharing.
25. What is the difference between trigger.new
and trigger.old in Apex – SFDC?
Ans :
Trigger.new :
Returns a list of the new versions of the sObject records.
Note that this sObject list is only available in
insert and
update triggers, and the records can only be modified in
beforetriggers.
Trigger.old :
Returns a list of the old versions of the sObject records.
Note that this sObject list is only available in
update and
delete triggers.
26. How to restrict any Trigger to fire only
once ?
Ans:
Triggers can fire twice, once before workflows and once after
workflows, this is documented at
Triggers and Order of Execution
When you save a record with an insert, update,
or upsert statement, Salesforce performs
the following events in order.
On the server, Salesforce:
- Loads the original record from the database or initializes the record for an upsert statement.
- Loads the new record field values from the request and overwrites
the old values.If the request came from a standard UI edit page, Salesforce runs system validation to check the record for:Salesforce doesn't perform system validation in this step when the request comes from other sources, such as an Apex application or a SOAP API call.
- Compliance with layout-specific rules
- Required values at the layout level and field-definition level
- Valid field formats
- Maximum field length
- Executes all before triggers.
- Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
- Saves the record to the database, but doesn't commit yet.
- Executes all after triggers.
- Executes assignment rules.
- Executes auto-response rules.
- Executes workflow rules.
- If there are workflow field updates, updates the record again.
- If the record was updated with workflow field updates, fires before and after triggers one more time (and only one more time), in addition to standard validations. Custom validation rules are not run again.
- Executes escalation rules.
- If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
- If the parent record is updated, and a grand-parent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Grand-parent record goes through save procedure.
- Executes Criteria Based Sharing evaluation.
- Commits all DML operations to the database.
- Executes post-commit logic, such as sending email.
Additional Considerations
Please
note the following when working with triggers.
- The order of execution isn’t guaranteed when having multiple triggers for the same object due to the same event. For example, if you have two before insert triggers for Case, and a new Case record is inserted that fires the two triggers, the order in which these triggers fire isn’t guaranteed.
- When Enable Validation and Triggers from Lead Convert is selected, if the lead conversion creates an opportunity and the opportunity has Apex before triggers associated with it, the triggers run immediately after the opportunity is created, before the opportunity contact role is created. For more information, see “Customizing Lead Settings” in the Salesforce online help.
-
If you are using before triggers to set Stage and Forecast Category for an opportunity record, the behavior is as follows:
- If you set Stage and Forecast Category, the opportunity record contains those exact values.
- If you set Stage but not Forecast Category, the Forecast Category value on the opportunity record defaults to the one associated with trigger Stage.
- If you reset Stage to a value specified in an API call or incoming from the user interface, the Forecast Category value should also come from the API call or user interface. If no value for Forecast Category is specified and the incoming Stage is different than the trigger Stage, the Forecast Category defaults to the one associated with trigger Stage. If the trigger Stage and incoming Stage are the same, the Forecast Category is not defaulted.
- If you are cloning an opportunity with products, the following
events occur in order:
- The parent opportunity is saved according to the list of events shown above.
- The opportunity products are saved according to the list of events shown above.
- Trigger.old contains a version of the objects before the specific update that fired the trigger. However, there is an exception. When a record is updated and subsequently triggers a workflow rule field update, Trigger.old in the last update trigger won’t contain the version of the object immediately prior to the workflow update, but the object before the initial update was made. For example, suppose an existing record has a number field with an initial value of 1. A user updates this field to 10, and a workflow rule field update fires and increments it to 11. In the update trigger that fires after the workflow field update, the field value of the object obtained from Trigger.old is the original value of 1, rather than 10, as would typically be the case.
&#160;
“The before and after triggers fire one more time only if something
needs to be updated. If the fields have already been set to a value, the
triggers are not fired again.”
Workaround:
Add a static boolean variable to a class, and check its value
within the affected triggers.
|
1
|
public class HelperClass
{
| |
|
2
|
public static boolean firstRun
= true;
| |
|
3
|
}
| |
|
4
|
trigger
affectedTrigger on Account (before delete, after delete, after undelete) {
| |
|
5
|
if(Trigger.isBefore){
| |
|
6
|
if(Trigger.isDelete){
| |
|
7
|
if(HelperClass.firstRun){
| |
|
8
|
Trigger.old[0].addError('Before
Account Delete Error');
| |
|
9
|
HelperClass.firstRun=false;
| ||
|
10
|
}
| ||
|
11
|
}
| |
|
12
|
}
| |
|
13
|
}
|
27. What is difference between WhoId and
WhatId in the Data Model of Task ?
Ans :
WhoID refers to people things. So that would be typically a Lead
ID or a Contact ID
WhatID refers to object type things. That would typically be an Account ID or an Opportunity ID
WhatID refers to object type things. That would typically be an Account ID or an Opportunity ID
28. Where is the option of the report for the
“Custom Object with related object” and what are the condition to generate
related reports?
Ans :
Ans :
If the parent object is the standard object provided by the
salesforce like “Account”, “Contact” then the report will be in there section
with related custom object.
If both objects are the custom then the report will be in “Other Reports” Sections.
If both objects are the custom then the report will be in “Other Reports” Sections.
Following are the conditions to get the report of related
objects:
·
On both the objects, Reports option must be enable.
·
The relationship between both of them must be “Master – detail
relationship”.
Very often it is observed that after creating the custom object
which is related to other object, developers get surprise that where is
the report option for my object with that custom object.
When creating a custom object, you can use the “Relationships” section to define relationships between this new object and other objects. For example let’s say you have a new object called “Expense” that you want to attach to an “Account“.
When you check the “enable reports” box and you go to the report wizard where you choose the type of data you want to report on, after the standard sections like “Accounts & Contacts”, ”Opportunities”, ”Administrative Reports” you’ll see a new section for “Other Reports”. When you choose that section you’ll see an “Expenses” report type only.
However, if you want to see a report linking “Expenses with Accounts” see below:
Lets take the example of our previously created application of the “Student and Courses“, in which course is the parent object.When creating a custom object, you can use the “Relationships” section to define relationships between this new object and other objects. For example let’s say you have a new object called “Expense” that you want to attach to an “Account“.
When you check the “enable reports” box and you go to the report wizard where you choose the type of data you want to report on, after the standard sections like “Accounts & Contacts”, ”Opportunities”, ”Administrative Reports” you’ll see a new section for “Other Reports”. When you choose that section you’ll see an “Expenses” report type only.
However, if you want to see a report linking “Expenses with Accounts” see below:
- Ensure that the relationship between accounts and expenses is a master-detail relationship.
- Look for the “Accounts with Expenses” report in the Accounts & Contacts section, not the “Other Reports” section because Account is the Parent object.
As the parent object is not the standard object, in this case the report will be in the “Other reports” section as shown in below image.
Hi hope, this article will help to find the cause and solution that where is the custom objects report in salesforce.
No comments:
Post a Comment