
Mohit Agarwal
IndividualForum Replies Created
-
Mohit
MemberSeptember 20, 2016 at 6:02 am in reply to: How ISBLANK() is different from ISNULL() in Salesforce?Hi Pranav,
It is preferred to use the ISBLANK Salesforce function instead of ISNULL Salesforce function in new Formulas. ISBLANK() has the same functionality as ISNULL(), but also supports text fields. Salesforce will continue to support ISNULL, so you do not need to change any existing formulas.
ISNULL():
Text fields are never null, so using ISNULL() with a text field always returns false. Empty date and date/time fields always return true when referenced in ISNULL() functions.
ISBLANK():
If you use ISBLANK() with a numeric field, the function only returns TRUE if the field has no value and is not configured to treat blank fields as zeroes.
For example, the formula field IF(ISNULL(new__c) 1, 0) is always zero regardless of the value in the New field. For text fields, use the ISBLANK Salesforce function instead.
-
Mohit
MemberSeptember 19, 2016 at 7:10 am in reply to: How to disabling a lookUp inputfield on Salesforce visualforce page?Hi Tanu,
You can disable a lookup inputfield in visualforce page. By writing this piece of code in your javascript function which is used to cal the lookup function on your visualforce page :
document.getElementById(inputfieldId).disabled=true;
or
document.getElementById(LookupIconId).style.visibility = 'hidden';
-
Mohit
MemberSeptember 19, 2016 at 6:17 am in reply to: Is there any way to set track field history to standard field on object in salesforce?Hi Pranav,
Yes, there is way by which we can set track field history to standard object :-
1)Go to the SObject on which you want to set the track field history by the tab or by the by searching that sObject in search box,
2)Then go to the field option of that sObject.
3)Then in the top centre of the field page you see the option the Set History Tracking,
4)Enable the set sObject(like Account,contact, . . .) history and
5)After enable you will see the field of the sObject and the select field on which you want to set the history of sObject.
Thanks And Regards
-
Mohit
MemberSeptember 16, 2016 at 7:11 am in reply to: How to make multiselect checkboxes in searched results of any Salesforce sObject?Hi Pranav,
You have to create a Visualforce page to show data and you have to make controller for it to perform operation.
Here is Visualforce page:-
<apex:page standardController="Opportunity" extensions="OpportunityProductsearch">
<apex:form id="theForm">
<apex:pageBlock title="Search the Product" >
<apex:inputText value="{!searchtext}"/>
<apex:commandButton value="search" action="{!search}" />
<apex:pageMessages />
<apex:pageBlockSection Title="List of Product" id="table" collapsible="false" rendered = "{!toshow}">
<apex:pageBlockTable value="{!listofproductselected}" var="p" >
<apex:column title="Select" >
<apex:inputCheckbox value="{!p.checked}" ></apex:inputcheckbox>
</apex:column>
<apex:column headervalue="Name" value = "{!p.pro.Name}" />
<apex:column headervalue="Product Code" value="{!p.pro.ProductCode}"/>
<apex:column headervalue="Description" value="{!p.pro.Description}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value ="Submit" action ="{!submit}" rendered="{!toshow}" />
<apex:pageBlockSection Title="List of Product in Update" id="table2" collapsible="false" rendered = "{!!toshow}">
<apex:pageBlockTable value="{!showprod}" var="s" >
<apex:column headervalue="Name" >
<apex:inputField value = "{!s.Name}" />
</apex:column>
<apex:column headervalue="Product Code">
<apex:inputField value="{!s.ProductCode}"/>
</apex:column>
<apex:column headervalue="Description">
<apex:InputField value="{!s.Description}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:commandButton value ="save" action ="{!autoupdate}" rendered="{!!toshow}" />
<apex:commandButton value ="cancel" action ="{!search}" rendered="{!!toshow}" />
</apex:pageBlock>
</apex:form>
</apex:page>and Now the Controller:-
public with sharing class OpportunityProductsearch {
public String searchText{get;set;}
public boolean toshow{get;set;}
public List<Product2> prod{get;set;}
public list<ProductWrapper> listofproductselected{get;set;}
public list<Product2> selectedproduct;
public list<Product2> showprod{get;set;}public class ProductWrapper{
public Product2 pro{get;set;}
public Boolean checked{get; set;}
public ProductWrapper(Product2 p,boolean b){
pro = p;
checked = b;
}
}
public OpportunityProductsearch(ApexPages.StandardController con){
toshow = true;
prod = new List<Product2>();
prod.clear();
}
public void search(){
prod.clear();
toshow = true;
listofproductselected = new list<ProductWrapper>();if(!String.isBlank(searchText)){
String s = '%'+searchText+'%';
prod =[select Name,ProductCode,Description,family from Product2 where name like :s ];if(prod!=null){
for(Product2 p : prod){
ProductWrapper pw = new ProductWrapper(p,false);
listofproductselected.add(pw);
}
}
}
}
public void submit(){
toshow = false;
selectedproduct = new list<Product2>();
for(ProductWrapper p : listofproductselected ){
if(p.checked == true){
selectedproduct.add(p.pro);
}
}
System.debug('the select product to be printed : '+selectedproduct);
showprod = selectedproduct;
}
public void autoupdate(){
update showprod;
search();
}
} -
Hi Pranav,
Here is the code for sorting the wrapper list:-
global class Book implements Comparable {
public String BookTitle ;
public String Author ;
public Integer TotalPages ;
public Double Price ;
public Date publishingDate;public enum SORT_BY {
ByTitle,ByPage
}//Variable to decide the member on which sorting should be performed
public static SORT_BY sortBy = SORT_BY.ByTitle;public Book(String bt, String a, Integer tp, Double p, Date pd)
{
BookTitle = bt;
Author = a;
TotalPages = tp;
Price = p;
publishingDate = pd;
}global Integer compareTo(Object objToCompare) {
//Sort by BookName Alphabetically
if(sortBy == SORT_BY.ByTitle)
{
return BookTitle.compareTo(((Book)objToCompare).BookTitle);
}
else //Sort by Book price
{
return Integer.valueOf(Price - ((Book)objToCompare).Price);
}
}
} -
Mohit
MemberSeptember 15, 2016 at 6:28 am in reply to: How to check code coverage in Salesforce org class page not in developer console?Hi Pranav,
Yes, it is already present in org class.
-
This reply was modified 8 years, 7 months ago by
Mohit.
-
This reply was modified 8 years, 7 months ago by
-
Mohit
MemberSeptember 15, 2016 at 5:48 am in reply to: Is it possible to detect user permissions for a field simply on Salesforce visualforce page?Hi Pranav,
1)VisualForce Component:-By using the apex:inputField and apex:outputField components to accept and display data to the user, the platform will automatically respect the current users Field Level Security.This is the easiest way to implement field level security in your page.
2)VisualForce $ObjectType:- You can also access this information using the $ObjectType global variable. An eg:- apex:outputText value="{!contactName}" rendered="{!$ObjectType.Contact.fields.Name.Accessible}"
-
Mohit
MemberSeptember 14, 2016 at 6:11 am in reply to: What are the best practices in determining whether a Salesforce formula field should be created versus workflow field update?Hi Tanu,
Both Formula field and workflow are different things :-
A formula is similar to an equation that is executed at run time. We use formula field when there has to be a formulated value also to be displayed in another field etc.
Where as the Workflow is used when we have to perform task based on a certain criteria so to perform action automatically.
The automate action performed by the workflow are:-
1)Task
2)Email Alert
3)Field Update
4)Outbound messsages
-
Mohit
MemberSeptember 14, 2016 at 5:42 am in reply to: If a Salesforce controller has a series of extensions then which extension will execute first?Hi Tanu,
Multiple controller extensions can be defined for a single page through a comma-separated list.
If both extension having same method, whichever methods are defined in the “leftmost” extension, or, the extension that is first in the comma-separated list will execute first.
For eg:-
Visualforce Page:-
<apex:page standardController="Account"
extensions="ExtOne,ExtTwo" showHeader="false">
<apex:outputText value="{!foo}" />// this formula field first call the foo from ExtOne extension.
</apex:page>For Extension:-
public class ExtOne {
public ExtOne(ApexPages.StandardController acon) { }public String getFoo() {
return 'foo-One';
}
}public class ExtTwo {
public ExtTwo(ApexPages.StandardController acon) { }public String getFoo() {
return 'foo-Two';
}
}If both having different method then it will execute based on formula {! } which method you are calling
Extension Example:-
public class OneExt {
public OneExt(ApexPages.StandardController controller) { }
public String getFood() {
return 'OneExt';
}
}public class TwoExt {
public TwoExt(ApexPages.StandardController controller) {}
public String getFoo() {
return 'TwoExt';
}}
Visualforce page:-
<apex:page standardController="Account" extensions="ExtOne,ExtTwo" showHeader="false">
<apex:outputText value="{!foo}"/> //This formula field will call foo() from the TwoExt extension.
</apex:page> -
Mohit
MemberSeptember 13, 2016 at 5:38 am in reply to: How can I invoke a wrapper class in a test class in Salesforce?Hi Pranav,
You can invoke the wrapper class in test class in this way:-
ClassName.WrapperClassName objectName = new ClassName.WrapperClassName();
objectName.VariableName = parameter;//pass the values to the wrapper class variable
or
objectName.FuntionName();//to call the wrapper class function.
-
Mohit
MemberSeptember 9, 2016 at 5:37 am in reply to: Is there any way through which user is restricted to save duplicate records in salesforce?Hi Pranav,
You can prevent the duplicate record based on the value of a single custom field, select the Unique and Required checkbox on that field's definition :-
Steps for selecting unique and required checkbox is :-
In standard object:-
1) Click Setup | Customize.
2) Select the link for the desired object, and click Fields.
3) Click Edit next to the name of the appropriate field.In Custom Object:-
1) Click Setup | Develop | Objects.
2) Click the name of the object on which the field appears.
3) Click Edit next to the name of the field in the Custom Fields and Relationships related list.The Unique and Required checkboxes are only available on custom fields.
If you need to require uniqueness based on the value of two or more fields, or a single standard field, write an Apex before insert and before update trigger.
trigger sObjectDuplicatePreventer on sObject
(before insert, before update){Map<String, sObject> sObjectMap = new Map<String, sObject>();
for (sObject obj : System.Trigger.new){
if ((obj.Email !=null) &&
(System.Trigger.isInsert ||
(obj.Email !=
System.Trigger.oldMap.get(obj.Id).Email))){
if (sObjectMap.containsKey(obj.Email)){
obj.Email.addError('Another new lead has the '
+'same email address.');
}else{
leadMap.put(obj.Email, obj);
}
}
} -
Mohit
MemberSeptember 9, 2016 at 5:14 am in reply to: Can I programmatically determine if a user is licensed for a Salesforce package?Hi Tanu,
You can determine the user license for a package by UserInfo.isCurrentUserLicensed(namespace).
By this method only you cna determine the user is licensed for a package .
-
Mohit
MemberSeptember 8, 2016 at 5:52 am in reply to: How to check if any error has been added to a Salesforce record?Hi Tanu,
The addError methods in a Visualforce context will also add to the Apex Page messages collection, which you can access via the ApexPages.getMessages method.
Use the apexMessages on the visualforce page and apex controller :-
sObject testRecord = new sObject();
testRecord.addError('Some error');
testRecord.A_Number__c.addError('Field error');
for(ApexPages.Message message : ApexPages.getMessages())
System.debug(message.getComponentLabel() + ' : ' + message.getSummary()); -
Mohit
MemberSeptember 8, 2016 at 5:38 am in reply to: How to convert report in to PDF in Salesforce Apex class?Hi Tanu,
It is not possible to convert report into PDF, but in place of this you can create visualforce page same as report and schedule the visualforce page by using the code:
public class EmailReport implements Schedulable {
public void execute(SchedulableContext sc) {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('Report.pdf');
pagereference Pg = Page.PDFPage;
Blob body = pg.getcontentAsPdf();
attach.Body = body;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] { 'magulancse24@gmail.com' });
mail.setSubject('PDF Generation');
mail.setHtmlBody('PFA');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
mails.add(mail);if(!mails.isEmpty()) {
Messaging.SendEmail(mails);
}
} -
Mohit
MemberSeptember 7, 2016 at 6:05 am in reply to: How can I find out if the current user has access to a Salesforce record, if it has permissions or not?Hi Pranav,
You can check the accessibility of the user by SOQL in this way:-
SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId = [single ID] AND RecordId = [single ID]
And without Soql you check the accessibility of user:-
On Visualforce Page:-
{!$ObjectType.Account.accessible}
On Apex Page :-
Schema.DescribeSObjectResult accountDescribe = Account.sObjectType.getDescribe();
System.debug('accessible:' + accountDescribe.accessible); -
Mohit
MemberSeptember 7, 2016 at 5:46 am in reply to: How can I dynamically append the fieldtype in SOQL query in Salesforce?Hi Pranav,
You can give the dynamic fieldtype in SOQL in this way:-
String type ='fieldtype';
String test = String.valueof(testvalue); // the value on which you want to perform search action.
sObject obj = Database.query('SELECT Id,name FROM sObject WHERE ' + type + ' like \'%' + test + '%\' limit 1');
System.debug('@@@'+obj);I hope you get your answer
-
Mohit
MemberSeptember 6, 2016 at 6:38 am in reply to: How can I ensure that a field is blank for some account types, and mandatory for others?Hi Pranav,
we can do this by following ways:-
1)OR(logical1, logical2...) and replace any number of logical references with the expressions you want evaluated.
2)AND(logical1, logical2...) and replace any number of logical references with the expressions you want evaluated.
3)ISPICKVAL(picklist_field, text_literal) and replace picklist_field with the merge field name for the picklist; replace text_literal with the picklist value in quotes. text_literal cannot be a merge field or the result of a function.
4)NOT(logical) and replace logical with the expression that you want evaluated.
Eg:-
AND(
OR(
ISPICKVAL(Type, "Client"),
ISPICKVAL(Type, "Client - Group Contract")
),
ISPICKVAL(Customer_Management__c, "")
) -
Hi Pranav,
You can achieve this by the this code:-
List<sObject> sobjectList = new List<sObject>();
for(string s : str)
{
sobjectList.add(new sObject(Name = s));// fill other required fields as well
}
insert sobjectList; -
Mohit
MemberSeptember 5, 2016 at 7:52 am in reply to: What are the different types of messaging options in Visualforce page?Hi Pranav,
The Different type of messaging option are:-
1)Info:-
It is code is Eg:-
<apex:page >
<apex:pageMessage summary="This is a pageMessage" severity="info" strength="3"/>
</apex:page>2) Error :-
It is code is Eg From Standard Controller Message:-
<apex:page >
<apex:pageMessage summary="This is a pageMessage" severity="error" strength="1"/>
</apex:page>Custom Controller Message:-
<apex:page controller="TestMessageController">
<apex:pageMessages />
</apex:page>public class TestMessageController{
public TestMessageController(){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This is apex:pageMessages'));
}
}3)Warning :-
The code is:-
<apex:page controller="WarningMessage">
<apex:pagemessages />
</apex:page>public class WarningMessage
{
public WarningMessage()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Warning, 'This is a warning message'));
}
}4)Confirm
It is code is :-
<apex:page controller="SuccessMessage">
<apex:pagemessages />
</apex:page>public class SuccessMessage
{
public SuccessMessage()
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Confirm, 'This is a success message'));
}
} -
Mohit
MemberSeptember 5, 2016 at 7:18 am in reply to: How can I change the Date format in Visualforce page?Hi Pranav,
You can have date in this format by following this example:-
<apex:outputText value="{0, date, MMMM d',' yyyy}">
<apex:param value="{!FieldName}" />
</apex:outputText>or by:-
<apex:outputText value="{0, date, MMMM d',' yyyy}">
<apex:param value="{!Now()}" />
</apex:outputText> -
Hi Tanu,
You can get the total count of login done by a profile by this SOQL query:-
List<User> userid =[Select id from user where Name = 'Profile Name' limit 1];
Integer count = [select count() from LoginHistory where id =: userid[0].id ];
System.debug('The total count of login'+count); -
Mohit
MemberSeptember 1, 2016 at 6:41 am in reply to: Is there any way in query to do Like against a List of Values?Hi Pranav,
You can do this by query like :-
String[] searchitem = {'%searchtext1%','%searchtext2%'};
List<Accounts> acc = [select id, name from Account where name like :searchitem];
-
Mohit
MemberAugust 31, 2016 at 7:57 am in reply to: Is there any method through which we can count if a particular field has some value or not?Hi Pranav,
You can do this by Applying Soql query on it
Eg If you want to check how many contact are present on the account. The Soql is : -
SELECT COUNT() FROM Contact where AccountId!=Null.
And if you want to check that particular contact on account contain particular field or not then you can apply this query:-
SELECT COUNT() FROM Contact where AccountId!=null AND FieldName != null
-
Mohit
MemberAugust 31, 2016 at 7:25 am in reply to: In salesforce every record has Id so how unique IDs work?Hi Pranav,
For all entity types, every record has an ID field that uniquely identifies that record. The value for the ID field is created automatically upon insert, and it cannot change over the lifetime of that record, even if the record is deleted and then undeleted. Each ID value is guaranteed to be globally unique. The ID of a record is the best way to uniquely identify that record.
here are two versions of every record Id in salesforce :
1)15 digit case-sensitive version which is referenced in the UI.
2)18 digit case-insensitive version which is referenced through the API. The 18-digit reference IDs are just case-safe.
The last 3 digits of the 18 digit ID are a checksum of the capitalizations of the first 15 characters, this ID length was created as a workaround to legacy systems which were not compatible with case-sensitive IDs.
The API will accept the 15 digit ID as input but will always return the 18 digit ID.You can either pass the 15 digit or 18 digit ID for same SOQL. And for 18 Digit character version, first you have to convert the 18 character ID to 15 character version .To do this you have to follow this procedure :-truncate the last three characters.
-
Mohit
MemberAugust 31, 2016 at 6:59 am in reply to: How can I set a date field to null using Visualforce JavaScript Remoting?Hi Tanu,
Try passing a list<string> fieldsToNull parameter to the @remoteAction this will allow you to set them all to null in the @remoteActionwith something like s.put('field1',null).