anusha(salesforce developer)

Workflows, Changeset, Test class coverage, Ajax Toolkit,Salesforce on pagination, pagination in SOQL, Dynamic Visualforce Binding, Random Password, Convert Lead using Apex, count more than 50000 in SOQL, Monitor email sent, Indexed field, Change field type

121 : Consider we have overall 90% code coverage however there is one class which have 0% code coverage. Can we still able to deploy that class on production?
Ans : Yes. Minimum 1% required for every trigger and there is no such restriction for Apex class.

122 : How to get selected records ID from List View using Javascript / Ajax Toolkit, when custom button is added on List View page?
Ans : Create a new Button on Lead of type List Button. Add the button on Lead List View Layout and write below Javascript code:
1{!RequireScript("/js/functions.js")}
2 
3var recordsSelected = {!GetRecordIds($ObjectType.Lead)}
4for(var i=0; i < recordsSelected .length ; i++) {
5     alert('Selected ID '+recordsSelected[i]);
6}

123 : In Ajax toolkit for custom Javascript button, you have to explicitly login to API because global Session variable is not available. In that case it is security vulnerable because anybody logged in can see the javascript code and your username and password. So is there any way to avoid this?
Ans: We can create a visualforce page with output type as JavaScript. Global session variable is available in VF page. Initialize the global javascript variable in that VF page. include VF page as a javascript file and we are done!

124 : In Custom Component How we can return value to Custom Controller or Controller Extension?
Ans: In Apex, Objects are passed by reference (read this article to understand Pass by Value and Pass by reference in Salesforce and also read this Salesforce blog article). So supply an argument of wrapper class (object) type to custom component. If its value is changed in Custom component we will get updated value in controller also.

125 : Lets consider you had created outbound changeset previously. After that, some class is modified which is part of that old changeset. If you clone that Changeset, current updated class will be included or that previous class will be included in changset?
Ans : Once changeset is created it cannot be modified. After creation of changset, if we modify any component it will not reflected and when we clone the changeset, all components (offcource old copy of component) will be added to changeset.

126 : We have a “Time Based Workflow” and there is Action scheduled to be executed. If we Deactivate the workflow, Scheduled actions will be removed from queue or not?
Ans : Even after deactivation of workflow, its action will be active in queue.

127 : We have “Time Based Workflow” and there is action scheduled to be executed. Can we delete that workflow?
Ans : If a workflow have any pending time dependent action, then we cannot delete the workflow.

128 : How to clear the Time based workflow action queue ?
Ans : Two ways to achieve this : 1. Make criteria false for all those records. 2. Navigate to “Set up | Monitoring | Time Based Workflow”, search for scheduled actions and remove from queue.

129 : While creating workflow on Task, what difference observed on available actions?
Ans : “Send Email” action is not available while creating workflow on task.

130 : In trigger, lets say we have system.debug() statement after adderror() method. Will system.debug() be statement executed in Trigger after adderror() method?
Ans: adderror() method is not error statement rather its normal execution flow and all the statements written after adderror() will be executed normally.
101. How to force lead assignment rule via Apex while updating or adding the Lead?
Ans : To enforce Assignment Rules in Apex you will need to perform following steps:
  1. Instantiate the “Database.DMLOptions” class.
  2. Set the “useDefaultRule” property of “assignmentRuleHeader” to True.
  3. Finally call a native method on your Lead called “setOptions”, with the Database.DMLOptions instance as the argument.
Example:
1// to turn ON the Assignment Rules in Apex
2Database.DMLOptions dmlOptn = new Database.DMLOptions();
3dmlOptn.assignmentRuleHeader.useDefaultRule = true;
4leadObj.setOptions(dmlOptn);

102. How to implement the pagination in SOQL ?
Ans:
In spring 12, Salesforce has come up with ability of SOQL to get records from position “X” instead of position “1” every time to help creating pagination feature.
Pagination in SOQL using keyword Offset
Pagination in SOQL using keyword Offset
Example:
1Select Id, Name from Lead LIMIT 5 OFFSET 2
Above query will return 5 Lead records starting from record number 10 (5×2).

103. Access custom controller-defined enum in custom component ?
Ans :
We cannot reference the enum directly since the enum itself is not visible to the page and you can’t make it a property.
Example:
Apex class:
1global with sharing class My_Controller {
2  public Case currCase {get; set; }
3  public enum StatusValue {RED, YELLOW, GREEN}
4 
5  public StatusValues getColorStatus() {
6    return StatusValue.RED;  //demo code - just return red
7  }
8}
Visualforce page:
1<apex:image url='stopsign.png' rendered="{!colorStatus == StatusValue.RED}" />
Above code snippet will throw error something like “Save Error: Unknown property‘My_Controller.statusValue'”
Resolution:
Add below method in Apex Controller:
1public String currentStatusValue { get{ return getColorStatus().name(); }}
and change Visualforce code to
1<apex:image url='stopsign.png' rendered="{!currentStatusValue == 'RED'}" />

104. How to generate the random string or random password using Apex?
Ans:
1Integer len = 10;
2Blob blobKey = crypto.generateAesKey(128);
3String key = EncodingUtil.convertToHex(blobKey);
4String pwd = key.substring(0,len);

105. What is dynamic binding in salesforce?
Ans:

Dynamic Visualforce bindings are a way of writing generic Visualforce pages that display information about records without necessarily knowing which fields to show. In other words, fields on the page are determined at run time, rather than compile time. This allows a developer to design a single page that renders differently for various audiences, based on their permissions or preferences. Dynamic bindings are useful for Visualforce pages included in managed packages since they allow for the presentation of data specific to each subscriber with very little coding.
Example 1: 
Access the Account name from Contact.
1{!myContact['Account'][fieldname]}
Example 2:
Consider Data type in Apex
1public Map<String, List<Account>> accountsMap {get; set;}
Visualforce page:
1<apex:variable value="A" var="selectedKey" />
2<apex:pageBlockTable value="{!accountsMap[selectedKey]}" var="acc">
3   <apex:column value="{!acc.name}"/>
4   <apex:column value="{!acc.BillingStreet}"/>
5   <apex:column value="{!acc.BillingCity}"/>
6   <apex:column value="{!acc.BillingPostalCode}"/>
7</apex:pageBlockTable>

106. How to convert lead using Apex?
Ans:
1Lead myLead = new Lead(LastName = 'Foo', Company='Foo Bar');
2insert myLead;
3 
4Database.LeadConvert lc = new database.LeadConvert();
5lc.setLeadId(myLead.id);
6 
7LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
8lc.setConvertedStatus(convertStatus.MasterLabel);
9 
10Database.LeadConvertResult lcr = Database.convertLead(lc);
11System.assert(lcr.isSuccess());


108. How can you determine that email is actually sent or not from the salesforce?
Ans:

There is an Email log that you could use. It’s available in the setup menu under Monitoring.
It’s only for the past 30 days and you would have to manually check it.
From the email log page: “Email logs describe all emails sent through salesforce.com and can be used to help identify the status of an email delivery. Email logs are CSV files that provide information such as the email address of each email sender and its recipient, the date and time each email was sent, and any error code associated with each email. Logs are only available for the past 30 days.”

109. In salesforce which fields are indexed automatically?
Ans : 

The following fields are indexed by default:
  • primary keys (Id, Name and Owner fields),
  • foreign keys (lookup or master-detail relationship fields),
  • audit dates (such as LastModifiedDate),
  • Custom fields marked as External ID or Unique.

110 : Give any scenario when you cannot change the currency field type to numeric type.
Ans :
 When the field is used either in Apex class or trigger.

No comments:

Post a Comment