Showing posts with label picklist. Show all posts
Showing posts with label picklist. Show all posts

Thursday, 16 June 2022

Delete Inactive Picklist Values in Bulk (Beta)

With the Salesforce summer’22 release, we can bulk delete unused inactive picklist values. Before the release of summer’22, custom picklists with many inactive values were difficult to maintain because we can delete inactive ones at a time. let’s take a look in brief.

Clean Up Inactive Picklist Values (Beta)

Managing inactive picklist values and establishing restrictions on the number of inactive values for custom picklists can help your Salesforce org run more smoothly and efficiently. You can bulk delete inactive unused values from a picklist if there are a lot of them.

Below are the steps to avail of this feature in your org.

Active Bulk delete inactive picklist values(Beta) option

  • Click Setup.
  • In the Quick Find box, type Picklist Settings.
  • Activate Bulk Delete Inactive Picklist Values (Beta) option.

Bulk Delete Inactive Picklist Values
Now, we will get the option to bulk delete inactive unused picklist values.

Below are the rules that apply while bulk deleting picklist values.

Rules
  • This feature is available only for custom picklist fields on an object. It’s not available for standard or multi-select picklist fields.
  • This feature is only for picklist fields that have defined values. It’s not available for picklist fields that use a global value set.
  • This feature deletes inactive, unused picklist values. If a picklist value is inactive but still referenced in a record, the value isn’t deleted.
  • After you delete unused values, if a picklist is unbound and the total number of inactive values falls below the limit, the field is set to a bound picklist.
  • While the job that deletes inactive values runs, these actions are unavailable on that picklist field: Activate, Activate Selected, Deactivate, Deactivate Selected, Delete, Delete Selected, Replace, and Replace Selected. The buttons are enabled, but an error message is returned when you click them.
  • While the job that deletes inactive values runs, changes to the picklist field via Metadata API are unavailable. You can retrieve data from the field, but you can’t: create a picklist value, update the field or its values, delete the field or its values, or deploy the field.

Follow the below steps to delete all inactive unused values from a picklist.

  • Click Setup.
  • Click on Object Manager, and select your Object.
  • Click on Fields & Relationships, and click the picklist field. In the Picklist Values Used section, you can see how many inactive picklist values the field has.
  • From the Inactive Values section of the picklist field, click Delete Unused Values.

Delete unused values

After all of the picklist values have been deleted, you will receive an email indicating whether or not the deletion was successful. The email is sent to the user whose email address was used to initiate the deletion.

Click here to see release notes of summer'22 on Clean Up Inactive Picklist Values (Beta) 

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday, 24 February 2022

[Resolved:] Set value of the picklist field for the selected records to mass update in lightning web component.

SCENARIO 

While working on one of the requirements for a manufacturing sector solutions customer based out in Dallas, Texas there was a requirement to set selected value of picklist field to mass update of records in lightning web component.

CHALLENGE 

We have achieved this functionality of setting the value of picklist by creating  custom lightning web component. We have used custom javascript functions to update mass records. 

However, we got stuck with the issue of updating records for the selected value. 

APPROACH

To fulfill this requirement,we decided to create custom javascript functions to select multiple files and to assign values to each files. 

Below is a sample code for reference.

HTML Code:-

    <template>
      <lightning-card title="Account List"> 
        <div class="slds-m-around_medium" >

        
        <div class='slds-grid slds-gutters'>
          <div class='slds-col'>
            <lightning-input type="checkbox" onchange={handleSelectAllIndustryChk}
                             label="Select All" data-id="selectAllIndustry">
          </lightning-input>

          </div>
         </div>
         <template for:each={accounts} for:item="account" for:index="index">
          <div class='slds-grid slds-gutters' key={account.Name}>
            <div class='slds-col slds-m-top_large slds-size_1-of-7'>
              <lightning-input type="checkbox" name={account.Name} data-class="cus_IndustryHelper"
              onchange={handleIndustryCheckbox} data-id='IndustryTypeChk'>
              </lightning-input>
              </div>
              <div class='slds-col slds-size_3-of-7'>
                <lightning-input label="Account Name" type="text" value={account.Name}
                                  disabled="true">
                </lightning-input>
              </div>
              <div class='slds-col slds-size_3-of-7'>
                <lightning-combobox name={account.Name} label="Industry" data-id={account.Name}
                                    class="picklistContent"  dropdown-alignment="auto"
                                    placeholder="Select account Type" options={IndustryPicklist.data.values}
                                    onchange={handleIndustrySelectionChange} required>
                </lightning-combobox>
              </div>
          </div>
        </template>
      </div>
      </lightning-card>  
    </template>    
  

JavaScript Code:-

import { LightningElement, api, wire, track } from 'lwc';
import AccountList from '@salesforce/apex/AccountController.AccountList';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import Account_OBJECT from '@salesforce/schema/Account';
import Industry_FIELD from '@salesforce/schema/Account.Industry';
   
export default class DataTableInLwc extends LightningElement {
    
    @track accounts=[];
    @track selectedIndustryValues=[];
    
    

