Friday, June 24, 2016

How To Write a SOQL To Fetch All Events Related to Account and Opportunity

Scenario:

Usually when we are writing any kind of SOQL queries on related objects we always known that this particular child record always be linked to specified parent object record. For example if you have a relationship between Account(Parent) and Contact(child) that means every contact record is related any one the account record not to any ABC__c or BCD__c objects.

But where in case of Task or Events if you could see we can't guarantee that these Tasks or Events are always related to a Account records or Contact Records because these Task or Events can be linked to any one of the Contract,Campaign,Account,Opportunity,Product,Asset,Case,Solution,Quote and Any Custom Objects .

Question:
In such type of situations the Task or Event that is linked to which object it's not a static and it's gets varies based on the Event that your creating for which object(Called as Polymorphic Relationship).Now If you want to fetch all Events related to Account and Opportunity only.How we need to write a SOQL query ?



Solution:

We already know that WhatId filed in Event or Task for deciding for which object this is linked /created.So with the help of TYPE qualifier on WhatId we can achieve this.The TYPE qualifier on field always determine the object type that is referenced for Task or Event.Use this TYPE clause on where condition of SOQL to control the result.

SELECT Id,subject,What.Type,whatId 
FROM Event
WHERE What.Type IN ('Account', 'Opportunity')

This above SOQL query returns all the Events related to Account and Opportunity only.


You can also apply comparison operators such as '=' or LIKE on WHERE condition of TYPE clause .


[SELECT Id,subject,What.Type,whatId 
FROM Event
WHERE What.Type like '%Accou%']

[SELECT Id,subject,What.Type,whatId 
FROM Event
WHERE What.Type ='Position__c']

They are multiple other ways also to do same.So we will discuss all those things in my next post.

Thanks for visiting...Enjoy!!!


What is Polymorphic Relationship in Salesforce ?

We are all very familiar with relationships in Salesforce right? Usually when we are discussing about relationships in salesforce immediately in our mind below listed relationship will appears

  • Lookup Relation Ship (Many-One relationship)
  • Master-detail Relationship  (Many-One relationship)
  • Many-to-Many Relationship
  • Self Relation Ship
But apart from this in salesforce we have one more relationship called Polymorphic Relationship.In all the above relationship (except Polymorphic Relationship) we always know that this particular child record always be linked to specified parent object record. For example if you have a relationship between Account(Parent) and Contact(child) that means every contact record is related any one the account record not to any ABC__c or BCD__c objects.

But where in case of Task or Events if you could see we can't guarantee that these Tasks or Events are always related to a Account records or Contact Records because these Task or Events can be linked to any one of the Contract,Campaign,Account,Opportunity,Product,Asset,Case,Solution,Quote and Any Custom Objects .These types of relationships is called as Polymorphic Relationship.In Polymorphic Relationship the referenced object of relationship can be any one of the Standard or Custom Objects.

Linking an attachment to any one of the custom object or standard object with the help of the Parent Id also refereed as Polymorphic Relationship only.

When your working with Polymorphic Relationship objects in SOQL we have several ways to access.

Follow my next to post to learn how to use this Polymorphic Relationship in SOQL.


Thanks for visiting....Enjoy!

Wednesday, June 22, 2016

25 Basic Deployment or Test Classes Issues During Deployment in Salesforce

1.System.DmlException: ConvertLead failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []

2.System.NullPointerException: Argument 1 cannot be null

3.System.LimitException: Too many SOQL queries: 101

4.System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SampleTrigger: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a4980000001paQSAAY; first error:

5.first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SampleTrigger: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.SampleTrigger: line 181, column 1: [] Trigger.ChildTrigger: line 85, column 1 Trigger.ChildTrigger: line 50, column 1: []

6.System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OrderRequest: execution of AfterInsert caused by: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process was found.: [] Trigger.OrderRequest: line 81, column 1: []

7.System.LimitException: Too many query rows: 50001

8.No such column 'Unique_Key__c' on entity 'End_Date_Ruleset__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

9.This custom field is referenced elsewhere in salesforce.com. : Field Updates.

