Forum Replies Created

Page 1 of 3
  • Hi Subramanyam Subbu,
    Yes, it is possible to query the list of Accounts where Associated Contacts greater than 200.
    For this, we can use the Aggregate query to fetch the AccountId of those Account record having related contact greater than 200.
    Here is the Code below:-

    AggregateResult[] groupedResults = [select AccountID from Contact GROUP BY AccountID HAVING count(AccountId)>200];

    for (AggregateResult ar : groupedResults) {

    System.debug('Account ID' + ar.get('AccountID'));

    }
    Hope this may help you.

    Thanks,
    Mohit Agarwal

  • Mohit

    Member
    January 29, 2018 at 8:41 am in reply to: How can we prevent phishing attacks in Salesforce?

    Hi Manpreet,

    Phishing is a social engineering technique that attempts to acquire sensitive information such as usernames, passwords, and credit card details by masquerading as a trustworthy entity in an electronic communication. Phishers often direct users to enter details at a fake website whose URL and look-and-feel are almost identical to the legitimate one.

    Salesforce Ongoing actions to avoid phishing:-

    • Actively monitoring and analyzing logs to enable proactive alerts to customers who have been affected.
    • Collaborating with leading security vendors and experts on specific threats.
    • Executing swift strategies to remove or disable fraudulent sites (often within an hour of detection).
    • Reinforcing security education and tightening access policies within Salesforce.
    • Evaluating and developing new technologies both for our customers and for deployment within our infrastructure.

    Salesforce recommendation to avoid phishing:-

    • IP range restrictions.
    • Decrease Session Timeout Thresholds
    • Educate Users About Phishing.
    • Two-Factor Authentication.
    • Salesforce Password Policies.
    • Use Transaction Security to monitor events and take appropriate actions.

    Hope this may help you.

  • Hi Shaik,
    I have done this functionality in my org, with the help of apex trigger.

    This is the following code to achieve this functionaity.

    trigger toCheckNumberOfUser On Opportunity(before Insert, before update){
    Map<Id,Integer> mapofOwnerIdVsCount = new Map<Id,Integer>();
    for(AggregateResult arOpp : [select count(id),OwnerId from Opportunity Group BY OwnerId HAVING Count(id)>0] ){
    mapofOwnerIdVsCount.put(Id.valueOf(String.valueOf(arOpp.get('OwnerId'))),Integer.valueOf(arOpp.get('expr0')));
    }
    for(Opportunity opp: Trigger.new){
    if(mapofOwnerIdVsCount.get(opp.OwnerId)>15){
    opp.addError('Number of Opportunity on this User is greater than 15');
    }
    }
    }

    Thanks

  • Mohit

    Member
    January 6, 2017 at 3:09 pm in reply to: what is list used for in salesforce?

    Hi Sushant,

    The List<SelectOption> is used to show the dynamic drop-down value on the visualforce page.

    For Eg:-

    Apex Controller:-

    public class sampleCon {

    String[] countries = new String[]{};

    public PageReference test() {
    return null;
    }

    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('US','US'));
    options.add(new SelectOption('CANADA','Canada'));
    options.add(new SelectOption('MEXICO','Mexico'));
    return options;
    }

    public String[] getCountries() {
    return countries;
    }

    public void setCountries(String[] countries) {
    this.countries = countries;
    }

    }

    Visualforce Page:-

    <apex:page controller="sampleCon">
    <apex:form>
    <apex:selectCheckboxes value="{!countries}">
    <apex:selectOptions value="{!items}"/>
    </apex:selectCheckboxes><br/>
    <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>
    <apex:outputPanel id="out">
    <apex:actionstatus id="status" startText="testing...">
    <apex:facet name="stop">
    <apex:outputPanel>
    <p>You have selected:</p>
    <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
    </apex:outputPanel>
    </apex:facet>
    </apex:actionstatus>
    </apex:outputPanel>
    </apex:page>

  • Mohit

    Member
    December 19, 2016 at 12:56 pm in reply to: Can we call a future method in another future method in Salesforce?

    Hi Sushant,

    You cannot call a future method from another future method as both them are asynchronous. In salesforce you cannot call one asynchronous function into another asynchronous method.

    As per the salesforce documentation:-

    You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method.

  • Hi Ashley,

    The List.Size() > 0 will check whether the list has any record in it or not.

    The List!=null will be use full when you have not initialize the list. It is not helpfull to check the whether the list has any record or not. This is a waste of CPU time, because (a) records will never be null, and (b) iterating over an empty list is acceptable

    And List.isEmpty() then it also check whether the list has any record or not.

    for Example:-

    Account[] records = [SELECT Id, Name, AccountNumber FROM Account];
    if(records!=null && !records.isEmpty()) {
    for(Account record: records) {
    // Do Something Here
    }
    }

    Thanks

  • Mohit

    Member
    December 6, 2016 at 7:27 am in reply to: API names for all standard fields in Salesforce?

    Hi Kumar,

    On the Standard Object : -

    1)Goto the setup.

    2)In Quick Find Box write the Object name and then Goto the Field To know the Field associate to that Object.

    On the Custom Object:-

    1. Go to Setup.
    2. Under "Build," click Create | Objects.
    3. Click the object name, click Fields.
    4. And check for "API name" column name value

    On the Custom Fields :-

    1. Go to Setup.
    2. Go to App Setup | click Customize.
    3. Locate the object the click Fields.
    4. Look for "API Name" column value in "Custom Fields & Relationships" section

    Thanks

  • Hello Ajit,

    System Mode is nothing but running apex code by ignoring user's permissions. In system mode, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren't applied for the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user. All apex code run in system mode. It ignores user's permissions. Only exception is anonymous blocks like developer console and standard controllers.

    User Mode is nothing but running apex code by respecting user's permissions and sharing of records. Only standard controllers and anonymous blocks like developer console run in user mode.

    Apex Triggers always run in System Mode irrespective of sharing settings, is a myth. Because if your apex trigger is calling a class declared using “WITH SHARING”, then all sharing rules for the context user will apply during trigger execution. If you apex triggers is expecting to query all records and that code is running under WITH SHARING context, then user’s profile will come into play.

  • Hi Pranav,

    You can achieve the multi select option from a select list in this way:-

    Page:-

    <apex:page controller="MultiselectController">
    <apex:form >
    <apex:selectList value="{!value}" size="3" multiselect="true" label="blah" id="blah" >
    <apex:selectOptions value="{!options}" />
    </apex:selectList>
    </apex:form>
    </apex:page>

    Controller:-

    public class MultiselectController {
    public List<SelectOption> options { get; set; }
    public String[] value { get; set; }

    public MultiselectController() {
    value = new String[] { 'a', 'b','c'};
    options = new List<SelectOption> {
    new SelectOption('a', 'a'),
    new SelectOption('b', 'b'),
    new SelectOption('c', 'c'),
    new SelectOption('d', 'd'),
    new SelectOption('e', 'e')
    };
    }
    }

  • Hi Pranav,

    You can unlock the records through apex code by enabling Apex code to set and remove approval process lock.This features is avaliable in summer 16 release only. To do this follow these step :-

    1. Goto Setup
    2. .Then search 'Process Automation Settings' in search box. 
    3. There you click the checkbox 'Enable record locking and unlocking in Apex'

    From this you can enable the record locking and unlocking by apex code.

    Then the code for unlocking the record :-
    For(sObject a :[select name From sObject])//Name of the object on which lock is acquire
    {
    if(Approval.isLocked(a.id)){  //To check whether the record is locked or not
    Approval.unlock(a.id);          //Id of the record which you want to unlock
    }
    }

  • Mohit

    Member
    September 29, 2016 at 8:02 am in reply to: How to make a dynamic picklist in salesforce?

    Hi Tanu,

    To create a dynamic picklist you can use this code:-

    For visualforce page:-

    <apex:page controller="dynamicpicklistcontroller" action="{!autoRun}">
    <apex:form >
    <apex:pageblock >
    <apex:pageBlockSection id="InfoId" columns="1" >
    <apex:outputLabel value="New Account Status" />
    <apex:selectList size="1" value="{!SelectedValue}">
    <apex:selectOptions value="{!statusOptions}"/>
    </apex:selectList>
    </apex:pageBlockSection>
    </apex:pageblock>
    </apex:form>
    </apex:page>

    For Controller:-

    public class dynamicpicklistcontroller {

    public List<SelectOption> statusOptions { get;set; }
    public List<sObject> listofacc{get;set;}// You can use any sObject for which you want to apply the search
    public void autoRun()
    {
    statusOptions = new list<SelectOption>();
    listofacc = [select name from contact];//you can mention that sobject for which you want to apply query
    for(contact a : listofacc){
    statusOptions.add(new SelectOption(a.name,a.name));
    }
    }

  • Mohit

    Member
    September 29, 2016 at 5:58 am in reply to: What are the best practices of using insert option in Salesforce trigger?

    Hi Pranav,

    The Best Practices of using insert option in trigger are

    Before Insert:-

    1) We can use this during change fields using trigger.new

    2)You cannot update or delete original object using an update or delete DML operation because the original object has not been created; nothing can reference it, so nothing can update it.

    After Insert:-

    1) We cannot use  change fields using trigger.new because  a runtime error is thrown, as trigger.new is already saved.

    2)We can use after insert during update or delete original object using an update or delete DML operation. But in case of delete it is not necessary to use because the object is deleted immediately after being inserted.

  • Hi Pranav,

    There are some special kind of custom setting that include against the custom object. You can see that in the system overview of your organisation there you will see the an indicator bar show the details information about this. In my or there are 18 custom object and 10 custom setting so is showing me 28 custom object which is indicate in bar as 7% which of 28/400 of my salesforce org. You view this in picture below:-

    Screenshot

  • Mohit

    Member
    September 28, 2016 at 6:20 am in reply to: How to check a lead is converted or not in salesforce?

    Hi Pranav,

    Once the Leads are converted in a Salesforce Organisation, they aren't directly available in a Leads List View. To view the data of all converted Leads you will need to either use a standard Lead report or create a Custom Report Type based on your Organisation's needs. To create report to view converted lead this is the way:-

    1. Click the Report tab and then click the new Report.
    2. Select the (+) sign next to the Leads folder and select the report type Leads with converted lead Information and click Create
    3. Select the Add drop Down next to filter and select Field Filter.
    4. Set your criteria to Converted equals True.
    5. Click Run Report.
  • Mohit

    Member
    September 27, 2016 at 1:36 pm in reply to: How to create a universal search box in Salesforce?

    Hi Tanu,

    This is a code for the universal search for searching any kind of object and custom setting in your salesforce org it will give all value of all field available on the salesforce object:-

    String s1 ='';
    Integer i =0;
    String[] types = new String[]{'Account'};//sobject name
    Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
    for(Schema.DescribeSobjectResult res : results){
    for(Schema.SObjectField s : res.fields.getMap().values())
    {
    i=i+1;
    if(res.fields.getMap().size()>i){
    s1 = s1+s+',';
    }else
    s1=s1+s;
    }
    }
    sObject a = Database.query('Select '+s1+' From '+types[0]+' limit 1');
    System.debug('@@'+a);

  • Mohit

    Member
    September 27, 2016 at 12:54 pm in reply to: What is an Encrypted Field in salesforce?

    Hi Pranav,

    Encrypted Field is used to masked the data for user who don't have permission to view encrypted data.

    To make field encrypted in your salesforce Organisation:-

    1)Goto Setup, use the Quick Find box to find the Platform Encryption setup page.
    2)Click Encrypt Fields.
    3)Click Edit.
    4)Select the fields you want to encrypt, and save your settings.

    Note:- Make sure that your salesforce organisation has an active encryption key. If you’re not sure, check with your administrator. When you encrypt a field, existing values aren't encrypted immediately. Values are encrypted only after they are touched

    I hope this will help you.

  • Mohit

    Member
    September 26, 2016 at 12:06 pm in reply to: How can I get security token of my Salesforce org?

    Hi Pranav,

    You can get the security token of your salesforce org:-

    1)Goto your Org Name,

    2)Then goto MySetting and then on left side click on Personal  ,

    3)Then Click Reset my security token and now the new security token is sent to your email address in your salesforce personal setting

  • Mohit

    Member
    September 26, 2016 at 6:21 am in reply to: What is CPU time and How does it is calculated by Salesforce?

    CPU Time in Salesforce:-

    CPU time is calculated for all executions on the Salesforce application servers occurring in one Apex transaction—for the executing Apex code, and any processes that are called from this code, such as package code and workflows. CPU time is private for a transaction and is isolated from other transactions. Operations that don’t consume application server CPU time aren’t counted toward CPU time. For example, the portion of execution time spent in the database for DML, SOQL, and SOSL isn’t counted, nor is waiting time for Apex callouts.

  • Mohit

    Member
    September 23, 2016 at 6:15 am in reply to: What is the difference between these two(loop) codes?

    Hi Pranav,

    So you want difference between for loop and for each loop. As your first code for the for each loop and second code is for the for loop.

    1)We use the for each loop when we don't know the number of iteration it is going to iterate and we use for loop when we have fixed no of iteration like n size of iteration.

    2)When you want to add/remove items from the collection during iteration. This  will throw an exception that "Cannot modify a collection while it is being iterated." in Apex if you using first code but it will not thow exception when we use the second code.

    3)Perform the comparison operation between the current value or the previous or next value within the same list or separate list.It cannot be done in first code but can we achieve in second code.

    Eg:-for(Integer i =1 ;i<accountList.size()-1;i++){

    if(accountList[i]!=accountList[i+1])

    {}

    }

     

  • Hi Tanu,

    You cam detect the writing permission for a field on the visualforce page by two ways:-

    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. Hiding the field if it is not visible to them or making it read only if they cannot edit it.

    2)Visualforce $ObjectType:- We can also access this information using the $ObjectType global variable

    Eg-apex:outputText value="{!contactName}" rendered="{!$ObjectType.Contact.fields.Name.Accessible}"

  • Mohit

    Member
    September 22, 2016 at 6:05 am in reply to: How can I avoid the security risks with escape=false in salesforce?

    Hi Pranav,

    A Boolean value that specifies whether sensitive HTML and XML characters should be escaped in the HTML output generated by this component. If you do not specify escape="false", the character escape sequence displays as written. Be aware that setting this value to "false" may be a security risk because it allows arbitrary content, including JavaScript, that could be used in a malicious manner.

    By default, nearly all Visualforce tags escape the XSS-vulnerable characters. It is possible to disable this behavior by setting the optional attribute escape="false". For example, the following output is vulnerable to XSS attacks:

    <apex:outputText escape="false" value="{!$CurrentPage.parameters.userInput}" />

    Hope this help you

    Thanks.

  • Mohit

    Member
    September 22, 2016 at 5:25 am in reply to: How to wildcard SELECT * to query all fields of objects in APEX?

    Hi Tanu,

    There is no way to Select * with SOQL. You can however work with the limitation by using dynamic SOQL and describe methods to get all of the fields on the object. In this way you can get the result of the Select *  with soql  in salesforce.

  • Mohit

    Member
    September 21, 2016 at 2:01 pm in reply to: How to use two custom controllers in one Salesforce visualforce page?

    Hi Tanu,

    You can have the two controller functionality in one visualforce page by using standard controller and extension. So in extension you can mention the name of multiple controller from which you want to access the functionality of these controller . For example:-

    VisualForce page:-

    <apex:page standardController="Account"
    extensions="ExtOne,ExtTwo" showHeader="false">
    <apex:outputText value="{!foo}" />
    </apex:page>

    Extension Class:-

    ExtOne:-

    public class ExtOne {
    public ExtOne(ApexPages.StandardController acon) { }

    public String getFoo() {
    return 'foo-One';
    }
    }

    ExtTwo:-

    public class ExtTwo {
    public ExtTwo(ApexPages.StandardController acon) { }

    public String getFoo() {
    return 'foo-Two';
    }
    }

  • Mohit

    Member
    September 21, 2016 at 12:38 pm in reply to: Can we create custom Salesforce icons in tabs?

    Hi All,

    1)From Setup, enter Tabs in the Quick Find box, then select Tabs.

    2)Click New in the Custom Object Tabs/VisualForce Page / Web tabs related list..

    3)Click the Tab Style lookup icon to display the Tab Style Selector.

    4)click Create your own style on the Tab Style Selector dialog to create a custom tab style if your org has access to the Documents tab.

    5)Click the Color lookup icon to display the color selection dialog and click a color to select it.

    6)Click Insert an Image, select the document folder, and select the image you want to use.

    7)Select a file and click OK. The New Custom Tab wizard reappears.

    Now you have create your own custom tab style.

    Hope this will help you in solving issue.

  • Hi Pranav,

    This can be done if you temporarily change the field from autonumber format to Date format field.  Once it's date format, update your records in Data Loader with the appropriate numbering, then re-enable the autonumber field, making sure to set the starting number to pickup where you need it to.

Page 1 of 3