Friday 18 July 2014

Relationships in Salesforce

Types of Relation ships in Salesforce:

 There are 3 types of Relation ships in Salesforce

1. Self Relation ship

2. One - to - Many Relation ship

     i) Master - Detail Relation ship

     ii) Look up Relation ship

3. Many - to - Many Relation ship


1. Self Relationship: If we are creating relation ship with the same object then that relationship is called as "Self Relation ship".

Ex: Student - custom object

i) Set up -> Build -> Create -> Objects -> Click on "Student" object -> Go to "Custom Fields & Relationship" section -> Click on "New"

ii) Select data type as "Look up Relationship " -> Select the object as "Student" and click on "Next"

iii) Finally "Save" it

2. One - to - Many Relationship:

Master - Detail Relationship:

i) If we delete record in the master object the corresponding child records will also deleted.

ii) The detail(child) record will not have the standard "Owner field" to change the owner of that record.

iii) The owner of the "Master" record will be the owner of "Detail" record.

iv) Sharing settings of "Master" object will be applicable to the "Detail" Object.

v) The master field is "Mandatory" field. With out giving value if we are trying to save the record,it will show the error message.

Eg: DepartmentNew - Custom Object (Master Object)

      EmployeeNew - Custom object (Detail Object)


Roll up Summary Field:

This data type is enabled only for the "Master Object"

If any custom object is acting as "Master object" to any other custom object. Only for that "Master object" this data type is "Enabled".

Roll summary field is a read only field. This is enable only for master object. With the help of roll up summary field we can know the count,sum,min & max of related list records.

count

max

min

sum

Only for the "DepartmentNew" object this "Roll up summary field" will be enabled.

Set up -> Build -> Create -> objects -> Click on the Master object(Eg:Deparment MD) -> Custom fields & Relation ship section -> New -> Select "Roll up summary field" -> Next -> Select object name in the "Summarized object" -> Choose the function -> Next -> Save.


Limitations of Master Detail Relation:

For one custom object, we can create only 2 Master-Detail relation ship with objects.

For one custom object,  we can create 20 look up relation ship with other object.

  i) 2 Master - details relation ship with other objects

  ii) 25 Look up relation ship with other objects.

Look Up Relationship:

i) This field is "Optional" field. With out giving value also we can save the record. It wont display the error message.

3. Many - to - Many Relationship:

To acheive many - to - many relation ship between two objects we have to create one intermediate object that object called as  "Junction object".

Steps to Many - to - Many Relationship:

i) Students
ii) Courses

Want to create Many - to - Many Relation ship between students and courses at that we need an intermediate object to achieve this relation ship. That intermediate object will call as  "Junction Object".
iii) Studying - Custom object (Through this acheiving Many-to-Many R.S between Students & Courses)

 i) set up ->  Build -> Create -> Objects -> Click on "Studying" object -> Click "New" in Custom Fields & Relationship section ->  Select Master-Detail Relation ship data type -> Next -> Select "Students" in the drop down -> Next -> Next -> Save

 ii) set up ->  Build -> Create -> Objects -> Click on "Studying" object -> Click "New" in Custom Fields & Relationship        section ->  Select Master-Detail Relation ship data type -> Next -> Select "Courses" in the drop down -> Next -> Next -> Save
 
 2 fields:

    i) Master - detail relation ship (Student) - Primary relation ship

    ii) Master - detail relation ship ( Courses) - Secondary Relation ship

Create Roles, Profiles, Users and Permission Sets

Roles, Profiles, Users & Permission Sets:

Roles: Role is nothing but designation in the organization.

Eg: Team Lead, Cashier

Creating Roles:

Set up -> Administer  -> Manage users -> Roles -> Set up Roles -> Add Role -> Enter the Role name.

Profiles: In the profile we will give the permissons for the customs applications,custom objects, administrative permissions , general permissions and tab visiblity.

The following settings will do in the profile:

1) Custom App Settings: Giving Permissions for the custom applications.

2) Stadard tab Settings 

3) Custom Tab Settings

  1) Default On : The tab will displayed ON,means displayed bydefault after logging on.

  2) Default off: The tab is not displayed in the home landing page.

  3) Tab Hidden: The tab will be hidden.

4) Administrative permissions:

5) General User Permissions

6) Standard object Permissions

7) Custom Object Permissions

Creating Profile:
Setup -> Administer  -> Manage Users -> Profile -> New Profile -> Select any existing profile in the above drop down (Eg: Standard Platform user) -> Enter the profile name.