  @wire(AccountList)
  wiredfiles(result){
      
      if(result.data){
          this.accounts=result.data;
          
      }
      else{
          console.log('Data not found');
      }
    }


    @wire(getObjectInfo, { objectApiName: Account_OBJECT })

    AccountMetadata;

    @wire(getPicklistValues,

        {

            recordTypeId: '$AccountMetadata.data.defaultRecordTypeId',

            fieldApiName: Industry_FIELD

        }

    )

    IndustryPicklist;
    
   

    handleSelectAllIndustryChk(event) {
    this.selectedIndustryValues = [];
    var checkboxes = this.template.querySelectorAll('[data-id="IndustryTypeChk"]');
    for (var i = 0; i < checkboxes.length; i++) {
        checkboxes[i].checked = event.target.checked;
        event.target.checked ? this.selectedIndustryValues.push(checkboxes[i].name) : '';
        }
    }

        
        handleIndustryCheckbox(event) {
            if (event.target.checked) {
                this.selectedIndustryValues.push(event.target.name);
                let checkboxes = this.template.querySelectorAll('[data-class="cus_IndustryHelper"]');
                let length = 0;
                for (var i = 0; i < checkboxes.length; i++) {
                    (checkboxes[i].checked == true) ? length = length + 1: length = length - 1;
                }
                ((checkboxes.length) == length) ? this.template.querySelectorAll('[data-id="selectAllIndustry"]')[0].checked = true: this.template.querySelectorAll('[data-id="selectAllIndustry"]')[0].checked = false;
            } else {
                this.selectedIndustryValues.splice(this.selectedIndustryValues.indexOf(event.target.name), 1);
                this.template.querySelectorAll('[data-id="selectAllIndustry"]')[0].checked = false;
                length -= 1;
            }
        }
            
        handleIndustrySelectionChange(event)
        {
            if (this.selectedIndustryValues.indexOf(event.target.name) != -1) {
                for (var i = 0; i < this.selectedIndustryValues.length; i++) {
                var selected = this.template.querySelectorAll('[data-id="' + this.selectedIndustryValues[i] + '"]')[0];
                selected.value = event.target.value;
                   }
                }
        }



}  


  • handleSelectAllIndustryChk:- By clicking select all checkbox it will check all the checkboxes.
  • handleIndustryCheckbox:- Checks for checkboxes to see whether it is selected or
    
    unselected.
  • handleIndustrySelectionChange:- Used when value is selected from the picklist 
    
    and assigns that value to each and every selected picklist.

Apex Class:-

public with sharing class AccountController {
    @AuraEnabled(cacheable=true)
    public static List<Account> AccountList() {
        return [SELECT Id, Name ,Industry FROM Account LIMIT 5 ];
    }
}

OUTPUT:-




CONCLUSION
 
By using above mentioned javascript functions, We are able to set selected value of picklist field based for bulk/mass update records in lightning web component.

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday, 6 January 2022

[Resolved:] Set default value to dependent picklist based on the value selected on controlling picklist in VF page

SCENARIO 

While working on one of the requirements for a health sector solutions customer based out Atlanta, Georgia there was a requirement to assign default value to particular dependent picklist field based on value selected on controlling picklist field in VF page.

 
CHALLENGE 

Although, We can achieve the requirement by making the field mandatory on page layout but  the client doesn't want that field to be required. So we have made custom JS to set default value to dependent picklist based on controlling picklist field value in the VF page.


RESOLUTION 

To fulfil the requirement, we have used <apex:actionFuntion> tag of visualforce page. By using this tag, we can call apex controller method from Javascript code  using  an  AJAX  request.   

Below is a sample code for reference. Here, we get the value of controlling picklist field and calling apex class using <apex:actionFunction>. 

ActionFunctionVFPage.vfp
<apex:page controller="retrieveValue">
    <script>
    function changefield(regionValue){
        
        var r =document.getElementById(regionValue);
        
        if(regionValue == "India"){            
            rerendAction();
        }
    }
    </script>
    <apex:form >
        <apex:sectionHeader title="Account" subtitle="Region Picklist Value"/>
        <apex:actionFunction action="{!zoneValue}" name="rerendAction" rerender="zone"/>
        <apex:pageblock id="pageRender">
            
            <apex:pageblocksection >
                
                <apex:pageblocksectionitem >
                    
                    <apex:outputlabel value="Region"/>
                    
                    <apex:inputField value="{!acc.Region__c}" onchange="changefield(this.value)"/>
                </apex:pageblocksectionitem>
                
            </apex:pageblocksection>
            
            <apex:pageblocksection id="zonefield">
                
                <apex:pageblocksectionitem >
                    <apex:outputlabel value="Zone"/>
                    <apex:inputField value="{!acc.Zone__c}" id="zone"/>
                    
                </apex:pageblocksectionitem>
                
            </apex:pageblocksection>
        </apex:pageblock>
        
    </apex:form>
    
</apex:page>

ActionFunctionController.apxc
global class retrieveValue {
    public Account acc{get;set;}
    public retrieveValue(){
        acc=new Account();
    }
  
    public void zoneValue()
    {
         acc.Zone__c = 'West_Zone';
    }
    
}