10.Field Project_Quarter__c does not exist. Check spelling.

11.In field: field - no CustomField named Job_Profile__c.ID_to_get_cluster_value__c found

12.An object 'Lead-ETS/WMI Lead Page Layout' of type Layout was named in package.xml, but was not found in zipped directory

13.An object 'Lead.IsUKCreatedLead__c' of type CustomField was named in package.xml, but was not found in zipped directory

14.System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Update failed. First exception on row 0 with id 00Q8000001e17G8EAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateAcctShippingAddr: execution of AfterUpdate caused by: System.LimitException: Too many SOQL queries: 101

15.Fatal Error null: The changes you requested require salesforce.com to temporarily lock your organization's administration setup. However, the administration setup has already been locked by another change. Please wait for the previous action to finish, then try again later.

16.Invalid field Billing_Email__c for SObject Account

17.System.QueryException: List has no rows for assignment to SObject

18.Stack Trace: Class.SendEmailQuote.generateEmailBody: line 941, column 1 Class.SendEmailQuote.<init>: line 151, column 1 Class.TestSendEmailQuote.Test1: line 73, column

19.Cannot update a field to a Lookup, MasterDetail, or Hierarchy from something else

20.Apex class 'QuoPDF_US' does not exist

21.Dependent class is invalid and needs recompilation: QuoPDF_US: line 58, column 20: Invalid type: Sales_Cond_Type__c

22.Invalid type: Sales_Type__c

23. new_quote does not exist or is not a valid override for action New.

24. Field is not writeable: Service_Order__c.CreatedById

25. Code Coverage Failure Your code coverage is 74%. You need at least 75% coverage to complete this deployment.


Thanks for visiting...Enjoy!

Method only allowed during testing" Error in Test Classes

Issue:

Lets take an example where you have a test class which contains Test.startTest() and Test.stopTest() methods and you have more than one test method in test class.When you run this test class in any way it touches any class that implements the Queueable interface your test classes methods more than one will fails

WorkAround:

Split all your test class methods into individual test class in salesforce. For more information please refer salesforce known issues page 


Thanks for visiting...Enjoy!

Issue with action support function on select of select list values

Today we had an issue with selection of pick-list. I am just trying to invoke a controller method when a user selects a pick list value from drop down and we are using an <apex:actionSupport> to make a call to the controller and the event is onchnage on onselect but unfortunately we are not able to make a call to controller method and the actionsupport with onselect or onchange in not working along with rerender also.



After a multiple hours of surfing over the internet we got some suggestion that just replace the onselect or onchnage with onclick event then it is started working and then after again reverted back to onselect or onchange now I'm able to make a call to controller method .I am not sure why is it working like that.

If you people are also facing the same issue just replace the your event onselect or onchange with onclick and try to invoke a controller method and if it's able to make a call to controller then again revert the onclick with onselect or onchange.

Thanks for visiting....Enjoy!



INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: Name: [Name]

When your working with Person Accounts in Salesforce we should be very careful because these Accounts can also acts as a Contact .It means these person accounts will share many fields with contacts.

The Person Account name will contains First Name and Last Name .When your trying to load any Person Accounts with data loader or with any other apex code we should follow some naming conventions .If your trying to map these field values to Name field of Account we will end up with the same error.

So when your loading the Person Accounts data your .csv file must contain a columns FirstName and LastName but not only the Name.

For more information visit Salesforce Document here 

Thanks for visiting....Enjoy!




Difference between WorkFlow and Process Builder in Salesforce

As we already know that we have a multiple options in Salesforce to make you business automation.Among all of them we usually goes with workflow before Lighting Process Builders comes into the picture visit my post for more info.But now we have a multiple actions are available on Process builder compared to workflow.

This post will explains you the differences between workflow and Process Builder and when we need to go with workflow and process builder.

Actions
WorkFlow
Process Builder
Task Creation
ü
ü
Email notification
ü
ü
Field Update
ü
ü
Outbound Message
ü
û
Create a record
û
ü
Invoke a Apex
û
ü
Invoke a Flow
û
ü
Post to Chatter
û
ü
Quick Actions
û
ü
Submit For Approval
û
ü
Update Child Records
û
ü
Cross object field updates
û
ü

