Posts

Showing posts with the label salesforce

Mark custom object record as duplicate via Apex for large (100,000+) data sets

 Problem statement Let's say I have a data load that inserts 100,000 unique records of a custom object - call it MyObject__c. Each record has a lookup to a Contact record that is populated. I want to iterate over the entire list of 100,000 inserted records and find all of the records of MyObject that look up to the same Contact, and then set a checkbox on all but one record that indicates they are 'duplicates'. Example: there are 5 record of MyObject (out of 100,000) that all look up to the Contact MyContact (SFID 123456789). After processing the entire list of 100,000 records, I'd have four of the five records have a 'duplicate reference' checkbox marked, with the fifth one having it unchecked. Basically a uniqueness check on the lookup. What would be the best way to accomplish something like this? My current thought process is to build an Apex batch job; The batch runs the query to get all MyObject records that need to be processed (100,000) and splits them in...

Dynamically Pass Bind Variables to a SOQL Query - salesforce release'23

  With the new  Database.queryWithBinds ,  Database.getQueryLocatorWithBinds , and  Database.countQueryWithBinds  methods, the bind variables in the query are resolved from a Map parameter directly with a key rather than from Apex code variables. As a result, it’s not necessary for the variables to be in scope when the query is executed. Where:  This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions. How:  In this example, the SOQL query uses a bind variable for an Account name. Its value ( Acme Corporation ) is passed in using the  acctBinds  Map. Map<String, Object> acctBinds = new Map<String, Object>{'acctName' => 'Acme Corporation'}; List<Account> accts = Database.queryWithBinds('SELECT Id FROM Account WHERE Name = :acctName', acctBinds, AccessLevel.USER_MODE); SEE ALSO

Use the System.enqueueJob Method to Specify a Delay in Scheduling Queueable Jobs

Image
  A new optional override adds queueable jobs to the asynchronous execution queue with a specified minimum delay (0–10 minutes). Using the  System.enqueue(queueable, delay)  method ignores any org-wide enqueue delay setting. The delay is ignored during Apex testing. Where:  This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions. How:  Here are some cases where it can be beneficial to adjust the timing before the queueable job runs. If the external system is rate-limited and can be overloaded by chained queueable jobs that are making rapid callouts. When polling for results, and executing too fast can cause wasted usage of the daily async Apex limits. This example adds a job for delayed asynchronous execution by passing in an instance of your class implementation of the  Queueable  interface for execution. There’s a minimum delay of 5 minutes before the job is executed. Integer de...

Synchronize Component Data Without a Page Refresh Using RefreshView API (Beta)

Image
  Whether user-driven or app-invoked, the ability to synchronize data without reloading an entire page is a key user experience requirement. The new  lightning/refresh  module and RefreshView API provide a standard way to refresh component data in LWC and Aura. Previously, LWC lacked a data refresh API, and Aura only supported the legacy  force:refreshView , which doesn’t meet the requirements of modern web development. RefreshView API’s detailed control of refresh scope lets developers create refined user experiences while maintaining backward compatibility. Where:  This change applies to Lightning Experience in Enterprise, Unlimited, and Developer editions. NOTE This feature is a Beta Service. Customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at  Agreements and Terms . How:  RefreshView API updates the data for a specific hierarchy of components, kno...

View Debug Information for Your Wired Properties Spring'23 release

Image
  Access debug information for wired properties and methods on a component via custom formatters in Chrome DevTools. Where:  This change applies to custom Lightning web components in Lightning Experience, Experience Builder sites, and all versions of the Salesforce mobile app. This change also applies to Lightning web components in Open Source. Why:  Previously, to debug data received with a wired property, you had to use a wired function to return your data and inspect the deconstructed  data  and  error  properties. How:  Consider a wired property that looks like this. import { LightningElement, wire } from 'lwc'; import getContactList from '@salesforce/apex/ContactController.getContactList'; export default class ApexWireMethodToProperty extends LightningElement { @wire(getContactList) contacts; } NOTE  For a full example, see the  apexWireMethodToProperty  component in the  lwc-recipes  repo. To start debugging you...

Mixed shadow mode is available as a developer preview with Sprint'23 release

Image
  Build Components in Mixed Shadow Mode (Developer Preview) With mixed shadow mode, Lightning web components can use native shadow DOM even when the synthetic shadow polyfill is applied. Where:  This change applies to custom Lightning web components in Lightning Experience, Experience Builder sites, and all versions of the Salesforce mobile app. This change also applies to Lightning web components open source. NOTE  Mixed shadow mode is available as a developer preview. This feature isn't generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Don't implement functionality developed with these commands or tools. Why:  All major browsers now support  shadow DOM . Salesforce maintains the  synthetic shadow polyfill  for legacy browsers such as older ver...

