Tuesday, July 4, 2017

Salesforce Interview Questions – Part 5

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:
  1. Visualforce page
  2. Trigger
  3. Web Services
  4. Email Services

43. Can we create Master Detail relationship on existing records?
Ans:
No. As discussed above, first we have to create the lookup relationship then populate the value on all existing record and then convert it.

44. How validation rules executed? is it page layout / Visualforce dependent?
Ans :
The validation rules run at the data model level, so they are not affected by the UI. Any record that is saved in Salesforce will run through the validation rules.

45. What is the difference between database.insert and insert ?
Ans:
insert is the DML statement which is same as databse.insert. However, database.insert gives more flexibility like rollback, default assignment rules etc. we can achieve the database.insert behavior in insert by using the method setOptions(Database.DMLOptions)
Important Difference:
  • If we use the DML statement (insert), then in bulk operation if error occurs, the execution will stop and Apex code throws an error which can be handled in try catch block.
  • If DML database methods (Database.insert) used, then if error occurs the remaining records will be inserted / updated means partial DML operation will be done.

46. What is the scope of static variable ?
Ans:
When you declare a method or variable as static, it’s initialized only once when a class is loaded. Static variables aren’t transmitted as part of the view state for a Visualforce page.
Static variables are only static within the scope of the request. They are not static across the server, or across the entire organization.

47. Other than SOQL and SOSL what is other way to get custom settings?
Ans:
Other than SOQL or SOSL, Custom seting have there own set of methods to access the record.
For example : if there is custom setting of name ISO_Country,
1SO_Country__c code = ISO_Country__c.getInstance("˜INDIA');
2//To return a map of data sets defined for the custom object (all records in the custom object), //you would use:
3Map<String,ISO_Country__c> mapCodes = ISO_Country__c.getAll();
4// display the ISO code for India
5System.debug("˜ISO Code: "˜+mapCodes.get("˜INDIA').ISO_Code__c);
6//Alternatively you can return the map as a list:
7List<String> listCodes = ISO_Country__c.getAll().values();

48. What happen if child have two master records and one is deleted?
Ans :
Child record will be deleted.

49. What is Difference in render, rerender and renderas attributes of visualforce?
Ans:
render – It works like “display” property of CSS. Used to show or hide element.
rerender – After Ajax which component should be refreshed – available on commandlink, commandbutton, actionsupport etc.
renderas – render page as pdf, doc and excel.

50. What is Scheduler class in Apex and explain how to use Crone statement to Schedule Apex class?
Ans:
The Apex class which is programed to run at pre defined interval.
Class must implement schedulable interface and it contains method named execute().
There are two ways to invoke schedular :
  1. Using UI
  2. Using System.schedule
The class which implements interface schedulable get the button texted with “Schedule”, when user clicks on that button, new interface opens to schedule the classes which implements that interface.
To see what happened to scheduled job, go to “Monitoring | Scheduled jobs ”
Example of scheduling :
1scheduledMerge m = new scheduledMerge();
2String sch = '20 30 8 10 2 ?';
3system.schedule('Merge Job', sch, m);
To see how to make crone job string – Refer this Online Crone Expression Generator tool .
Note : Salesforce only accepts integer in Seconds and Minutes. So, lets say if you want to run Apex job on every 10 minutes, crone statement will be ‘0 0/10 * 1/1 * ? *’ and salesforce will throw an error saying “System.StringException: Seconds and minutes must be specified as integers“. That mean like Time based Workflow, minimum interval to schedule job is 1 hour.

No comments:

Post a Comment