In apex class, we are setting default values to dependent picklist and action function will reRender the dependent picklist field.
                           
Output


CONCLUSION 

By Using custom JS and <apex:actionFuntion> , we are able to set default value to dependent picklist field based on value selected on controlling picklist field in VF page. 

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday, 18 March 2021

Display Picklist values dynamically in lightning component


Requirement:
While working on one of the user stories of Engineering sector project for a client based out of Tampa, FL, USA;  there was a requirement to provide an interface that would display selected Industry (Pick-list field) values for Accounts on the fly while performing Mass Edit.

Challenge: 

Mass Edit feature was implemented using the Custom Lightning component. And, t
here is no out-of-the-box (OOTB) feature available to display selected pick-list values in the in lightning component, while bulk edit is being performed.

Solution:
To overcome this limitation, we have created an Apex class that contains the mechanism to retrieve the list of Industry (pick-list) field values from the Account object.

This Apex class is then used by Custom Lightning Component (BulkEdit.Cmp) which displays the list of Accounts. Using component.get ("v.pickvalues") in DynamicPickController component, we are retrieving selected pick-list values from the Parent Component (BulkEdit.cmp). 

Then Industry pick-list values are being compared with the values that have been retrieved from Parent Component. If field values are matched, it will set the selected Industry field value.

If values are not matched, then it will set the first value from the pick list options.

Once comparison is done,  value is set to the attribute IndustryPick that we have defined in the Custom DynamicPickController.Cmp component.

BulkEdit.cmp
<aura:iteration items="{!v.selectedlst}" var="ac" >
                                    <c:DynamicPickController selectedOptions = '{!v.selectedlst}'
                                                  Name = '{!ac.lstTelLineAccLocUserobject2.Name}'
                                                  Industry = '{!ac.lstTelLineAccLocUserobject2.Industry}'
                                                  pickvalues = '{!v.pickvalues}'
                                                  />
</aura:iteration>

DynamicPickController.Js
doInit : function(component, event, helper) {
        var IndustryPick = [];
        for(var i = 0 ; i < component.get("v.pickvalues").length ; i++)
        {
            if(component.get("v.pickvalues")[i] == component.get("v.Industry"))  
            {
                IndustryPick.push({"label":component.get("v.pickvalues")[i], "value":component.get("v.pickvalues")[i], "selected":true})
            }
            else
            {
                IndustryPick.push({"label":component.get("v.pickvalues")[i], "value":component.get("v.pickvalues")[i]})
            }
        }
        component.set("v.IndustryPick", IndustryPick);
    }

DynamicPickController.Cmp
<aura:attribute name="pickvalues" type="list"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<lightning:select name="Industry" label="Select a Industry:" aura:id="Industry" value="{!v.Industry}">
                <aura:iteration items="{!v.IndustryPick}" var="option">
                    <option text="{!option.label}" value="{!option.label}" selected="{!option.selected}"/>
                </aura:iteration>
</lightning:select>

Output:

If you have any questions you can reach out our Salesforce Consulting team here.

Wednesday, 23 December 2020

Cascading pick-lists using apex:actionRegion component in Visualforce page

Requirement:

We had to provide the cascading functionality for dependent pick-list in a Visualforce page based on the selection in the controlling pick-list dynamically. 

Challenge: 

The Visualforce page was a registration form that had pick-lists for the state. But, the OnChange event of the controlling pick-list (country) was not calling the apex function which was responsible to perform the cascading in the dependent pick-list (state). Moreover, we were unable to trace any error while debugging the code.

Solution:

After relentless efforts and trying multiple solutions by digging into standard Salesforce documents, we tried a solution to enclose the <apex:actionsupport> component within <apex:actionRegion> component considering, that this would submit the data that is bound within this region. And, that worked like a gem!


<apex:actionRegion>

  // Your code here

</apex:actionRegion>

Hence, by wrapping the <apex:selectlist> component within <apex:actionRegion>, the input was getting submitted to the controller, thus, allowing it to fire the event.

<apex:pageBlock>
    <apex:pageBlockSection columns="2">
        <apex:pageblockSectionItem>
            <apex:outputLabel value="Country"/>
        </apex:pageblockSectionItem>        
        <apex:pageblockSectionItem>
            <apex:actionRegion>
                <apex:selectList size="1" value="{!country}">
                    <apex:selectOptions value="{!countries}"/>
                    <apex:actionSupport event="onchange" reRender="state"/>
                </apex:selectList> 
            </apex:actionRegion>
        </apex:pageblockSectionItem>
        <apex:pageblockSectionItem>
            <apex:outputLabel value="State"/>
        </apex:pageblockSectionItem>            
        <apex:pageblockSectionItem>
            <apex:selectList size="1" value="{!state}" id="state">
                <apex:selectOptions value="{!states}"/>
            </apex:selectList>
        </apex:pageblockSectionItem>            
    </apex:pageBlockSection>        
</apex:pageBlock>

If you have any questions you can reach out our Salesforce Consulting team here.