Eg: "My Custom Profile" -> created one profile

Creating User:

 1) Role :  Project Manager

 2) Profile: My Custom Profile

Set up -> Administer -> Manage Users -> Users -> New User -> Enter all the mandatory fields values -> Save

Thursday 17 July 2014

Salesforce Interview Questions | Apex | Visualforce

1. In Data loader using upsert operation can u do update a record if that record id is already exist in page and if updated that record then can u update 2records with having same id and if not updated 2 records then wat error message is given?

It is not possible to update records with same id in a file usin upsert operation. It will throw "duplicate ids found" error.

2. One product cost is 1000. It is stored in invoice so once if change the cost of product to 800 then how can i update it automatically into a invoice?

We can achieve this using triggers or through relationship among objects.

3. One company is having some branches and all branches having different departments. So, now I want to display all departments from all branches in a single visualforce page?

Using subquery we can fetch all the required data and we can display it in VF page.

4. Can you please give some information about Implicit and Explicit Invocation of apex?

Triggers - Implicit

Javascript remoting - Explicit

5. what is apex test execution?

Exectuing apex test classes.

6. In an apex invocation how many methods that we can write as future annotations?

10

7. Can you please give some information about Implicit and Explicit Invocation of apex?

Triggers - Implicit

Javascript remoting - Explicit

8. what is apex test execution?

Exectuing apex test classes

9. I have an account object, I have a status field which has open and completed checkboxes, when ever I click on completed, I want an opportunity to be created automatically. Through which we can achieve in salesforce?

Triggers.

10. What are workflows and what actions can be performed using workflows?

Workflows are used for automation.
Field Update
Outbound Messages
Email Alert
Task

11. In an apex invocation how many methods that we can write as future annotations?

10

12. Write a query: I have 1 parent(account) and 1 child(contact),how will you get F.name,L.name from child and email from the account when Organization name in account is "CTS"?

SELECT Email, (SELECT F.Name, L.Name FROM Contacts) WHERE Name = 'CTS'.

13. what are workflow actions?

Field Update
Task
Email Alert
Outbound Message

14. What are outbound messages?what it will contain?

In outbound message contains end point URL.

15. What is External id? primary id?

External id is unique to external application.
Primay id is unique to internal organization.

16. Data loader?and which format it will support?

Data loader is a tool to manage bulk data. It will support .csv format of Excel.

17. How import wizard will not allow the duplicates? 

Using external id.

18. What are validation rules?

Used to maintain data format.

19. Ajax Components in V.F?

apex:actionPoller, apex:actionFunction, apex:actionSupport, etc.

20. Salesforce sites?

Used to show data from our organization for public view.

21.Auto-response rules and Escalation rules(for which objects are mandatory)?

Case and Lead.

22.Difference between REST and SOAP API'S?

Varies on records that can be handled.

23. What is creating debug log for users?

Track code.

24.   How cases are created?

Email to Case and Web to Case

25.   What is after undelete?

While retrieving from recycle bin

26.   Will Trigger.new supports --->Insert,,,Will Trigger.Delete supports --->Delete

Yes.

27.   What is Inline visualforce page?

Having vf page in pagelayout.

28.   If is child is mandatory field in lookup and I m deleting Parent,will child get deleted?

No.

29.   Junction object? when will we use? If we delete the junction object what will happen?

For many to many relationship.

30. Can we have V.F pages in page layout?

Yes.

31. How to create standard object as child to custom object(which is not possible thru standard away process,have to bypass this restriction)?

Create Lookup and make the lookup field mandatory.

32. In a visual force page the save should ensure the data to be be stored in current object as well as associated child object?

We have to use Database.SavePoint and Database.Rollback for this situation.

33. what is audit field,what is the purpose of audit field?

Created By, Created Date, Last Modified By and Last Modified Date are audit fields. Used to track when the changes are done to the records.

34. what we need to do for extending the limit of creating only 2 M-D relationships for custom object?

Create Lookup and make the lookup field mandatory.

34. How to write java script code for save button?

We have to create custom button and in that custom button we have to write Java script code.

35. What are the attributes of apex tag?

Attribute tag is used in creating components.

36. How to insert value to a parent and child element at the same time?

Use triggers.

37. How to make pick-list as required (thru java script)?

We have to create custom button and in that custom button we have to write Java script code to check whether the picklist value is null.

