Skip to main content

#Apex토론 중인 항목 32개

I spent weeks debugging an obscure Salesforce internal error that made no sense. 

System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop 

The query had 5 child records with a Long Text Area field and a few hundred records in a completely separate subquery with only Id selected. 

No LTA. No RTA. Just IDs. 

Yet the query was failing. 

After opening a case with Salesforce Support and escalating to the Product Team, I got the official answer: 

"Working as Designed." 

The Apex runtime applies a shared CLOB budget across ALL child subqueries — even ones with no LTA/RTA fields. The reasoning: heap safety across the entire query tree. 

I wasn't satisfied with that answer. So I ran dozens of tests across different field sizes and record counts and reverse-engineered the internal formula. 

Here's what the runtime actually does: 

Step 1 — sum up all declared LTA/RTA field lengths anywhere in the query (parent + every subquery) 

Step 2 — derive a total children row budget: 

 

FLOOR( 1000 / POW(2, MAX( CEILING(LOG2(totalClobLength / 32768)), 0 )) ) 

Which produces this table: 

totalClobLength | Row budget 

--------------- 

256 B - 32 KB | 1,000 

32–64 KB | 500 

64–128 KB | 250 

128–256 KB | 125 

256–512 KB | 62 

 

Both empirical thresholds I observed matched this formula exactly. 

Here's the flaw. 

The row budget is calculated from LTA/RTA field sizes — and then applied to ALL child records across ALL subqueries, including those that select only Id. 

A subquery like (SELECT Id FROM Children2__r) contributes zero bytes of CLOB content. 

But each of its records still consumes one slot from the budget. 

The budget is asking "how many rows can we safely load given the CLOB volume?" 

Then it counts rows that carry no CLOB data at all toward that answer. 

The fix is straightforward: 

Apply the CLOB row budget only to subqueries that actually select LTA/RTA fields. 

Records in (SELECT Id FROM ...) should not count against a heap limit derived from text field sizes. 

I've submitted this to IdeaExchange: 

"Fix Design Flaw in internal totalClobLength calculation" 

If you've ever hit this error in a multi-relationship query — or you work with contracts, documents, or any domain with rich-text fields on parent objects — please vote. 

https://ideas.salesforce.com/s/idea/a0BHp000017Jka1MAC/fix-design-flaw-in-internal-totalcloblength-calculation

 

#Salesforce #Apex #SalesforceArchitect #SalesforceDeveloper #GovernorLimits

댓글 2개
  1. 어제 오전 8:36

     Incredible write-up and deep dive! Counting zero-byte ID subqueries against a CLOB-derived budget is a textbook design oversight. Heading over to the IdeaExchange to vote for this right now. Thanks for doing the heavy lifting to figure this out! 

0/9000

Aadhar card, driving license and pan card numbers are to be masked such that only last four characters are to be displayed. It is fully  visible only to CEO and COO. How to solve this without coding ? 

답변 6개
  1. Eric Burté (DEVOTEAM) Forum Ambassador
    2024년 3월 2일 오후 5:08

    Hello @Rajadesingu J with RIGHT(field__c, 4) you could get the 4 last digit of the concerned field (field__c to replace with the concerned field api name).

    Then after, you can concatenate this with any other text you want in your formula.

    Eric

0/9000
I have getting error as System.NullPointerException: Attempt to de-reference a null object on the test class

Class:-