Sample Package.xml for salesforce

Many a time we search the format and list of components which can be retrieved by package.xml. Below list will help in such scenario. <package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>Case-page layout name</members> <name> Layout </name> </types> <types> <name> WebLink </name> </types> <types> <members>*</members> <name>ApexPage</name> </types> <types> <members>*</members> <name>ApexClass</name> </types> <types> <members>Triggger_name</members> <name>ApexTrigger</name> </types> <types> <members>ESD_Report_Data_Archive__c</members> <members>*</members> <name>CustomObject</name> </types> <types> <members>object_api_nam...

SFDC : Create ANT Package.xml from Change set

Image
Chrome Extension which generate package.xml from change set Salesforce has powerful tool, change set, which provides admins the ability to move and deploy bundle of components to different connected SFDC ORGs. However it becomes tedious when you have to keep in sync several sandboxes. Or if you have big project going on having big list of components, in this case you need to select all the components one by one which is time consuming job. There is one idea to create package.xml from change set. https://success.salesforce.com/ideaView?id=08730000000jh8sAAA# However till the time this idea is delivered by salesforce, I have created a chrome extension which extracts the components of change sets and creates package.xml. https://chrome.google.com/webstore/detail/sfdc-magic-toolkit/kilgdoafhhpkloidoajmlfienjndfbfo?utm_source=chrome-ntp-icon We know that through ANT migration tool we can easily deploy set of components to different sandboxes hence this exte...

SFDC Issue in Runtime engine while bulk DML operation

Image
Salesforce Issue in partial record processing in bulk DML operation Here we will go through the issue related to partial record processing in bulk DML operations for example. Data loader, or database.insert( listSobject, false ). What is partial update? To understand the issue, first let’s understand partial update. Suppose we try to insert 5 records into Lead object and 1 fails 4 succeeds. This is called partial records processing in bulk DMLs. Scenario Let’s execute a scenario and prove that there is an issue with Salesforce partial record processing . Suppose we have a trigger as shown below. This sets the email field for all the newly inserted leads. 2.         Now suppose we insert below listed leads using data loader. Since we know that Company is mandatory on lead object, So last lead ‘Lead10’ should fail and all other should be successfully inserted. Also for success full leads email id should be set to ‘testemail@domain.co...

Governor limit SOQL 101 being suppressed

System.LimitException: Too many SOQL queries: 101 Did anyone faced scenario where SOQL 101 governor limit is not being reported to user interface (UI), instead it is being logged into debug logs ? Please provide your thoughts in the comments if there exists any possible scenario. As far as I know, Governor limits can not be suppressed and will be shown to user on the UI. However I am facing below scenario where SOQL 101 limit is being logged into debug log and not being shown in the UI. 1.User converts the lead. 2.Account, Opportunity, Contact created. 3.User is successfully redirected to newly created account page. 4.All the references are correct. Like ConvertedAccountId, convertedOpptyId etc. When I go to the Debug logs, There SOQL 101 (System.LimitException: Too many SOQL queries: 101) is being shown. If dig more in the debug logs then I found that this exception came while Opportunity Before Update trigger. The question is, Since all this is happening in sing...

Too many batch retries in the presence of Apex triggers and partial failures.

Too many batch retries in the presence of Apex triggers and partial failures If you write and execute batch scripts then some time you might end up with this error, which may be difficult to understand. However proper explanation is given in the Salesforce documentation as below. Bulk DML Exception Handling Exceptions that arise from a bulk DML call (including any recursive DML operations in triggers that are fired as a direct result of the call) are handled differently depending on where the original call came from: When errors occur because of a bulk DML call that originates directly from the  Apex  DML statements, or if the  all_or_none  parameter of a database DML method was specified as true, the runtime engine follows the “all or nothing” rule: during a single operation, all records must be updated successfully or the entire operation rolls back to the point immediately preceding the DML statement. When errors occur because of a bulk DML call that ...

apex HTML pass through not working

Pass through attribute doesn't generate proper html HTML Pass through provided by salesforce in VF pages has been very useful when working with javascript libraries, However while working on the same I came across a situation where Pass through attribute doesn't get passed to generated html if the binding variable is 'Currency' type. Below is the example. Controller 1: public Opportunity Oppty {get;set;} VF page 1: <apex:outputField value = '{!Oppty.Amount}' html-passedValue='XYZ'></apex:outputField> Generated html 1: <span id="j_id0:j_id1:j_id14">$20</span> Hence you can see that the pass through attribute is not generated. However if you change the binding variable to any type other then Currency, pass through will start working. as shown below. VF page 1: <apex:outputField value = '{!Oppty.name}' html-passedValue='XYZ'></apex:outputField> ...