You may be wondering that there are tons of articles available for upsert operation and what is need of one more blog post. I wanted to note everything important about upsert operations using datalaoder and Apex with identified gotchas at single place, and that’s why its here .
External ID is field in Salesforce to say that this field is primary key in external Database which can be used to identify that external record exists in Salesforce or not ? There are many benefits of external key like :
- It can be used to identify if record exists or not and record automatically inserted or updated using upsert operation
- Upsert operation is supported by Dataloader, Apex and API
- Any field marked as external id is indexed and can be used in SOQL or report filter
- You can create Parent child record in single statement in Apex
Using Upsert operation to create/update child record and relate to existing parent record with help of External Id
Lets assume that you have list of contacts and Account in external SQL Server database and you want to import those Account and contact weekly. It is possible that you have already imported contacts previously so don’t want to duplicate records if already created in Salesforce. To solve this problem we can use external Id on Contact and use upsert operation on dataloader. Let’s assume external Id field on Contact is “SQL_Server__Id__c” (I am assuming that Account records in Salesforce also have external Id and records are already imported. Same below steps can be used to import Account record as well). Continue reading
In this article, we discussed how to use GIT with Eclipse.
I have created Video Tutorial for same which includes
- How to Upgrade Eclipse from Helios to Indigo
- Install EGIT Plugin
- Introduction to Bit Bucket
There are situations where the business requirement is too complex and standard sharing rules provided by the Salesforce will not work.
Example: On Opportunity, you want to give access to record to some users which are in related list.
One way is to manually share the record which will need the interference of opportunity owner. But everyone will love automated solution.
Apex managed sharing provides developers with the ability to support an application’s particular sharing requirements programmatically via Apex code.
The object’s organization-wide default access level must not be set to the most permissive access level. For custom objects, this is Public Read/Write. For more information, see Access Levels. This object is used for creating Apex based sharing.
The user to which the record going to be shared must have the object level permission. If you are trying to share the record with edit permission but user does not have the edit permission on that object, then it will not work.
To access sharing programmatically, you must use the share object associated with the standard or custom object for which you want to share. For example, AccountShare is the sharing object for the Account object, ContactShare is the sharing object for the Contact object, and so on. In addition, all custom object sharing objects are named as follows, where MyCustomObject is the name of the custom object: “MyCustomObject__Share”.
Objects on the detail side of a master-detail relationship do not have an associated sharing object. The detail record’s access is determined by the master’s sharing object and the relationship’s sharing setting.
In this article I want to share the custom object “Test__c” with students. Let’s consider that every “Test” has lookup to the “Student”. Continue reading
In a web development PHP has prooved itself as one of the major contributor in the world. There are lots of websites which are built over the PHP and the best example is facebook. PHP is very powerfull, easy to learn and the best thing is that it is open source.
Following the popularity of PHP, salesforce has also started providing support to PHP and delivered the Toolkit for it. Using this toolkit we can connect with salesforce and perform all API operations supported like Insert, update, delete, retrieve etc.
Download Salesforce PHP Toolkit Example – Zip Continue reading
On 24th April 2012, There was Apex code chat conducted by the Salesforce. So i thought to share important question and answers of that chat. You can read complete chat here.
Here are some of the (edited) highlights from this episode’s chat transcript.
Question: Is there a way in Apex to send an email and replace the default from email address (email@example.com)?
Ans: Yes, using either the setSenderDisplayName or setOrgWideEmailAddressID methods on the SingleEmailMessage or MassEmailMessage classes.
Question: Which fields are accessible in a Trigger.new record without performing a SOQL query? For example if my trigger is on the Contact object, are fields on the parent Account object (like Account Description) accessible without performing an explicit SOQL query?
Ans: You can use Trigger.new to access all non-null fields of the object on which the trigger is defined. You have to perform an explicit SOQL query to access any fields on associated parent or child records. For example, if the trigger is defined on Contact, you can only access the Id of the parent Account record (via AccountId) in Trigger.new. You’d need to perform a separate SOQL query to access any other field on the parent Acccount record (e.g. Description, Industry etc.). Continue reading
Although this is very common approach and lots of articles are around on this topic, still I want to delineate the topic in other way. This topic covers complete scenarios for the approval process based on the Apex class.
Agenda of this article:
- Automatically submit the record for approval on the basis of field value.
- Automatically select the next Approver.
- Approve / Reject the record on the basis of field.
- Opportunity Object is used.
- Approval Process is already set on the Opportunity.
- Field “Next_Approver” will decide that who is going to approve the record.
- There are three steps in the approval process.
- There is no test class written and no check for mandatory fields needed for the trigger, as I have considered positive scenarios only.
API of Approval Process classes:
- Apex process
- Apex ProcessRequest
Steps of Standard approval process defined:
Approval Process Steps
40. What is Master Detail relationship and look up relationship in Salesforce?
Master Detail relationship is the Parent child relationship. In which Master represents Parent and detail represents Child. If Parent is deleted then Child also gets deleted. Rollup summary fields can only be created on Master records which will calculate the SUM, AVG, MIN of the Child records.
Look up relationship is something like “has-a” (Containership) relationship. Where one record has reference to other records. When one record is deleted then there is no impact on other records.
41. Can we convert the lookup relationship to Master Detail relationship?
We can convert the lookup relationship to master detail relationship if and only if all the existing record has valid lookup field.
42. In How many way we can invoke the Apex class?
- Visualforce page
- Web Services
- Email Services
In this article, I will explain the code which can be used for connecting and getting the records from different or multiple salesforce organization using Apex and REST Service.
Note : Here is new article to connect two salesforce instances in just 5 lines of code using Named Credentials.
To start first we will need to authorize below two URL which can be accessed from salesforce environment.
This can be done from “Setup | Administration Setup | Security Controls | Remote Site Settings”
Salesforce Remote Site Setting
What is an Email service in Salesforce?
Email services are automated processes that use Apex classes to process the contents, headers, and attachments of inbound email.
You can associate each email service with one or more Salesforce-generated email addresses to which users can send messages for processing.
The general template to create the apex class for the email services is:
How Email Services works in Salesforce