Salesforce Interview Question – Part 14

Author posted by Jitendra on Posted on under category Categories Apex, Salesforce and tagged as Tags with 1 Comment on Salesforce Interview Question – Part 14

131. What will happen if you try to update record in After Trigger Context?
Ans : You will get an error saying “record is Read only”.


132. Let’s say we have to update the same record in After Trigger context. Is there any way or workaround?
Ans : If we create a new instance of an SObject in the Apex Trigger in memory using the Id of the newly created record as provided in the After Trigger context, we can perform an Update DML statement and not get a read only error. This is because in Apex, the SObject is seen as a new reference (even though the records have the same SFDC ID) and therefore is eligible for DML operations. The below snippet of code illustrated this working and not working.

List<Contact> originals = new List<Contact>();
if(mirrorResultMap.values().size() > 0)
{
	for(Contact origContact : contactRecs.values())
	{
		Contact mirrorContact = mirrorResultMap.get(origContact.Id);
		//origContact.Linked_Contact__c = mirrorContact.Id; //Link the Original Record tot he Mirror Record WILL FAIL
		Contact origContactUpdate = new Contact(Id=origContact.Id, Linked_Contact__c = mirrorContact.Id); //This will WORK
		originals.add(origContactUpdate);
	}
	//update contactRecs.values(); //Update the Records -> THIS WILL FAIL AS ITS ORIGINAL RECORDS IN MEMORY
	update originals;
}

Credit goes to Cory Cowgill for this Blog Entry.


133 . When loading data into date fields such as Opportunity Close Date using the Data Loader, the date displayed in the application is sometimes one day earlier than the date in the file. What may be the reason and solution ?
Ans :
The reason for this is that fields such as Close Date are actually date/time fields. When a date is loaded without specifying the time, the time is defaulted to 00:00 – midnight. When another user is in a time zone which is behind the current user’s time zone, the date will show on the previous day. For example:

20 August 2008 00:00 in Paris is 19 August 2008 23:00 in London

Similar issues can arise when daylight savings time begins or ends.

Two simple solutions to this are:
1) Specify a time as well as a date when loading dates using the Data Loader.
or
2) Switch your PC’s time zone to Hawaiian time before starting up the Data Loader.


134 : System.debug() statements are included against script count?
Ans : Any statement ending with semi-colon will be included against script count. There is very good article by Abhinav explaining this here.


135 : While trying to access javascript code from some CDN like Google, we get error something like “attempt to run uG request”. How to resolve it ?
Ans : While providing URL, do not specify the protocol. Use like this:

<script type='text/javascript' src= '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>

136 : Explain ActionFunction, ActionSupport and ActionPoller in Visualforce.
Ans:

apex:ActionFunction : This component helps to envoke AJAX request (Call Controllers method) directly from Javascript method. It must be child of apex:form. Read here – www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

apex:ActionSupport : This component adds Ajax request to any other Visualforce component. Example : Commandlink button has inbuilt AJAX functionality however few components like OutputPanel does not have inbuilt AJAX capabilities. So with the help of this component, we can enable AJAX. Read more here.

apex:ActionPoller : This is timer component which can send AJAX request on pre-defined interval. Minimum interval is 5 sec and default is 60 sec.


137 : In how many ways you can invoke Controllers / Controller Extensions method from VF?
Ans : Javascript Remoting, ActionFunction, ActionSupport, ActionPoller.


138 : What is the use of apex:detail component ?
Ans : With the help of this Visualforce component, we can diretly get complete behavior of page layout defined for logged in users profile. There is no need to add fields, related lists explicitly. Read more here.


139 : What is the difference between “apex:dataTable” and “apex:pageBlockTable” components in Visualforce?
Ans : Both component is used to render data in tabular format. dataTable will render records in simple HTML table format whereas the “pageBlockTable” possess default look and feel of salesforce standard CSS and must be written inside “apex:pageBlock” componet.
You can read more here.


140 : User have all the permissions to see the Dashboard and Source Folder still when he wants to see dashboard, its not visible. What might be the cause?
Ans : It is possible that Salesforce User license for Dashbaord running user is different than User wants to access Dashboard. Example – Running User license is “Salesforce” and user trying to access Dashboard is “Salesforce Plateform”.

Related posts

  • RKR

    Just now i have finished going through all the Questions.

    Thanks a lot for your Help.
    and when can we expect the part 15 and on what topics it will be.