38. What is the Difference between Ajax and ActionPoller?

ActionPolleris a timer that sends an AJAX update request to the server according to a time interval that you specify.

39. When a case is generated by an user through web to case,how or where a developer will provide solution case arised?

Email notification through trigger or through email alert Workflow rule.

40.what is the use of interfaces(in apex classes)?

An interface is like a class in which none of the methods have been implemented—the method signatures are there, but the body of each method is empty. To use an interface, another class must implement it by providing a body for all of the methods contained in the interface.

Interfaces can provide a layer of abstraction to your code. They separate the specific implementation of a method from the declaration for that method. This way you can have different implementations of a method based on your specific application.

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

41. I have added an string 'updated' to all users in Account object through batch apex,now how to remove that 'updated'?

Run the below code in developer console

List<Account> acc =[SELECT Id, Name FROM Account];
for(Account a : acc)
{
    a.Name = a.Name.removeEnd('Updated');
    update a;
}

42. What are workflows and what actions can be performed using workflows?

Workflows are used for automation.
Field Update
Outbound Messages
Email Alert
Task

43. What are types of workflows?

Immediate Workflow Actions
Time-Dependent Workflow Actions

44. Can you tell me what is time based workflow?

Time Based workflow will be triggered at what time we define while creating the Time-Dependent workflow rule.

45. Can you give me situation where we can you workflow rather than trigger and vice versa?

If you want to perform any action after some action, we can go for Workflow Rule.
If you want to perform any action before and after some action, we can go for Trigger.

46. Lets say I have a requirement whenever a record is created I want to insert a record on some other object?

Triggers can be used for this.

47. Whenever a record is inserted in contact I want insert a record in opportunity as well, we can’t do it with workflow right how would you do it with trigger?

We can get the Account Id from the Contact and we can create an Opportunity under the Account.

48. What is the difference between trigger.new and trigger.newmap?

Trigger.new can be used in before and after operations.

Trigger.newMap can be used in after insert and after and before update.

49. Can you tell me what is the difference between apex:actionfunction and apex:actionpoller? Is there any way that we can do the same functionality of apex:actionpoller do?

apex:actionPoller is used to call an Apex method for the interval of time specified.

apex:actionFunction is used to call Apex method from Javascript.

Using setTimeOut in Javascript, we can achieve apex:actionPoller functionalities. 

50. You have VF page and whenever you click a button it should go to google,so how would you do that?

Use pageReference and give the google URL in that.

51. I have an opportunity object, which is having two values like open and close,i have a workflow rule,if a particular object is in open status,it should be updated to close and if status is close it should be updated to open,how should salesforce behave. what would happen to record,how would salesforce behave here?

It causes looping error.

52. I have an account object, I have a status field which has open and completed checkboxes, when ever I click on completed, I want an opportunity to be created automatically. Through which we can achieve in salesforce?

Triggers.

53. Can you brief me about salesforce module flow?

Sales processes include quote generation, tracking opportunity stages, updates on close dates and amounts and won opportunities.

54. How many records can be retrieved by List data type if the page attribute in readonly?

10,000.

55. Can you tell me about Rollup summary field ?

Rollup Summary field can be created in Master detail relationship alone.

Rollup Summary field should be created on master object.

Rollup Summary field is used to find

Sum
Count
Min
Max
of the child records.

56. Can you tell the difference between Profile and Roles?

Profiles are used for Object level access settings.

Roles are used for Record level access settings.

57. What are permission sets?

Permission Sets are used to extend Profile permissions.

