Jul 22, 2022

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


Issue: Unable to add new lines/Products if already added more than 100

Backend debug log
|FATAL_ERROR|System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop

 

The solution provided here: Salesforce Developers

 

1 for(sbqq__quote__c qt : [SELECT Id,Quote_Type__c,Special_Freight_Rate__c,Consumables_Only__c, 2 Company_Region__c,Country_code__c,Comp_Reg_Text__c, 3 (SELECT Id,SBQQ__AdditionalDiscountAmount__c,SBQQ__ListPrice__c,SBQQ__ProductCode__c, 4 Product_Group__c,Product_Type__c,SBQQ__Optional__c,SBQQ__NetTotal__c,SBQQ__NetPrice__c, 5 SBQQ__EffectiveQuantity__c,Dangerous_Goods__c,Instrument_item__c,Consumable_item__c, 6 Article_Type_Number__c,SBQQ__Quantity__c,Trade_Name__c,SBQQ__Quote__c,Article_Type__c, 7 SBQQ__Quote__r.Country_Code__c,SBQQ__Product__r.Weight__c, SBQQ__Product__r.Net_Weight__c, 8 SBQQ__Product__r.Weight_unit__c, CurrencyIsoCode 9 FROM SBQQ__LineItems__r order by SBQQ__Number__c ASC) 10 FROM sbqq__quote__c WHERE Id in :quoteIds]) 11 { 12 /************** prevoius code ************ 13 //QuoteToLineMap.put(qt.id,qt.SBQQ__LineItems__r ); 14 ************************************************/
15 16 /**************** Modified code ******************/ 17 if(!QuoteToLineMap.containsKey(qt.Id)){ 18 QuoteToLineMap.put(qt.id,new List<SBQQ__QuoteLine__c>()); 19 } 20 for(SBQQ__QuoteLine__c insideLine : qt.SBQQ__LineItems__r ){ 21 QuoteToLineMap.get(qt.id).add(insideLine); 22 } 23 24

 




Feb 12, 2022

Flow - Variables

Variable: 

Data Type Use to store...
Text IDs, descriptions, and other text or long text data.
Record Field values from a record, such as an opportunity. When this data type is selected, you create a record variable.
Number A numeric value.
Currency A currency value.
Boolean A yes/no value, such as whether a checkbox was selected.
Date A date value.

Date/Time

A date and time value.

Picklist

A picklist value.
Multi-Select Picklist Picklist values, separated by semicolons.
Apex-Defined
Field values from an Apex class. When this data type is selected, you create an Apex-defined variable.

We can Store single values or collection values.


Screen Components

 Screen components are available in three categories.

  • Input includes standard components that request information from the user.
  • Display includes standard components that display information to the user.
  • Custom includes components that you or someone else have created. Install them from AppExchange or a third-party library, or work with a developer to build your own.


Action Types

Without creating or configuring anything else in Salesforce, you can use these actions.

      • Post to Chatter.
      • Send Email.
      • Submit For Approval.
      • Activate or Deactivate a Permission Set.
      • Global or object-specific actions provided by Salesforce.

You can also include actions you create with clicks.

      • Other flows in your org are available in the Subflow element.
      • Custom global or object-specific actions are available in the Action element.

You can also include actions that require code. And you can install custom actions from AppExchange or a third-party library.

      • To do something in the Salesforce database, build or install an Apex action.
      • To do something in the browser, build or install a local action.

 

 

Aug 27, 2021

System.TypeException: Cannot have more than 10 chunks in a single operation. Please rearrange the data to reduce chunking.

 System.TypeException: Cannot have more than 10 chunks in a single operation. Please rearrange the data to reduce chunking.

Cause:   
If  we are doing DML operation on collection of sobject in single operation.
1. More the 10 Sobjects 
List<Sobject> dmlList = new List<Sobject>();
dmlList.add(New Account (Name='Test'));
dmlList.add(New Contact (LastName='Test'));
dmlList.add(New Lead (Name='Test'));
dmlList.add(New opportunity (Name='Test'));
dmlList.add(New custom1__c (Name='Test'));
dmlList.add(New custom2__c (Name='Test'));
.
.
.
dmlList.add(New custom11__c (Name='Test'));
insert dmlList;
        2. Less than 10 Sobjects and  records in not in order
List<Sobject> dmlList = new List<Sobject>();
dmlList.add(New Account (Name='Test'));
dmlList.add(New Contact (LastName='Test'));
dmlList.add(New Lead (Name='Test'));
dmlList.add(New Account (Name='Test'));
dmlList.add(New Contact (LastName='Test'));
dmlList.add(New Lead (Name='Test'));
.
.
.
dmlList.add(New Account (Name='Test'));
dmlList.add(New Contact (LastName='Test'));
dmlList.add(New Lead (Name='Test'));
insert dmlList;
Solution:
SImply Use SORT() method
dmlList.sort();
insert dmlList;
(OR)
List<Sobject> dmlList = new List<Sobject>();
dmlList.add(New Account (Name='Test1'));
dmlList.add(New Account (Name='Test2'));
.
.
dmlList.add(New Account (Name='Test11'));
dmlList.add(New Lead (Name='Test1'));
dmlList.add(New Lead (Name='Test2'));
.
.
dmlList.add(New Lead (Name='Test11'));
dmlList.add(New Contact (LastName='Test1'));
dmlList.add(New Contact (LastName='Test2'));
..
..
dmlList.add(New Contact (LastName='Test11'));
insert dmlList;

Jun 29, 2021

Salesforce Apex Coding Standards

                Salesforce Apex Coding Standards

Coding Style

*      Indentation

·         Whitespace - Since Apex is case insensitive you can write it your way. However, to increase readability, use four spaces instead of tabs for indentation.

·         New Line – To increase readability – Use new line at starting point for every new block.

*      Naming conventions (Pascal, Camel Case, snake_case etc.)

·         Apex Class names should be in UpperCamelCase, with the first letter of every word capitalized.

§  Eg: AccountTriggerHandler 

·         Methods should be verbs in lowerCamelCase or a multi-word name that begins with a verb in lowercase; that is, with the first letter lowercase and the first letters of subsequent words in uppercase.

§  Eg: getParentAccount()

·         Variables: Local variables, instance variables, and class variables are also written in lowerCamelCase.

§  Eg: Integer index, String accountName.

·         Final Varibale should be CAPITAL. Eg: final Integer BATCHSIZE=20.

·         Variable names should not be single characters.

·         Test Class name should be as PascalCaseTest.  i.e. – AccountTriggerHandlerTest

·         Test method should be as testShouldExecute<ClassName>When<data>

§  Eg: testShouldExecuteAccountTriggerHandlerWhenAddresschanged()

·         Datatype should be UpperCamelCase

§  Eg: String, Integer, List, Map, Wrapper, Account, etc.

·         Boolean values Should be CAPITAL i.e., TRUE or FALSE.
 

*      Minimal comments - unless VERY temporary

ü  Remove the commented code as this is always a blocker, while going through the code.

ü  Comments should tell WHY not WHAT.

ü  Git tracks history so no need to comment code.

*      Use same conventions within a Class.

Example: instantiating an sObject using the sObject constructor vs the object.field notation

 SBQQ__Quote__c quote1 = new SBQQ__Quote__c (

SBQQ__Opportunity2__c = opp1.Id,

 SBQQ__MasterContract__c = c.Id,

 SBQQ__Primary__c = TRUE

);

multiQuoteList.add(quote1);

Vs

SBQQ__Quote__c quote1 = new SBQQ__Quote__c ();

quote1.SBQQ__Opportunity2__c = opp1.Id;

quote1.SBQQ__MasterContract__c = c.Id;

quote1.SBQQ__Primary__c = TRUE;

multiQuoteList.add(quote1);


Doesn't matter which convention you use, just keep it consistent within the class.

*      Should not have methods with large number of lines.

ü  Make sure each method contains not more than 40 lines.

ü  If there are more lines break into multiple methods.

ü  Classes no more than 10 methods or 300 lines.

ü  Don't add unnecessary code. Only the code needed to achieve the feature you are working on

*      Break SOQL Queries across multiple lines

·         SELECT keyword and clauses such as WHERE, WITH, GROUP BY, and ORDER BY, etc. all should be in CAPS.

·         Need to Break/new line for each clause.

·         List all fields in ascending alphabetical order.

[ Select Id, Name, customField1_c, customField2_c from Account where Name like '%Nave%' ]

·         Bad Practice

·         Good Practice

[ SELCT Id, Name, customField1_c, customField2_c

 FROM Account

 WHERE Name like '%Nave%' ]



 

 

*      No System.debug Statements

ü  Unless you absolutely need to debug something in Production.

ü  This also include Javascript console.log statements in front-end code.

 

Coding best practices

*      Keep It Simple Stupid (KISS Principle)

ü  There should be as little logic in your code as possible.

ü  Write a single method and reduce the clutter in your code.

ü  Simple code is easier to maintain.

ü  Bad Practice



ü  Good Practice

                        



 

 

*      Don’t put SOQLs inside loops.

ü  Bad Practice




ü  Good Practice




*      Utilize the Maps for Queries

ü  Map<Id, sObject> myAwesomeMap = new Map<Id,sObject>(List of sObjects or SOQL Query);

*      Use relationships to reduce queries.





*      Don’t put DMLs in loops.





*      Test code coverage

ü  Cover as close to 100% of the code as possible.

ü  Never use dummy code coverage

*      Write meaningful unit tests.

ü  Create all test data before calling the Test.startTest method.

ü  Must have System.Assert for each test method.

ü  Include a description of expected behaviour as 2nd parameter for System.assert() or 3rd parameter for System.assertEquals()

ü  Examples:

ü  System.assert(A == B,’A does not equal B’);

ü  System.assertEquals(Expected,Actual,’Actual does not equal Expected’);

ü  System.assertNotEquals(Expected,Actual,’Actual equals Expected, but should not’);

*      Reusability

ü  Avoid duplicated code (more-so in same class than across classes)

ü  Use existed Trigger Framework, TestDataFactory and HTTPMOCKClasses

ü  One Object should have one Trigger only

*      Avoid Hardcoding IDs:

ü  Use Custom Settings, metadata types or custom Labels. (Or)

ü  Get values dynamically

ü  Bad Practice

 




ü  Good Practice





*      The fewer the method parameters the better

ü  Try to avoid more than 3 arguments