/*

@Class Description- Contact Trigger Helper.

Class is introduced to handle Titan Portal Status Sync between Contact and its related account.

*/ public with Sharing class ContactHelper {

//Boolean variable to prevent recursions on this Class.

public static Boolean isPortalSyncUpdateRecursion = FALSE ; public static Boolean isPortalSyncDeleteRecursion = FALSE ;

public void updateAccountPortalStatus(Map<Id,Contact> mapNewContact, Map<Id,Contact> mapOldContact) { system.debug('mapNewContact' +mapNewContact ); system.debug('mapOldContact' +mapOldContact );

Set<Id> setContactIds = new Set<Id>(); Set<Id> setAccountIds = new Set<Id>(); List<Account> lstAccountsToUpdate = new List<Account>(); if(mapNewContact != null) { for(Contact objContact : mapNewContact.values()) { system.debug('mapOldContact' +mapOldContact.get(objContact.Id).Titan_Portal_Status__c ); system.debug('objContact'+ objContact.Titan_Portal_Status__c); //if there is a change in Titan Portal Status of this contact, collect contact ids. if(mapOldContact != null && mapOldContact.containsKey(objContact.Id)) { if(objContact.Titan_Portal_Status__c != mapOldContact.get(objContact.Id).Titan_Portal_Status__c ) { setContactIds.add(objContact.Id);//collect contact ids that needs to be evaluated for all AccountContactRelation system.debug('setContactIdsinfor' + setContactIds); } } } } else if(Trigger.isDelete) { System.debug('Old Keyset'+mapOldContact.keySet()); for(AccountContactRelation objAccountContactRelation : [SELECT Id, AccountId FROM AccountContactRelation WHERE ContactID IN: mapOldContact.keySet()]) { //NOTE-use this variable only in Contact Delete context, as this is used to find accounts of deleted contact setAccountIds.add(objAccountContactRelation.AccountId); } } System.debug('Set Contact Ids:'+setContactIds); System.debug('Set Account Ids:'+setAccountIds); /* * NOTE: This blank update will execute the record-triggered flows in AccountContactRelation, which will handle * Titan Portal Status sync between Accounts and their related Contacts linked using AccountContactRelation. * */ if(setContactIds.size()>0 && Trigger.isUpdate) { system.debug('setContactIdsinupdate' + setContactIds); List<AccountContactRelation> lstToUpdate = [SELECT Id FROM AccountContactRelation WHERE ContactId IN: setContactIds]; if(lstToUpdate.size()>0) { Database.update(lstToUpdate,false); } } /* * NOTE: - For delete of contact, validate the Portal Flag in this method * */ if(setAccountIds.size()>0 && Trigger.isDelete) { Boolean portalFlag = FALSE; for(Account objAccount: [SELECT Id, Titan_Enabled__c , (SELECT Id, Contact_Titan_Portal_Status__c FROM AccountContactRelations WHERE Contact_Titan_Portal_Status__c ='Active' AND ContactId NOT IN: mapOldContact.keySet() LIMIT 1) FROM Account WHERE Id IN: setAccountIds]) { //For the deleted contact, There is atleast 1 more diff contact related to the account, which is portal active. if(objAccount.AccountContactRelations != null && objAccount.AccountContactRelations.size()>0) { portalFlag = TRUE; } else { portalFlag = FALSE; } System.debug('Portal Flag'+portalFlag); System.debug('Account Flag'+objAccount.Titan_Enabled__c); //if there is a change in Account checkbox field and the flag var calculated here, add this update for update if(objAccount.Titan_Enabled__c != portalFlag) { objAccount.Titan_Enabled__c = portalFlag; lstAccountsToUpdate.add(objAccount); } } System.debug('Accountupdate list:'+lstAccountsToUpdate); //Update the accounts' Titan Enabled checkbox if(lstAccountsToUpdate.size()>0) { Database.update(lstAccountsToUpdate, false); } }

} }

Test class:- @isTest public class ContactHelperTest { static testmethod void PortalStatus(){ Map<id,contact> oldmap = new Map<id,contact>(); Map<id,contact> newmap = new Map<id,contact>(); Account acct = new Account(); acct.Name='TEST'+ math.random(); acct.Type='Standard'; acct.BillingStreet='Test'; acct.BillingCity='test'; acct.BillingCountry='United States'; acct.Phone='123214231453'; acct.BillingPostalCode='1234567'; acct.BillingState='California'; acct.Titan_Enabled__c = True; acct.OwnerId=userinfo.getUserId(); //acct.Billing_Address__c = 'XYZ, Albama, ' insert acct;

system.debug('acct'+ acct); Contact con = new Contact(AccountId = acct.id,lastname = 'testdata' , firstname ='testdata1', Email = 'test1@honeywell.com'); insert con; system.debug('con'+ con); con.lastname = 'Test2'; con.Titan_Portal_Status__c = 'Active'; update con; system.debug('conupdate'+ con); oldmap.put(con.id,con); system.debug('oldmap'+ oldmap); contact con1 = [select id,name,lastname,firstname,email,Titan_Portal_Status__c from contact where id =:con.Id]; system.debug('con1' +con1); con1.lastname = 'Test3'; con1.Titan_Portal_Status__c = 'Inactive'; update con1; system.debug('con1update' +con1); newmap.put(con1.id,con1); system.debug('newmap' +newmap); AccountContactRelation all = [SELECT ID, AccountId, ContactId,Contact_Titan_Portal_Status__c, IsActive FROM AccountContactRelation where contactid =:con1.id]; system.debug('all' + all); contact con2 = [select id,name,lastname,firstname,email,Titan_Portal_Status__c from contact where id =:con1.Id]; delete con2; Test.startTest(); ContactHelper ts = new ContactHelper(); try{ ts.updateAccountPortalStatus(newmap,oldmap); } catch (DmlException ex) { System.assertEquals('expected text', ex.getMessage()); } Test.stopTest(); /* check for AccountContactRelation record with IsActive = false and also check for the error message */ }

System.NullPointerException: Attempt to de-reference a null object on test class

User-added image

Getting below error while running the test class

can anyone please help on this as we are getting error on the System.NullPointerException: Attempt to de-reference a null object on line 50 on the class "if(setContactIds.size()>0 && Trigger.isUpdate)"
답변 1개
  1. 2023년 8월 31일 오전 10:40
    HI Mahesh,

    I see you also posted on https://salesforce.stackexchange.com/questions/402221/system-nullpointerexception-attempt-to-de-reference-a-null-object-on-test-class according to which, 

    "This test class is incoherent and does not appear to be meaningfully testing the class ContactHelper.

    It looks like you are attempting to test behavior on Contact deletion, but the logic you've written does not do so effectively for a number of reasons. A few points that I will highlight, which may not be the specific issue causing this error and may not be all of the issues in this code, are:

    > Your code appears to invoke the trigger handler multiple times. The handler will be run, presumably, by your trigger at each DML operation you perform during test data setup, and will then explicitly be invoked again when you call it. This is almost certainly not what you want. I assume you were trying to build a DML-free test to exercise this code in isolation, but you haven't actually done that - you're still performing lots of DML.

    > You have static Booleans to try to control recursion, but you are not using them. If in your actual code these values are used, you may see unexpected behavior because of the way your test runs the code multiple times in a single transaction.

    >You are attempting to catch and validate a DmlException that your code never causes to be thrown (by calling addError()).

    >Your test will false-positive if an exception is not thrown because you do not make a System.assert(false) assertion after you call ts.updateAccountPortalStatus(newmap,oldmap) to ensure that the flow of control doesn't continue.

    >The logic in your test will cause the wrong code path to be executed in your trigger handler. Because you construct and pass an incorrect newmap value to the handler (delete events do not have a Trigger.newMap), your handler will execute what appears to be the update pathway in the first if statement, instead of the delete pathway.

    > That said, the logic in your handler is so confused that it is difficult to follow the flow of control. You need to step back and do a major refactor, breaking out logic for different trigger events into separate methods and business logic into its own testable code unit."

    Related:

    https://developer.salesforce.com/forums/?id=906F0000000AvQJIA0

    https://stackoverflow.com/questions/70463065/salesforce-test-class-system-nullpointerexception-attempt-to-de-reference-a-n

    https://www.sfdcpoint.com/salesforce/system-nullpointerexception-attempt-to-de-reference-a-null-object/

    Please mark answer as best to close the thread. Thanks

     
0/9000
답변 4개
  1. 7월 4일 오전 5:12

    Greetings @Saskia Singh

    The answerto yourquestion depends on your end goal? Are you a beginner learning from scratch or studying for PD1 exam or someone transitioning from another language like Java or C#?  

     

    If you specify your end goal, we should beable topoint youin the right direction.  

     

    Be well Katende

0/9000

<aura:component implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

<aura:attribute name="fields" type="String[]" default="['Capital_Markets_Outlook_CMO__c',

'Webcast__c',

'X75_20_Rate_Email_Update__c',

'Bernstein_Market_Insights_BMI__c',

'Quarterly_Video_Update__c',

'Crisis_Communications__c',

'Client_Quarterly__c',

'Quarterly_EE_Deck__c']" />

<div class="slds-box">

<lightning:recordForm

recordId="{!v.recordId}"

objectApiName="Contact"

fields="{!v.fields}"

columns="2"

mode="View"

/>

</div>

</aura:component>

  1. How to apply styling for a checkbox in lighting:recordform
답변 1개
  1. 2019년 8월 8일 오후 12:25
    Hi Kiran,

    Greetings to you!

    You can use the below CSS:

    .THIS .slds-checkbox [type=checkbox][disabled]+.slds-checkbox__label .slds-checkbox_faux {

    background-color: rgba(201, 199, 197, 0.96);

    }

    Please refer to the below links which might help you further with the above requirement.

    https://salesforce.stackexchange.com/questions/223746/how-to-apply-styling-for-a-checkbox-in-lightingrecordform

    https://github.com/salesforce-ux/design-system/issues/570

    I hope it helps you.

    Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

    Thanks and Regards,

    Khan Anas
0/9000
Ishaan Garg 님이 #Open Jobs에 글을 올렸습니다

You're in the right place — #Open Jobs, Create a Post selected. Paste this directly into the Details box:

Hiring: Senior Salesforce Developer (Agentforce) | Remote India | Immediate

We're Zyphex Tech — an AI solutions firm building production-grade Agentforce and automation systems for clients across industries.

Looking for 2 Senior Salesforce Developers who've deployed Agentforce agents in a live org — not just explored it in a sandbox.

What we need:

  • 5+ years Salesforce (Apex, LWC, Flows, Data Cloud)
  • Agentforce experience — Topics, Actions, Instructions
  • REST/SOAP API integrations, async processing (Batch/Queueable Apex)
  • AI coding tools in daily workflow (Copilot, Cursor, Claude Code)
  • Comfortable working directly with clients and stakeholders

Details:

  • Remote, India
  • ₹1L + GST/month
  • 3+ months, immediate start
  • 2 open positions

If this is you or someone you know — comment below or reach out directly. 

 📩 ishaan.g

#Open Jobs  #Salesforce Developer  #Apex

댓글 1개
0/9000
S.P. C. 님이 #Trailhead Challenges에 질문했습니다

I am working from a completely fresh Salesforce playground. When I open the Dev Console and attempt to create a new Apex Class, I receive the above-mentioned error message.  

 

I am unsure how to resolve this. Any assistance is appreciated. 

 

IDEMPOTENCY_NOT_SUPPORTED when trying to make an Apex Class

 

 

 

#Trailhead Challenges  #Apex  #ApexDevelopment  #ApexSandboxChallenges

답변 1개
  1. 7월 5일 오전 4:32

    Hi, Close the developer console and reopen it. This is not an expected here. From the File menu, select New | Apex Class.

0/9000

Hi, i've been working on this for the past 3 days and I can't seem to work it out. Ive downloaded the latest Java 17.0 for apex to work on my org in Visual studio. Unfortunately, the system can't seem to find it and the video provided didn't walk through that step. I'm just not entirely sure what i'm exactly am I doing wrong. Pls help. 

I can't find my Java to work on Visual studio code

 

#Trailhead Challenges  #Salesforce  #Apex  #Java Development  #Apple Mac and OS X

답변 3개
  1. 6월 13일 오전 10:50

    I want to mention some common issue:  

    move the file or relocate to anywhere else. 

    search the file in system by name 

    renaming the file etc.

0/9000
답변 11개
  1. 2019년 11월 4일 오전 5:17
    Hi likitha,

    Please refer to my code below:

    public class QUES {

        public static void addOddNum(){

            Integer n =50;

            Integer sum=0;

            while(n>0){

                if(math.mod(n,2)==1){

                  System.debug(n);

                }

                n=n-1;

            }

        }

    }

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

    Thanks and Regards,

    Deepali Kulshrestha

    www.kdeepali.com
0/9000
I have two class:

OpportunityLineItemTriggers

OpportunityLineItemTriggers_Test

In the developer console, I run the test class of which there are 5 and all of them check out as green. Yet the code coverage remains very low on the class. When I open up the OpportunityLineItemTriggers class and select Code Coverage, it's only showing that it ran one test, and it's the last one in the list.

Has anyone else run into this problem, and if so, how can I get the Code Coverage to be cumulative across all of the tests in the test class?
답변 2개
  1. 2015년 5월 5일 오후 3:16
    No I can't. There are over 1500 lines of code between those classes, and there are other triggers and classes such as Opportunities, Accounts, Contacts which also run. What I'm wondering is why only the last running test is showing up as the one that covers the class when I have 5 test methods. I ran the unit tests again, and each time the Code Coverage showed only one test method running against the class, I commented out that test method and ran the unit tests again. There ended up being two test methods which I had to comment out, and then when I ran the unit tests again, the remaining 3 showed up in the Code Coverage drop down. 

    I'll have to look at the two I commented out to see how they are affecting the other unit tests and why they are not showing up as cumulative.

    Thanks for the reply.
0/9000