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 “All about Upsert and External ID in Dataloader and Apex – Videos”
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.
Example of using PHP toolkit in Salesforce with Sample code
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.
Salesforce Apex Code talk on – 24-April-2012 , Important Interview Questions
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 (firstname.lastname@example.org)? 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 “Salesforce Apex Code talk – Important Questions and Answers”
This article explain the Automatic submission of Approval process using Apex and trigger. It include Automatic submission, approval as well as rejection of record completely using Apex and trigger.
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.
Basic concepts and Interview Questions of salesforce, Visualforce, Apex and SOQL
40. What is Master Detail relationship and look up relationship in Salesforce? Ans:
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? Ans:
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? Ans:
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”
Complete tutorial of Email services in Salesforce with simple step by step example
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: