Deep dive into Junction object – Create many to many relationship in Salesforce

Article to show step by step process of creating junction object for Many to Many relationship in salesforce and impact of deleting one master record on others

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.

Creating Custom object in salesforce
Creating Custom object in salesforce

Continue reading “Deep dive into Junction object – Create many to many relationship in Salesforce”

Create a custom Web service in Salesforce and consume it in C#.Net application

In this tutorial, we will create the web service in salesforce and consume it in c#.Net application

In Previous article, we have consumed the standard enterprise wsdl of the salesforce. In this article we will create the webservice using apex in salesforce and consume it in C#.Net application.

In Salesforce create below class (using force.com IDE)

global public with sharing class SaveExpenditureWebService {

	webservice static Expenditure__c createExpenditure(Decimal amount,String expName, String paidByName )
	{
		Expenditure__c c = new Expenditure__c();
		Person__c p = [Select p.Name From Person__c p Where Name = :paidByName limit 1];
		c.Amount__c = amount;
		c.Name = expName;
		c.Exp_Date__c = Date.today();
		c.Paid_By__c = p.Id;
		insert c;

		return c;
	}
}

Note:

  • Apex class in which webservice is going to be written must be declared “global“.
  • Keyword “webservice“ must be used for a method which should be exposed as a webservice.
  • Method must be declared as static.

In above code, I am using a custom object “Expenditure__c“ to insert into Salesforce.  Any type of code can be written.
Now in C#, create windows application with following controls:

Create Custom web service in salesforce using apex and consume using C#.Net
Create Custom web service in salesforce using apex and consume using C#.Net

Continue reading “Create a custom Web service in Salesforce and consume it in C#.Net application”

Consume Salesforce Web service in C# .Net Application

Author posted by Jitendra on Posted on under category Categories c#, Salesforce and tagged as Tags , with 14 Comments on Consume Salesforce Web service in C# .Net Application

This tutorial is the demonstration of how to consume the web service from salesforce.

In this example, we are going to consume the enterprise WSDL of the Salesforce in C# application.

Log into the Salesforce and navigate to “Your Name | Setup | App Setup | Develop | API” and select the “Generate Enterprise WSDL”.  Copy the URL, as we will need this in our C# Application.

Now Open Visual Studio (I am using Visual Studio 2010) and create new Windows Application. The UI of the application should look like:

C# Application to consume salesforce webservice
C# Application to consume salesforce webservice

Right click on the “References“ folder and select “Add Service Reference“.

Add Service Reference in C#
Add Service Reference in C#

Continue reading “Consume Salesforce Web service in C# .Net Application”

Where are the reports for my custom object with related objects in salesforce?

Where are the reports for my custom object with related objects in salesforce?

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“. Continue reading “Where are the reports for my custom object with related objects in salesforce?”

Override standard Links with VisualForce pages in Salesforce

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags with 7 Comments on Override standard Links with VisualForce pages in Salesforce

Demonstration of Overriding standard Links with VisualForce pages in Salesforce

overriding existing salesforce page with your own page is one of the advantages offered by salesforce.com. In this article i will demonstrate that how we can override existing Contact page with our custom contact page.

Go to Set up | Develop | Pages and create new Visual force page with below code.

<apex:page standardController="Contact" tabStyle="Lead">
<apex:pageBlock title="My Contact Details">
<p>Hello {!contact.FirstName}</p><br>
<i>Developed by : <b>Jitendra Zaa </b></i></br> <br>
<i>This is the customPage developed</i></br>
<apex:form >
<apex:inputField value="{!contact.addit__c}"/>
</apex:form>
</apex:pageBlock>
<apex:detail relatedList="false" />
</apex:page>

The above code will only display one textbox (Custom textbox field created by me). Continue reading “Override standard Links with VisualForce pages in Salesforce”

Lead convert problem in Salesforce

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags with 5 Comments on Lead convert problem in Salesforce

Lead convert problem in Salesforce if the fields in Account, contact, opportunity are mandatory and not available in Lead

Many of salesforce programmer face problem while converting the Lead into Accounts, Contact, Opportunities and followup tasks.

Normally the reason is custom field created by you in any of above which is mandatory and not present in Lead.

For example in Below screen:

Lead Conversion error in salesforce
Lead Conversion error in salesforce

The error is caused because of field Phone extention in Account which is mandatory.

Continue reading “Lead convert problem in Salesforce”

Create and manage Assignment rules in Salesforce

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , with 11 Comments on Create and manage Assignment rules in Salesforce