58. Can you override profile permissions with permission sets(i have defined some permissions in profile,i am trying to use permission sets for the same object,can i override permissions for a particular object in the permission sets over to the profile?

No. Permission Sets are used only to extend the Profile permissions. It never overrides.

59. I want to have read/write permission for User 1 and read only for User 2, how can you acheive?

Create a Permission Set with read/write and assign it to User 1.

60. Can you tell difference between Profile, OWD or a Sharing Rule?

Profile: Profile is used for object level access. It is used to provide CRUD(Create, Read, Update and Delete) permission.

OWD: OWD is used for record level access for all the users across Organization. It is used to provide Public Read Only, Public Read/Write, Private, Public Read/Write/Transfer(Lead and Case Objects alone).

Sharing Rule: Sharing Rules is used to extend Role Hierarchy.

61. What is the role hierarchy?

Role Hierarchy states that higher hierarchy person can see lower hierarchy person records.

62. I have an OWD which is read only, how all can access my data and I want to give read write access for a particular record  to them, how can i do that?

All users can just Read the record.

Create a Sharing Rule to give Read/Write access with "Based on criteria" Sharing Rules.

63. What is the difference between role hierarchy and sharing rules? will both do the same permissions ?

Role Hierarchy states that higher hierarchy person can see lower hierarchy person records.

Sharing Rule is used to extend Role Hierarchy.

64. What is on-Demand process ?

On-demand process is nothing but "pay for what you use" policy.
We can subscribe to what we want and pay-as-you-go model.

65. Can we create 2 opportunities while the Lead conversion?

Yes using Apex code.

66. User1 is associated with profile "P". If i create a permission set and assign it to User1, now will the Permission sets which we assigned overrides the existing profile "P".

No. Permission set is always used for extending the profile permission. It's not used to override the Profile permissions.

67. Is there is any alternative for the "ActionPoller"?

Using SetTimeout in Javascript and calling the apex method using apex:actionFunction.

68. While inserting a new record with Before Insert. What would be the values in "Trigger.new" and "Trigger.newmap"?

In trigger.New, new record values will be there.
Trigger.newMap will be empty.

69. What is the difference b/w Trigger & Workflow?

Triggered can be fired before or after some operation.

Workflow cab be fired only after some operation.

70. What are the actions used in Workflow?

Email Alert
Field Update
Task
Outbound Message

71. Say About Visual force page?

Using VF tags we can develope visualforce pages.

72. What is meant by Rendered & Re-render attribute in VF ?

Rendered is used decide whether to display or hide the VF elements.

Re-Render is used to refresh the VF elements.

73. What is meant by Standard Controller & Controller?

In standard controller we can refer Standard and custom objects.

In Contoller we can refer Apex class.

74. What are the different types of Cloud in SF?

Sales cloud
Service cloud

75. In which object Roles are stored?

UserRole

76. In which object workflows are stored?

Workflow

77. In which object Roles are stored?

UserRole 

78. What is an alternative for workflow?

Trigger or Schedule apex.

79. What is the use of isNew()?

Checks whether the record is newly created.

80. If you organization Workflow's limit is over and if you want to write a workflow immediately and it it critical, what will you do?

1. De-activate any workflows and create it using trigger and then do the new workflow.
     or
2. Go for Schedule apex or trigger to achieve this workflow.

80. How many users have you supported?

Number of users in the Salesforce organization. It helps the recruiter to understand your scalability.

81. In which object all Approval process are stored?

Approval

82. In which object all email templates are saved?

EmailTemplate

83. In which object all Account Team Members are added?

AccountTeamMember

84. In which object all salesforce objects are saved?

sObject

85. In which object all Opportunity Team Members are added?

OpportunityTeamMember

86. In Which object all Apex Pages are stored?

ApexPage

87. In Which object all Apex Triggers are stored?
 
ApexTrigger

88. In Which object all Apex Classes are stored?

ApexClass

89. Where Products are added?

Product2

90. In which object workflows are stored?

Workflow

Wednesday 9 July 2014

Salesforce | Batch Apex


Apex dataloder : 5 million records
Using batch apex: 50 milion records
 Piece= batches: no.of: records/200..max 2000
 Every batch apex contain 3 methods

Diff between dataloader and batch:

1. Dataloder handle 5mill and batch apex handle 50 million
2. Max batch size for dataloder is 200 and batch it is 2000

What is Batch Apex ?

Batch as the name suggests, is used when a large data (bulk) volume is involved and it has to be redundantly processed using a particular logic.

Implementing the Database.Batchable Interface: The Database.Batchable Interface contains three methods that must be implemented.

1. Start Method:
global (Database.QueryLocator | Iterable<sObject>)
start(Database.BatchableContextbc) {
}
The start method is called at the beginning of a batch Apex job. Use the start method to collect the records or objects to be passed to the interface method execute. This method returns either a Database.QueryLocator object or an iterable that contains the records or objects being passed into the job.

2. Execute Method:
global void execute(Database.BatchableContextBC, list<P>){
 }
The execute method is called for each batch of records passed to the method. Use this method to do all required processing for each chunk of data.

3. Finish Method:
global void finish(Database.BatchableContextBC){
}
The finish method is called after all batches are processed. Use this method to send confirmation emails or execute post-processing operations.

Salesforce | Order of execution of triggers in Salesforce

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)