For best practices of process builder please refer my previous post.


Thanks for visiting....Enjoy!

Monday, June 20, 2016

FIELD_INTEGRITY_EXCEPTION, Related To ID: id value of incorrect type: [WhatId]:

We have a trigger on some custom object and it would sent an email notification based on few changes to record.When we are sending an email with help of Messaging.SingleEmailMessage class and we are also using an email template so to populate the merge fields in template we are setting the whatId to custom object which full fills the merge fields in template but unfortunately we are end up with an below error



Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger SummaryTrigger caused an unexpected exception, contact your administrator: SummaryTrigger: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Related To ID: id value of incorrect type: a0JJ000000A6TDWMA3: [WhatId]: Class.SummaryTrigHandler.sendEmailNotification: line 101, column 1

Root Cause:
Even after I am setting the correct WhatId I am getting the same error .This issue is not related to object WhatId it's actually related to Activity record whatId.
Because by default the setSaveAsActivity has a value true, which saves the emailing as an activity so If your WhatId custom object not allowed for activity tracking then you will receive this error.

Solution:

  • So if your facing the same issue please goto object detail page (i.e.,the object that your setting as part of whatId) and enable the activities for the object
  • Change in your code like do not save the activity by setting the setSaveAsActivity as false Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  email.setSaveAsActivity(false)



Thanks for visiting....Enjoy!

Thursday, June 16, 2016

Scenario Based Salesforce Interview Questions

1. Is it possible to schedule a dynamic dashboard in Salesforce? 
 No
 Yes
2. Is check box performs like controlling field? 
 No
 Yes
3. A developer is loading data, in CSV format, into a custom application from a legacy system. The developer would like to load users into the user object and positions and job applications owned by named users into related custom objects. Which obstacle will the developer encounter when using the import wizard? 
 The import wizards do not support custom objects
 The import wizards do not support the User object
 The import wizards do not import files to specify record owner
 The import wizards cannot import data from CSV files
4. What is a capability of a Data Loader? (Choose 2 answers) 
 The Data Loader can be executed from the Command Line
 The Data Loader can de-duplicate records
 The Data Loader can bypass sharing model settings
 The Data Loader can load more than 50,000 records at a time
5. A custom object has an organization-wide default setting of Private with Grant Access Using Hierarchies turned off. Which users can select the Sharing button on records for that object? 
 Only the record owner and a user with the System Administrator Profile
 The record owner, a user with the System Administrator profile, and a user shared to the record
 The record owner, a user shared to the record, any user above the record owner
6. Object B has a lookup relationship to Object A. Object C has a lookup relationship to Object B. A developer needs to run a report on A records with C records. How can the developer accomplish this? 
 Create a custom report type that includes A with B with C
 Create a summary report with a custom summary formula summarizing by A, then B, then C
 Create a matrix report with A and record as column headings and C records as row headings
7. When performing an update with the Data Loader, the comma-delimited file must contain a column with which values? 
 The logical names of the records
 The profile names of the record owners
 The created time and date of the records
 The Force.com record ID values of the records
8. A user successfully login’s at 3:00 PM, What happens at 3:31 PM, if the Login hours for the user’s Profile is set from 7:30 AM to 3:30 PM?
 User is automatically Logged Out
 User keeps working continuously without any issues
 User is asked in a Popup window if he would like to extend his session
 User is logged out once he tries to do any DML (Data Manipulation) Operation
9. In a lookup relationship, what happens to the child records if the parent record is deleted? 
 Child records are deleted
 Child records are not deleted
 A subset of the child records are deleted
 Parent record deletion fails
10. What is the Impact on a User of the Organization level Locale Changes?
 The default Locale of the user is also set to the new Organization Level locale
 The User is asked for a Choice; if he would like to choose New Organization Locale or his own Locale
 No Impact on the User as he keeps using his own default Locale