What is assignment rule in salesforce.com, how to create and manage assignment rules in SFDC

Assignment rules are used to automate your organization’s lead generation and support processes.

  • Lead Assignment Rules – Specify how leads are assigned to users or queues as they are created manually, captured from the web, or imported via the lead import wizards.
  • Case Assignment Rules – Determine how cases are assigned to users or put into queues as they are created manually, using Web-to-Case, Email-to-Case, On-Demand Email-to-Case, the Self-Service portal, the Customer Portal, Outlook, or Lotus Notes.

Aim : All the cases created by user ‘jZaa’ should be assigned to ‘Jitendra Yahoo’.

To create this Assignment rule, go to Setup | App Setup | Cases | Assignment Rules and on right hand side click on New.

In first step, give the assignment rule name, lets say name is ‘to jitendra Yahoo’. You may have noted the check box which says “Set this as the active case assignment rule” click on this.

Continue reading “Create and manage Assignment rules in Salesforce”

Salesforce Interview Questions – Part 3

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags , , with 29 Comments on Salesforce Interview Questions – Part 3

Most Frequently Asked interview questions of Apex, Visual force, SOQL in Salesforce.com SFDC

20. In Which sequence Trigger and automation rules run in Salesforce.com

Ans : The following is the order Salesforce logic is applied to a record.

  1. Old record loaded from database (or initialized for new inserts)
  2. New record values overwrite old values
  3. System Validation Rules
  4. All Apex “before” triggers
  5. Custom Validation Rules
  6. Record saved to database (but not committed)
  7. Record reloaded from database
  8. All Apex “after” triggers
  9. Assignment rules
  10. Auto-response rules
  11. Workflow rules
  12. Escalation rules
  13. Parent Rollup Summary Formula value updated (if present)
  14. Database commit
  15. Post-commit logic (sending email)

Additional notes: There is no way to control the order of execution within each group above.


21. If one object in Salesforce have 2 triggers which runs “before insert”. Is there any way to control the sequence of execution of these triggers?

Ans : Salesforce.com has documented that trigger sequence cannot be predefined. As a best practice create one trigger per object and use comment blocks to separate different logic blocks. By having all logic in one trigger you may also be able to optimize on your SOQL queries.


22. How to delete the User from Salesforce?

Ans : As per now, salesforce does not allow to delete any user, however you can deactivate the user.

Read further…


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 before triggers.

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 OR how we can avoid repeated or multiple execution of Trigger?

Ans:

Triggers can fire twice, once before workflows and once after workflows, this is documented at

http://www.salesforce.com/us/developer/docs/apexcode/ Content/ apex_triggers_order_of_execution.htm:

“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.

public class HelperClass {
   public static boolean firstRun = true;
}
trigger affectedTrigger on Account (before delete, after delete, after undelete) {
    if(Trigger.isBefore){
        if(Trigger.isDelete){
            if(HelperClass.firstRun){
                Trigger.old[0].addError('Before Account Delete Error');
                HelperClass.firstRun=false;
            }
        }
    }
}

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

Check Data Model of task here


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 :

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.

Following are the conditions to get the report of related objects:

  • On both the objects, Reports option must be enable.
  • Both object must be related either using Lookup or Master Detail type of field.

Read this article, to get detailed idea on this topic.


29. How you can provide the User Login (Authentication) in Public sites created by Salesforce.

Answer : We can provide the authentication on public sites using “Customer Portal”.


Roll up Summary fields in Salesforce

Author posted by Jitendra on Posted on under category Categories Salesforce and tagged as Tags with 10 Comments on Roll up Summary fields in Salesforce

What is Roll up summary field in salesforce, what are the types of roll up summary field and how does it works

To study the Roll up Summary field of salesforce, lets take example from our previous tutorial series

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:

  1. Count
  2. Sum
  3. Min
  4. Max

Continue reading “Roll up Summary fields in Salesforce”

Step by Step Salesforce Tutorial – Creating Trigger and Test cases – 6 of 6

Step by Step Salesforce Tutorial – Creating Trigger and test cases – 6 of 6 tutorials series

This is the last tutorial in series and we will see that how to create a Trigger and Test Cases in salesforce.

A trigger is an Apex script that executes before or after specific data manipulation language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.

Triggers are stored as metadata in Salesforce.com. A list of all triggers in your organization is located at SetupDevelopApex Triggers. In addition to this list, triggers are associated and stored with specific objects.

To define a trigger:

Continue reading “Step by Step Salesforce Tutorial – Creating Trigger and Test cases – 6 of 6”