Hot answers tagged

16

It does not look like a variable defined as indexVar was meant to be used as part of another expression. e.g. this works <aura:iteration items="{!v.contacts}" var="item" indexVar="index"> {!index} : {!item.FirstName}<br/> </aura:iteration> I think in your example "item" should be changed from final value to an object which has ...


14

The addDays method does not modify the value but instead returns the modified date. So you need: currentDay = currentDay.addDays(1); Your current code hits the CPU limit because currentDay never changes.


10

Replace = with :. for(Payment_received__c record : [SELECT ... FROM Payment_received__c] See Loops.


9

You're close to the solution. The thing that you're getting caught on is that the outer loop isn't iterating over a single Opportunity, but rather a List<Opportunity> // Outer loop on a List<List<Opportunity>> gets you one level in, resulting in // a List<Opportunity> for(List<Opportunity> oppList : totalMpRecords){ // ...


9

The reason for the cause of the recursion is your apex method and the lightning component helper method have same name "save" I would change the apex method to different name than save save : function(component, helper) { var testUser = component.get('v.testUser'); var action = component.get('c.serverSave'); Using separate name for controller and helper ...


8

If I am reading the question correctly what you are asking is if you ran this for(Account a : [Select Id, Name From Account Limit 10]){ //Your Code } If it was counted as 1 SOQL call or 10. If thats what your asking then its only counted as 1 SOQL query against the governor limits. Use Apex anonymous and try this for(Account a : [Select Id, Name ...


7

The problem is probably that you re-initilaise the Summaries list every time round the loop to an empty list so you end up with only 1 item in the final list. This is probably what you want: Summaries = new List < Summary > (); FOR(RecordType RType: RTypeList) { AggregateResult[] Results = [SELECT Account.Owner.Name accOwner, RecordType....


7

Your loop: for(Integer i = 0; i < bulkDataValue; i+2){ never terminates hence you hit the CPU limit. You probably meant something like: for(Integer i = 0; i < bulkDataValue; i += 2){


7

You should never do DML statements (such as insert) inside loops, this will easily get you off limits. Create a List outside the loop, iterate over your trigger in the first loop, create new records and add them to the list in the second loop, then insert everything outside the loop. Something like this: List<Revenue_Schedule__c> new_records = new ...


7

There's no problem with this for loop configuration because it doesn't cause multiplicative execution. The reason you may have heard about avoiding nested for loops is that some people try a naive implementation to match up records. Here's a typical example of what not to do: Account[] accounts = [SELECT Name FROM Account]; Contact[] contacts = [SELECT ...


7

If you need to append values to a variable from within a loop, you'll need to remember to include the variable itself during concatenation. Otherwise, you'll simply be "re-setting" the variable after each iteration (i.e., the variable will be set according to the last iteration, only). For example, this yields only the last result: %%[ for @counter = 1 to ...


6

You can't assign a value to the Trigger.new collection in an after trigger. brandnew is a record coming from the trigger, so when you attempt to assign true it give you an error. Now, more importantly, I don't believe you are actually trying to assign the value true to that field, I assume you're trying to perform an "equals" conditional. You will need ...


6

Please do not update the same sObjectType in the After Triggers. You need to use Before Triggers in this case. This would resolve the System.FinalException: Record is read-only error message. For person account , please use "isPersonAccount" field of Account, if it is enabled for your Org.


6

In general less loops is better, as this can lead to better chances to not thrash the L2 cache on the CPU, however there are so many levels between there and your apex code that the odds of you actually seeing any measurable difference is nil. For triggers, performance is totally dominated by db access by a large margin, so that's the best place to ...


6

I would start off by putting the different locations in maps. So something like: List<Inventory_Lots__c> icList = [SELECT Id, Location__c, Closed__c, On_Hold__c from Inventory_Lots__c WHERE Location__c IN :recIds.Keyset() AND Closed__c != TRUE AND On_Hold__c != TRUE]; Map<Id, List<Inventory_Lots__c> lotByLocation = new Map<Id, List<...


6

When you perform a comparison between a String and an Id (e.g. ==, !=, or <>), then the other argument is "promoted" to an Id value. All Id values must be 15 or 18 characters long, and must contain only A-Z, a-z, and 0-9, so '' is not a valid Id. Proof: String a = ''; Id b; System.assert(a != b); Edit: Also, there's a more efficient way you could ...


6

You can use a List as a Value for a Map. Map<Integer, ABC__c[]> codeToABC = new Map<Integer, ABC__c[]>(); for(ABC__c record: abcRecords) { if(codeToABC.containsKey(record.Code__c)) { // Code already in map codeToABC.get(record.Code__c).add(record); } else { // Code is not yet in Map codeToABC.put(record....


6

try like this.. ApexPages.CurrentPage().getParameters() return a map . you have to use like below code. for(String param: ApexPages.CurrentPage().getParameters().keyset()) { System.debug('===key==='+param); System.debug('===value==='+ApexPages.CurrentPage().getParameters().get(param)); }


6

Map<String, List<Account>>.values() has a return type of List<List<Account>>. You'll have to do an outer loop to "unroll" this data structure, if you want to iterate over all of the Accounts contained: for (List<Account> outerList : mapParentAccountNameToLstAccount.values()) { for (Account a : outerList) {


6

You're seeing recursion because your recursion guard is in the wrong place. When this gets executed: AankoopDetailTriggerHandler.isBeforeInsert(trigger.new); if(AankoopDetailTriggerHandler.aankRecursion) return; AankoopDetailTriggerHandler.aankRecursion = true; what happens is something like this: Insert goes off before ...


6

Using a Map to collect the values you want to update is one useful technique: existingRenewalCardsRequests = new Map<Id, Card_Request__c>(); ... existingRenewalCardsRequests.put(card.Id, card); ... update existingRenewalCardsRequests.values(); though be careful to not just hide a logical error in the process. It is also ...


5

You're trying to reach through the Opportunity relationship, but triggers don't pull that data in directly. You'd have to pull them in a separate query. Here is an example of how to achieve what you're after (fair warning, hand written code here): Set<ID> AccountIds = new Set<ID>(); Set<Id> OppIds = new Set<Id>(); Map<ID,ID> ...


5

There are multiple problems in your code. 1. List<myData> matchingDataGrid = [Select Id, Name, CreatedById, CreatedDate where Id = :defaultUserID]; you should also add a FROM clause to your query. Also, if you use a custom object do not forget the __c after it 2. for (List<myData> i :matchingDataGrid.Count) if you use count() method, do not ...


5

If you instantiate a Map and pass it a select statement the key will always be the id of the objects. To get what you want you need to first query into a List, then iterate the list adding the values keyed by your externalId value. List assetPlans = [Your SOQL]; Map<String, Asset_Plans__c> aMap = new Map<String, Asset_Plans__c>(); ...


5

So, this snippet should do it. (I am being more verbose than I need to, for clarity's sake) List<User> usersWithDupes = <your list here> Set<User> usersUnique = new Set<User>(); usersUnique.addAll(usersWithDupes); List<User> usersUniqueList = new List<User>(); usersUniqueList.addAll(usersUnique);


5

There is a standard Set method, called retainAll. That method remove all elements in original set, except from set in parameter (save in current set intersection of the two sets) and returns true if original set has been changed during operation. For example: Set<Integer> s1 = new Set<Integer>{1,2,3}; Set<Integer> s2 = new Set<Integer&...


5

My hacky stupid workaround for While loops in AMPscript: %%[ FOR @i=1 to 2 DO /*Execute your code here*/ IF NOT @condition THEN @i = Subtract(@i, 1) ENDIF NEXT @i ]%% This loop will keep executing until the condition is met.


5

You trigger is fired whenever you update an opportunity and it queries all Contracts linked to these opportunities. What you do in your test class is: Insert opportunities Update opportunities(probably to cover the trigger?) Insert contracts linked to these opportunities The problem is that you trigger only fires at step 2., but at this moment there are ...


5

I created a similar data structure. It's basically just missing the lookup from friend to person. Also for the sake of simplicity, I'm using the name as an identifier, but it would be the same principle to use the person id instead. The data I used to recreate the graph in you example: Person__c:{Name=Lisa, Id=a0d9000000OJ2v7AAD} Person__c:{Name=Jane, Id=...


5

This is always true because it is an assignment whose resulting value is true: if(ca.Incorrect__c = true){ This: if(ca.Incorrect__c){ or this: if(ca.Incorrect__c == true){ should work.


Only top voted, non community-wiki answers of a minimum length are eligible