Forum Replies Created

Page 1 of 3
  • William

    Member
    May 9, 2019 at 7:19 am in reply to: How to convert lead using Salesforce Apex?

    trigger leadConversation on Lead (before update) {

    LeadStatus convertStatus = [select MasterLabel from LeadStatus where IsConverted = true limit 1];

    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

    for (Lead lead: Trigger.new) {

    if (!lead.isConverted && lead.status== 'Closed - Converted') {

    Database.LeadConvert lc = new Database.LeadConvert();

    String oppName = lead.Name;

    lc.setLeadId(lead.Id);

    lc.setOpportunityName(oppName);

    // Leadconvert.setDoNotCreateOpportunity(TRUE);

    lc.setConvertedStatus(convertStatus.MasterLabel);

     

    leadConverts.add(lc);

    }

    }

    if (!leadConverts.isEmpty()) {

    List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);

    System.debug(+'result'+lcr);

    }

    }

  • You cannot track the following field because Those fields can't directly be changed by a user, so it doesn't make sense to have tracking on them. The formula is based on other fields, you could track formula field.

    Formula,

    roll-up summary,

    auto-number,

    Created By,

    Last Modified By

  • William

    Member
    May 9, 2019 at 7:15 am in reply to: Can we use DML operation in Salesforce Apex Constructor?

    DML operation is not allowed in the constructor of Apex class. A constructor is mainly used to initialization of variables. Salesforce has blocked this due to security issues. Whenever we go for a DML operation in the constructor it restricts us in Salesforce. Only DDL is allowed. Salesforce has blocked this due to security issues. Whenever we trying to perform any DML operations at the time of initial page load we will be ending up with an error called System.LimitException: DML currently not allowed.

    If you want to do DML operation during VF page loading, use action attribute in <apex: page>. Call a method from the action in which DML operation is allowed

  • William

    Member
    May 9, 2019 at 7:11 am in reply to: What is Salesforce Apex Email Service?

    This is possible to associate each email service with multiple Salesforce-generated email addresses that would help the user in sending or receiving messages. This is possible to define access for a particular email service to multiple users together where the concept of Apex comes into existence.

    This email service will automatically create the contact records based on the attached contact details. This is easy to configure multiple email services from Set up option in the Salesforce by searching the Email Services option from the Quick find box.

  • William

    Member
    April 23, 2019 at 6:03 am in reply to: What is the list of tools are available in Salesforce Lightning?

    Salesforce Lightning is a robust platform using a set of tools for integrating with the third-party platform. There is one Salesforce Lightning Component Framework for designing digital components.  You could use APEX at the server side and the JavaScript on the client side. There is Lightning App builder to design apps with simple drag and drop option. Further, the integrated capabilities can be enhanced with SOAP or REST APIs. You can also use Salesforce Connect to connect with the third-party platform.

  • William

    Member
    March 6, 2019 at 7:24 am in reply to: What is the difference between empty and null in Salesforce?

    for the outside world, the difference could be negligible but it means a lot for the developers because it always results in different outcomes. Null is nothing but the default value that is assigned to any variable, not initialized yet. At the same time, an empty string is blank and it will return the length as zero because the string doesn’t contain anything.

  • William

    Member
    March 6, 2019 at 7:21 am in reply to: How can we provide field level security in Salesforce?

    If your organization contains a lot of data, this is necessary to limit the access of fields so that everyone could not edit them. By defining security settings at the field-level, you can define which user should access which field and either they can modify them or not. In this way, you can add utmost security to your existing data and make it secure from third-party users. The security settings can be defined for multiple fields together based on requirement.

  • William

    Member
    February 27, 2019 at 6:18 am in reply to: What is the order of execution in Salesforce Triggers?

    When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order.

    1.      The original record is loaded from the database

    2.      System Validation Rules.

    3.      Executes all before triggers.

    4.      Custom Validation rules.

    5.      Executes all after triggers.

    6.      Executes assignment rules.

    7.      Executes auto-response rules.

    8.      Executes workflow rules.

    9.      If there are workflow field updates, updates the record again.

    10.   If the record was updated with workflow field updates, fires before and after triggers one more time. Custom validation rules are not run again.

    11.   Process Builder (PB)

    12.  If process builder update any field then before and after triggers are executed one more time if the workflow rule updates a field (BT & AT)

    13.   Executes escalation rules.

    14.   If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.

    15.   If the parent record is updated, and a grand-parent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Grand-parent record goes through save procedure.

    16.   Executes Criteria Based Sharing evaluation.

    17.   Commits all DML operations to the database.

    18.   Executes post-commit logic. Ex: Sending email.

  • William

    Member
    February 27, 2019 at 6:17 am in reply to: What is the use of THIS CSS class in Salesforce?

    All top-level elements in a component have a special THIS CSS class added to them. This, effectively, adds namespacing to CSS and helps prevent one component's CSS from overriding another component's styling. The framework throws an error if a CSS file doesn't follow this convention.

    It’s easy to style a Visualforce page, either by mimicking the look and feel of a standard Salesforce page, or by using your own stylesheets or content types.

    Many Visualforce components have a style or style Class attribute. Defining either of these attributes allows you to associate CSS code with the component. Custom CSS code enables you to change the default visual style of a component, including its width, height, color, and font.

    Example

    <apex:page standardController=”Account” showHeader=”false” tabStyle=”account” >
        <style type=”text/css”>
            .asideText { font-style: italic; }
        </style>
        <apex:outputText style=”font-weight: bold;” value=”This text is styled By CSS.”/>
        <apex:outputText styleClass=”asideText” value=”This text is styled via a stylesheet class.”/>
    </apex:page>
  • William

    Member
    February 27, 2019 at 6:15 am in reply to: What are the best practices while writing test classes in Salesforce?

    Test methods and test classes are not counted as part of Apex code coverage.

    While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single records. This should lead to 75% or more of your code being covered by unit tests.

    1.      These classes should all use the @isTest annotation.

    2.      All test methods should be put in a separate class from the actual class where the method to be tested resides.

    3.      Test data creation should be done in a separate Utility class or in a test method annotated as ‘@testSetup‘.

    4.      Each test method should follow the signature — ‘@isTest static void myTest()‘ or ‘static testMethod void myTest()‘.

    5.      Always put assert statements for negative and positive tests

    6.      Use the @testSetup method to insert the test data into Test class that will flow all over the test class.

    7.      Always use Test.startTest() and Test.stopTest() doing this it will increase the governor limit of salesforce. We also use this to increase the governor limit.

    8.      Only one Test.startTest() and Test.stopTest() statement can be in a method, and no of Test.startTest() and Test.stopTest() statement in any test class depend upon the test methods.

    9.      Use System.runAs() method to test the functionality in user Context.

    10.  Do not put (seeAllData = true) in test class otherwise, use it for exceptional cases.

    11.  Avoid Using Hard Coding Ids anywhere in test Class or any apex class.

    12.  Please make sure that each class has a minimum 75% coverage and also the main functionality has been covered. If possible increase code coverage up to 95%.

     

  • William

    Member
    January 30, 2019 at 4:43 am in reply to: How are lead assignment rules executed in Salesforce?

    Lead Assignment Rules — An assignment rule dictates to users or queues is assigned based on criteria that are specified within Salesforce. Lead they are created manually, captured from the web, or imported via the lead import wizards.

    To set up a lead assignment rule, navigate to Set Up -> Build -> Leads -> Assignment Rules, and click “New.” Enter a descriptive Rule Name, check “Active,” and click “Save.”

  • No a custom and standard controller cannot be referenced on the same page. A custom and standard controller should not be supported at the same time; another way is you can use extensions instead of Custom Controller.

    Ex- <apex:page standardcontroller=""  extensions="controller name"/>

     

  • William

    Member
    January 15, 2019 at 7:10 am in reply to: What is Lightning Data Services in Salesforce?

    Lightning Data Services (LDS) is a new mechanism in Salesforce that was proposed in winter 2017 to edit, delete, or update records in Lightning Components. LDS reduces the need for APEX methods and improves the overall performance and user-interface consistency. With the help of simple mark-ups, records and the related fields can be quickly loaded to the Lightning Component. In this way, LDS could be taken as a strong consideration before you start with next component development. This can be definitely be taken as the big deal for the future projects.

  • William

    Member
    December 31, 2018 at 3:39 am in reply to: what is MVC in salesforce?

    Salesforce is based on the MVC architecture that has three components — Model — View — Controller. MVC is a software architecture pattern that separates the information representation from the users’ interaction with it. Salesforce is based on traditional MVC paradigm where interaction with the database is easier than your expectations and secure too.

    Model show what schema is used to represent the system completely?

    View layer shows how the schema is represented?

    Controllers are used to performing actions whenever the user interacts.

  • William

    Member
    December 31, 2018 at 3:38 am in reply to: what is the difference between the types of Sandboxes in Salesforce?

    There are four different types of sandboxes in the Salesforce like Developer Sandbox, Developer Pro Sandbox, Partial Copy Sandbox, and the Full Sandbox etc. Each sandbox has different objectives and purposed based on developer needs and requirements. They are mostly needed to develop or test an application in an isolated environment and making it highly suitable for use.

  • William

    Member
    December 24, 2018 at 5:21 am in reply to: What is enqueue action and app hostile in Salesforce?

    Enqueue action refers to the server-side controller activity to the line of activities to be executed. All activities that are enqueued will keep running toward the finish of the event loop. As opposed to sending a different demand for every individual action, the system forms the occasion chain and groups the activities in the line into one demand. The activities are asynchronous and have callbacks.

    App hostile is the situation that occurs when the callbacks in the enqueue loop are hindered due to a faulty code or asynchronous instruction.

  • William

    Member
    December 24, 2018 at 5:19 am in reply to: Difference between Sandbox and Development environment in Salesforce?

    A sandbox can be a test territory where you put the dubious code to give it a shot before placing it into the final execution streams. It can likewise be a security component that places programs in their very own zone where they can't influence other running projects. Whereas, a development environment is nothing but a collection of stuff that you are going to use to compose the code and produce a related software.

  • William

    Member
    December 19, 2018 at 3:51 am in reply to: How can we give auto size the Salesforce visualforce page?

    Try this code:

    <apex:page sidebar=”false”>
        <apex:iframe src=”https://www.salesforce.com/” id=”theFrame” />
        <script>
            (function() { //this wrapper prevents pollution of the global scope
            var windowOnresize = window.onresize;
            window.onresize = function() {
                if (windowOnresize) windowOnresize(); //don’t trample the handler; intercept it
                document.getElementById(‘theFrame’).height = window.innerHeight — 220;
            };
            }());
        </script>
    </apex:page>
  • William

    Member
    December 14, 2018 at 4:41 am in reply to: How to determine whether to use After or before in Salesforce trigger?

    1.        "before" triggers to validate data or update fields on the same record being triggered.

    2.        "after" triggers to update parent or related records

    3.        "insert" for events that occur on record creation

    4.        "update" for events on existing records

    BEFORE trigger

    1.      BEFORE triggers are usually used when validation needs to take place before accepting the change. They run before any change is made to the database.

    2.      In case of validation check in the same object.

    3.      Insert or update the same object.

    AFTER trigger

    1.      AFTER triggers are usually used when information needs to be updated in a separate table due to a change.

    2.      They run after changes have been made to the database (not necessarily committed).

    3.      Insert/Update related object, not the same object.

    4.      Notification email.

    5.      We cannot use After trigger if we want to update a record because it causes read-only error. This is because after inserting or updating, we cannot update a record.

  • William

    Member
    December 14, 2018 at 4:38 am in reply to: How to make a dynamic picklist in salesforce?

    Apex class
    public class ScemaMultiDisplayEx {
    public list<selectOption>notSelectedOption{set;get;}
    public list<selectOption>SelectedOption{set;get;}
    public list<selectOption>SelecteObject {set;get;}
    public set<string>NotSelectedFields{set;get;}
    public set<string>SelectedFields{set;get;}
    public list<string>FieldNames{set;get;}
    Public list<string>nonSelected{set;get;}
    Public list<string>Selected{set;get;}
    public map<string,schema.SObjectType>ObjectMap    {set;get;}
    public map<string,schema.SObjectField>fieldMap {set;get;}
    public list<Sobject>result                     {set;get;}
    public string SelectedObject                   {set;get;}
    public ScemaMultiDisplayEx(){
    ObjectMap= new map<string,schema.SObjectType>();
    notSelectedOption= new list<selectOption>();
    SelectedOption= new list<selectOption>();
    SelecteObject=new list<selectOption>();
    NotSelectedFields= new set<string>();
    SelectedFields = new set<string>();
    Selected= new list<string>();
    nonSelected= new list<string>();
    ObjectMap=schema.getGlobalDescribe();
    fieldMap=new map<string,schema.SObjectField>();
    selectOption op = new selectOption('None','-None-');
    SelecteObject.add(op);
    notSelectedOption.add(op);
    SelectedOption.add(op);
    for(string s:ObjectMap.keySet()){
    selectOption op1= new selectOption(s,s);
    SelecteObject.add(op1);
    }
    }
    public void getOption(){
    schema.SObjectType obj = ObjectMap.get(SelectedObject);
    schema.DescribeSObjectResult res=obj.getDescribe();
    FieldMap=res.Fields.getMap();
    NotSelectedFields.addAll(fieldMap.keyset());
    getValue();
    //system.debug(NotSelectedFields);
    }
    public void getValue(){
    notSelectedOption.clear();
    SelectedOption.clear();
    Selectoption op= new selectoption('None','-None-');
    if(NotSelectedFields.size()>0){
    for(string ss: NotSelectedFields){
    selectoption p1= new selectoption(ss,ss);
    notSelectedOption.add(p1);
    }
    }else{
    notSelectedOption.add(op);
    }
    if(SelectedFields.size()>0){
    for(string s:SelectedFields){
    selectoption p= new selectoption(s,s);
    SelectedOption.add(p);
    }
    }else{
    SelectedOption.add(op);
    }
    }
    public void AddRecords(){
    NotSelectedFields.removeAll(Selected);
    SelectedFields.addAll(Selected);
    getValue();
    }
    public void RemoveRecord(){
    SelectedFields.removeAll(nonSelected);
    NotSelectedFields.addAll(nonSelected);
    getValue();
    }
    }
    Visulforce page
    <apex:page controller="ScemaMultiDisplayEx" showHeader="false" >
    <style>
    .b{
    width:200px;
    height:200px;
    color:Blue;
    }
    </style>
    <apex:form >
    <apex:pageBlock >
    Choose a Object <apex:selectList size="1" value="{!SelectedObject}">
    <apex:selectOptions value="{!SelecteObject}"/>
    <apex:actionSupport event="onchange" action="{!getOption}" reRender="one" />
    </apex:selectList>
    <apex:panelGrid columns="3" id="one">
    <apex:selectList multiselect="true" value="{!Selected}" styleClass="b">
    <apex:selectOptions value="{!notSelectedOption}"/>
    </apex:selectList>
    <apex:panelGrid columns="1">
    <apex:commandButton value="ADD" action="{!AddRecords}" reRender="one" />
    <apex:commandButton value="DEL" action="{!RemoveRecord}" reRender="one" />
    </apex:panelGrid>
    <apex:selectList multiselect="true" value="{!nonSelected}" styleClass="b"  >
    <apex:selectOptions value="{!soption}"/>
    </apex:selectList>
    </apex:panelGrid>
    </apex:pageBlock>
    <apex:pageBlock title="Records" rendered="{! !Isnull(result)}">
    <apex:pageBlockTable value="{!result}" var="a">
    <apex:repeat value="{!FieldNames}" var="b">
    <apex:column value="{!a[b]}" />
    </apex:repeat>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
    </apex:page>

  • William

    Member
    December 11, 2018 at 5:25 am in reply to: How to create a search page on Salesforce Lightning?

    Here is the code, you can use:

    Apex class

    public class ContactSearch {

    @AuraEnabled

    public static list<string>getAccount(){

    list<string>options= new list<string>();

    for(contact acc:[select name from Contact]){

    options.add(acc.name);

    system.debug('options name values'+options);

    }

    return options;

    }

    }

    Cmp

    <aura:component controller="ContactSearch ">

    <!--start attributes here-->

    <aura:attribute name="selectedOptions" type="string"/>

    <aura:attribute name="listOfOptions" type="string[]"/>

    <aura:attribute name="filteredOptions" type="string[]"/>

    <aura:attribute name="searchLookup" type="string"/>

    <aura:attribute name="searchKey" type="string"/>

    <aura:attribute name="placeholder" type="string"/>

    <aura:attribute name="actionMethod" type="string"/>

    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>

    <!-- clse attributes here-->

    Conatct Search {!v.listOfOptions}

    <div class="slds-form-element">

    <div class="slds-form-element__control">

    <div class="slds-combobox_container slds-has-inline-listbox">

    <div class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-combobox-lookup"

    aria-expanded="false"

    aria-haspopup="listbox"

    role="combobox"

    aura:id="searchLookup">

    <div class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right" >

    <ui:inputText updateOn="keyup"

    keyup="{!c.keypress}"

    class="slds-input slds-combobox__input"

    value="{!v.searchKey}" />

    <aura:if isTrue="{!empty(v.selectedOptions)}">

    <span class="slds-icon_container slds-icon-utility-search slds-input__icon slds-input__icon_right"

    title="Description of icon when needed">

    <lightning:icon iconName="utility:search" size="small" variant="brand"/>

    <span class="slds-assistive-text">Description of icon</span>

    </span>

    <aura:set attribute="else">

    <button class="slds-button slds-button_icon slds-input__icon slds-input__icon_right"

    onclick="{!c.clear}">

    <lightning:icon iconName="utility:close" size="small"/>

     

    <span class="slds-assistive-text">Remove selected option</span>

    </button>

    </aura:set>

    </aura:if>

    </div>

    <div id="listbox-unique-id" role="listbox">

    <ul class="slds-listbox slds-listbox_vertical slds-dropdown slds-dropdown_fluid"

    role="presentation">

    <aura:iteration items="{!v.filteredOptions}" var="option">

    <li role="presentation"

    class="slds-listbox__item"

    onclick="{!c.selectOption}"

    data-record="{!option}">

    <span id="listbox-option-unique-id-01"

    class="slds-media slds-listbox__option slds-listbox__option_entity slds-listbox__option_has-meta"

    role="option">

    <span class="slds-media__body">

    <span class="slds-listbox__option-text slds-listbox__option-text_entity">{!option}</span>

    </span>

    </span>

    </li>

    </aura:iteration>

    </ul>

    </div>

    </div>

    </div>

    </div>

    </div>

    </aura:component>

     

    Controller.js
    ({
    myAction : function(component, event, helper) {
    helper.helperMethod(component);
    },
    keypress:function(component,event,helper){
    var searchKey= component.get("v.searchKey");
    //alert('serach key value'+searchKey);
    var searchLookup=component.get("v.searchLookup");
    // alert('serach'+searchLookup);
    var searchLookup=component.find("searchLookup");
    //  alert('search key value is '+searchLookup);
    if(searchKey.length>0){
    $A.util.addClass(searchLookup,'slds-is-open');
    $A.util.removeClass(searchLookup,'slds-combobox-lookup');
    var options=component.get("v.listOfOptions");
    var filteredOptions=options.filter(function (el){
    return el.toLowerCase().indexOf(searchKey.toLowerCase())>-1;
    });
    component.set("v.filteredOptions",filteredOptions);
    }else{

    $A.util.addClass(searchLookup,'slds-combobox-lookup');
    $A.util.removeClass(searchLookup,'slds-is-open');
    }
    },
    clear: function (component, event, heplper) {
    var searchLookup = component.find("searchLookup");
    $A.util.addClass(searchLookup, 'slds-combobox-lookup');
    component.set("v.selectedOptions", null);
    component.set("v.searchKey", null);
    },
    selectOption: function (component, event, helper) {
    var selectedItem = event.currentTarget.dataset.record;
    alert('selected value is'+selectedItem);
    component.set("v.selectedOptions", selectedItem);
    var searchLookup = component.find("searchLookup");
    $A.util.removeClass(searchLookup, 'slds-is-open');
    component.set("v.searchKey", selectedItem);

    }
    })
    Helper.js
    ({
    helperMethod : function(component){
    var actionMethod = component.get("v.actionMethod");
    var action = component.get("c.getAccount");
    action.setCallback(this, function (response) {
    var state = response.getState();
    if (state === "SUCCESS") {
    var options = response.getReturnValue();
    //  alert('Returned values'+response.getReturnValue());
    //console.log(options);
    component.set("v.listOfOptions", options);
    }
    });
    $A.enqueueAction(action);
    },
    })
    Application
    <aura:application extends="force:slds" >
    <c:ComponentName/>
    </aura:application>

  • William

    Member
    December 10, 2018 at 3:55 am in reply to: Explain use of Junction Object in Salesforce.

    In salesforce junction object is a custom object which uses one instance of a record to many child records. A custom object with two master-detail relationships. Using a custom junction object, you can model a “many-to-many” relationship between two objects. For example, you may have a custom object called “Bug” that relates to the standard case object such that a bug could be related to multiple cases and a case could also be related to multiple bugs.

  • William

    Member
    December 10, 2018 at 3:20 am in reply to: what is the meaning of indexed fields in Salesforce?

    Below Fields that are automatically indexed in Salesforce are:

    ·         Name

    ·         CreatedDate

    ·         Systemmodstamp (LastModifiedDate)

    RecordTypeId
    RecordOwner
    Relationships (lookups and master-detail)
    Custom fields marked as External ID or Unique.

  • Here is step by step process for Salesforce MailChimp integration through an app.

    Firstly, install and configure the app in Salesforce. The app is quickly available at the Salesforce AppExchange for download.

    Once you have installed the app successfully, the next step is to define MailChimp sections to your content layouts. For this purpose, go to the Setup -> leads/Contacts -> Fields -> Layouts.

    In the Layout, you can see the VisualForce page. Simply drag and drop the Membership Contact section to the layout created by the MailChimp app you installed currently.

    For professional or unlimited editions, you can also add MC fields in the layout designer section. You have the flexibility to change the fields in the Layout Designer section.

    Don’t forget to save the changes at each step.

    Reference - https://www.janbask.com/blog/mailchimp-and-salesforce-integration/

  • William

    Member
    December 1, 2018 at 4:50 am in reply to: Difference between Communities and Sites in Salesforce?

    Community Cloud is a social stage of the Salesforce.com that is intended to associate and encourage correspondence among an association's representatives, accomplices and clients

    Whereas sites in Salesforce empowers you to make open sites and applications that are straightforwardly coordinated with your Salesforce association—without expecting clients to sign in with a username and secret key. You can freely uncover any data which has been put away in your association through a marked URL of your choice.

Page 1 of 3