11. Which of the following profile permissions will enables the User to edit any record, regardless of the Sharing Model? 
 Customize Application
 View Setup and Configuration
 View All Data
 Modify All Data
 None of the Above
12. Which of the following is the best way to make the Field Mandatory for everyone?
 Page Layout
 Validation Rule
 Roles & Profiles
 Field Level Security
13. Which Feature is not available in Salesforce.com? 
 Profile based Login Hours
 Profile based Login IP Ranges
 Organization based Login Hours
 Organization based Login IP ranges
14. Which of the following is not a Standard Salesforce.com Application?
 Service
 Sales
 Call Center
 Community
 Marketing
15. Which of the following is NOT a Standard Salesforce.com Functionality? 
 Email to Lead
 Email to Case
 Web to Lead
 Web to case
16. Which of the field types cannot be used as an External Id?
 Text Field
 Number Field
 Picklist Field
 Email Id Field
17. Which of the following cannot be on the controlling side of the Dependent Picklist? 
 Checkbox
 Custom Picklist
 Standard Picklist
 Multi Select Picklist
18. Do Validation rules get enforced on the Lead Conversion?
 Yes
 No
19. Which of the following profile permissions will enables the User to edit any record, regardless of the Sharing Model? 
 Customize Application
 View Setup and Configuration
 View All Data
 Modify All Data
 None of the Above
20. Is it possible for a user to see different Set of data in Report and in a Dashboard based on the same Report?
 Yes
 No
21. Which feature allows a user to group campaigns within a specific marketing program or initiative?
 Campaign hierarchy
 Campaign lists
 Campaign members
 Campaign influence
22. A sales executive at Universal containers wants to be notified whenever high-value opportunities are created for hot accounts. How should an administrator meet this requirement?
 Create the workflow rule on opportunity object
 Create an escalation rules based on the opportunity amount
 Create an auto-response rule based on the opportunity amount
 Create a validation rule that evaluates the account rating
23. Which circumstance will prevent a system administrator from deleting a custom field?
 The field is used in a page layout
 The field is used in a workflow field update
 The field is part of a field dependency
 The field is used in a report
24. What will occur when a system administrator creates a dynamic dashboard?
 The data displayed varies based on the user viewing the dashboard
 The dashboard component resize based on the device used to view the
 The dashboard automatically sends an email when the underlying data
25. What does a page layout allow an admin to control?
 The Fields users see on detail and edit pages
 The fields user see in reports and list views
 The record types available to each role and profile
 The business process and related picklist value displayed

For more interview question visit my post at here 

Thanks for visiting...Enjoy!




Business Questionnaires for Salesforce

  • Which edition of salesforce are you using?
  • How many user licenses do you have for your org?
  • What is the architecture of your system?
  • What are the different entities your company is involved with?
  • Do you make use of both sales and service cloud of salesforce for your business process?
  • What kind of product or service do you sell?
  • Who is the target audience for your system?
  • How long has the firm had a dedicated Salesforce practice?
  • How many Salesforce systems has it deployed?
  • Are you more into configuration (Admin) or customization (development)?
  • If you’re having sales cloud, do you have any existing lead management/routing systems?
  • In case if you are into service cloud, then do you have any existing case management system?
  • Do you have any existing account management, territory management, opportunity management in place?
  • How do you manage the campaigns for your company?
  • Are you looking for any CPQ (Configure - Price - Quote) implementation or do you have any existing system to handle the same?
  • Where do you maintain product catalogue?
  • How do you track contracts or service levels?
  • Are there any existing portals for your customers or business partners?
  • Do you have historical data available?
  • Do you have data analytical tool in place?
  • Have you started using Salesforce Lightning features?
  • How do you manage Version Control in salesforce?
  • Is there any integration with any third party systems?
  • What are the data relationships for your records that will be housed in Salesforce.com ?
  • Where does the data reside today?
  • Who owns the source data?
  • If some of the data will remain in an external system, how will Salesforce.com be updated (does in need to “sync” or integrate with a data warehouse or legacy system)?
  • How do you manage salesforce deployment process?
  • Do you follow waterfall model/agile methodology for the project implementation?
  • Are you using any automation tools for testing?
  • Do you have any existing test management tool to track the defects/bugs raised related to a salesforce application?

