1. 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:
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 | |
2 | Database.DMLOptions dmlOptn = new Database.DMLOptions(); |
3 | dmlOptn.assignmentRuleHeader.useDefaultRule = true; | |
4 | leadObj.setOptions(dmlOptn); |
2. 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.
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
Example:
1 | Select Id, Name from Lead LIMIT 5 OFFSET 2 |
Above query will return 5 Lead records starting from record number 10 (5×2).
3. Access custom controller-defined enum in custom component ?
Ans :
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:
1 | global 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:
Add below method in Apex Controller:
1 | public String currentStatusValue { get{ return getColorStatus().name(); }} |
and change Visualforce code to
1 | <apex:image url='stopsign.png' rendered="{!currentStatusValue == 'RED'}" /> |
4. How to generate the random string or random password using Apex?
Ans:
Ans:
1 | Integer len = 10; | |
2 | Blob blobKey = crypto.generateAesKey(128); |
3 | String key = EncodingUtil.convertToHex(blobKey); | |
4 | String 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.
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.
Access the Account name from Contact.
1 | {!myContact['Account'][fieldname]} |
Example 2:
Consider Data type in Apex
1 | public 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:
Ans:
1 | Lead myLead = new Lead(LastName = 'Foo', Company='Foo Bar'); | |
2 | insert myLead; |
3 | ||
4 | Database.LeadConvert lc = new database.LeadConvert(); |
5 | lc.setLeadId(myLead.id); | |
6 |
7 | LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]; | |
8 | lc.setConvertedStatus(convertStatus.MasterLabel); |
9 | |||
10 | Database.LeadConvertResult lcr = Database.convertLead(lc); | ||
11 | System.assert(lcr.isSuccess()); |
7. 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.
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.”
8. In salesforce which fields are indexed automatically?
Ans :
The following fields are indexed by default:
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.
\
9 : Give anyscenario when you cannot change the currency field type to numeric typeAns : When the field is used either in Apex class or trigger.
10 : While creating JavaScript button to execute anonymous apex, what should you keep in mind ?
Ans : End user must needs to have “Apex Author” permission and this is something should not be granted to end user. Also, while creating JavaScript button, user must be aware that its only supported in Salesforce classic and not in Salesforce Lightning.
11 : How to enable truncate custom object feature in Salesforce ?
Ans : Navigate to “App Setup | User Interface” and select “Enable Custom Object Truncate”.
12 : What may be reason truncate button is not visible on Custom Object ?
Ans :
Are referenced by another object through a lookup field or that are on the master side of a master-detail relationship
Are referenced in a reporting snapshot
Have a custom index or an external ID
13 : How to report on User License field?
Ans :
Create formula field in User Object with formula “Profile.UserLicense.Name”.
Note: You need to copy and paste this value because it doesn’t show up in the fields drop down.
14: Which custom fields or relationships in salesforce ends with “__pc” and “__pr” ?
Ans : In normal scenario all custom fields ends with “__c” and relationships ends with “__r” However for Person accounts, custom fields ends with “__pc” and custom relationship ends with “__pr”.
15 : Difference between Chatter API and Connect API.
Ans :
Chatter API is REST API for Chatter to display Salesforce data, especially in mobile applications. Responses are localized, structured for presentation, and can be filtered to contain only what the app needs.
Connect API provides apex classes for accessing the same data available in Chatter REST API. Use Chatter in Apex to create custom Chatter experiences in Salesforce.
16: How to capture errors after using Database DML methods in Salesforce?
Ans :
1
List<Contact> lstContact = new List<Contact>();
2
Contact con = new Contact (lastName = 'Zaa', SQL_Server_Id__c='3',firstName='Jitendra');
3
lstContact.add(con);
4
//.. Other Contact records added in List
5
Database.UpsertResult[] results = Database.upsert( lstSGAccOppInsert, Contact.SQL_Server_Id__c.getDescribe().getSObjectField() ,false ) ;
6
7
for(Integer i=0;i<results.size();i++){
8
if (!results.get(i).isSuccess()){
9
Database.Error err = results.get(i).getErrors().get(0);
10
System.debug('Error - '+err.getMessage() + '\nStatus Code : '+err.getStatusCode()+'\n Fields : '+err.getFields());
11
}
12
}
17: What causes Concurrent Apex limit error in Salesforce ?
Ans : If Synchronous Apex runs more than 5 sec it considered as long running job. And we have limit that only 10 long running job can execute at a time. So, whenever 11th Synchronous apex tries to execute, it gets Concurrent Apex limit error. Read more here about Concurrent Request Limits
18. What is custom metadata type ?
Ans : Custom metadata was introduced generally in Summer 15 release. Before Custom metadata type, we were using Custom settings of List type. Problem with custom setting was that, during migration or in packages, data were not migrated. We had to either use data loader or some API to create initial data. However, if we package custom metadata type or migrate it, data will also be migrated along with it.
19. Which component in Salesforce ends with “__mdt” and “__s”?
Ans : Custom metadata types ends with “__mdt” (meta data type), just like custom object or custom fields ends with “__c”.
When we create Geolocation field in Salesforce, lets say by name “location__c” then internally Salesforce creates subfields with extension “__s“. In this case “location_latitude__s” and “location_longitude__s”.
0 Comments