Thanks for visiting...Enjoy!

Monday, June 13, 2016

Sample package.xml Manifest Files for all types in Salesforce Ant

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>AccountCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>AccountOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomApplication</name>
    </types>
    <types>
        <members>*</members>
        <name>AppMenu</name>
    </types>
    <types>
        <members>*</members>
        <name>ApprovalProcess</name>
    </types>
    <types>
        <members>*</members>
        <name>AssignmentRule</name>
    </types>
    <types>
        <members>*</members>
        <name>AuthProvider</name>
    </types>
    <types>
        <members>*</members>
        <name>CallCenter</name>
    </types>
    <types>
        <members>*</members>
        <name>CampaignCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CampaignOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CaseCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CaseOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>*</members>
        <name>Community</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexComponent</name>
    </types>
    <types>
        <members>*</members>
        <name>ConnectedApp</name>
    </types>
    <types>
        <members>*</members>
        <name>ContactCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>ContactOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomApplicationComponent</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomObjectCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomObjectOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomPermission</name>
    </types>
    <types>
        <members>*</members>
        <name>Dashboard</name>
    </types>
    <types>
        <members>*</members>
        <name>DataCategoryGroup</name>
    </types>
    <types>
        <members>*</members>
        <name>Document</name>
    </types>
    <types>
        <members>*</members>
        <name>EmailTemplate</name>
    </types>
    <types>
        <members>*</members>
        <name>EscalationRule</name>
    </types>
    <types>
        <members>*</members>
        <name>FlexiPage</name>
    </types>
    <types>
        <members>*</members>
        <name>Flow</name>
    </types>
    <types>
        <members>*</members>
        <name>Group</name>
    </types>
    <types>
        <members>*</members>
        <name>HomePageComponent</name>
    </types>
    <types>
        <members>*</members>
        <name>HomePageLayout</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomLabels</name>
    </types>
    <types>
        <members>*</members>
        <name>Layout</name>
    </types>
    <types>
        <members>*</members>
        <name>LeadCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>LeadOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>Letterhead</name>
    </types>
    <types>
        <members>*</members>
        <name>Network</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomObjectTranslation</name>
    </types>
    <types>
        <members>*</members>
        <name>OpportunityCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>OpportunityOwnerSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexPage</name>
    </types>
    <types>
        <members>*</members>
        <name>PermissionSet</name>
    </types>
    <types>
        <members>*</members>
        <name>Portal</name>
    </types>
    <types>
        <members>*</members>
        <name>PostTemplate</name>
    </types>
    <types>
        <members>*</members>
        <name>Profile</name>
    </types>
    <types>
        <members>*</members>
        <name>Queue</name>
    </types>
    <types>
        <members>*</members>
        <name>QuickAction</name>
    </types>
    <types>
        <members>*</members>
        <name>RemoteSiteSetting</name>
    </types>
    <types>
        <members>*</members>
        <name>Report</name>
    </types>
    <types>
        <members>*</members>
        <name>ReportType</name>
    </types>
    <types>
        <members>*</members>
        <name>Role</name>
    </types>
    <types>
        <members>*</members>
        <name>Scontrol</name>
    </types>
    <types>
        <members>*</members>
        <name>Settings</name>
    </types>
    <types>
        <members>*</members>
        <name>SharingSet</name>
    </types>
    <types>
        <members>*</members>
        <name>SiteDotCom</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomSite</name>
    </types>
    <types>
        <members>*</members>
        <name>StaticResource</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomTab</name>
    </types>
    <types>
        <members>*</members>
        <name>ApexTrigger</name>
    </types>
    <types>
        <members>*</members>
        <name>UserCriteriaBasedSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>UserMembershipSharingRule</name>
    </types>
    <types>
        <members>*</members>
        <name>CustomPageWebLink</name>
    </types>
    <types>
        <members>*</members>
        <name>Workflow</name>
    </types>
    <version>31.0</version>
</Package>


Thanks for visiting...Enjoy!