Hot answers tagged

11

Here's a pattern that seems relatively efficient and easier to understand. public static List<Object> slice(List<Object> input, Integer ge, Integer l) { List<Object> output = input.clone(); for (Integer i = 0; i < ge; i++) output.remove(0); Integer elements = l - ge; while (output.size() > elements) output.remove(...


9

The syntax changes slightly when you use the parameterized syntax: List<List<String>> colorLists = new List<List<String>>(1); If you want the list to be empty, do not provide a parameter (or use 0): List<List<String>> colorLists = new List<List<String>>(0); [] is syntactic sugar, but it doesn't always work. ...


7

If we create a new array as below, @track sees the change: this.myArray = [...this.myArray, myNewElement]; My guess is that the @track isn't noticing the original push in the array since an array is actually only a pointer. When items are added to an array, it will never change the pointer, thus @track sees no change. (@track is only watching the address)...


6

The problem is that you're casting to a list when the object is a map. You want a list of maps. This should do it: List<Map<String,Object>> return_posts = new List<Map<String,Object>>(); for (String p : posts.keySet()) { Map<String,Object> pp = (Map<String,Object>)posts.get(p); return_posts.add(pp); }


6

While it's not a bad start, I can think of a number of problems: No bounds checks are provided Only Id and SObject are supported SObject version returns generic list, does not support upsert Has debug statements Is overly verbose Thrashes the heap more than necessary Here's a version that closer to what I'd include in a library (which I'm working on), but ...


6

Yes, you can nest iterators "infinitely" (up to some really large maximum); it looks like you had an unused value provider name prod in your code. Here's a revised, Short, Self Contained, Correct (Compilable), Example: <aura:application > <aura:attribute name="object" type="List" default="[ { 'Sub': [ ...


6

If you rebuild the array as below and reassign, the @track sees the change: this.myArray = [...this.myArray, myNewElement]; My guess is that the @track isn't noticing the original push() in the array since an array is actually only a pointer. When items are added to an array, it will never change the pointer, thus @track sees no change. However, in my ...


5

I'm not sure how you want it to display, but how about using an <apex:repeat> with a map? Your class could look like this. public Map<String,Integer> vals { get { if (vals == null) { vals = new Map<String, Integer> { 'Value 1' => 0, 'Value 2' => 0, 'Value 3' =&...


4

There's already some good answers here, but I figured I'd throw my hat into the ring anyways. In my approach, I've tried to stay as close to the Javascript versions as possible. The JS slice is a variable arity function that makes use of up to the first two arguments it is provided, so I provided three methods for my Slice class with 0, 1, and 2 ...


3

From what I could tell is you want to end up with a unique list of Franchise__c strings from the queried records, if so.... You code could be reduced to this: Set<String> SplitList = New Set<String>(); for(Sample_Order_Campaign__c so : [SELECT Franchise__c FROM Sample_Order_Campaign__c WHERE Name =:selCampaignName]){ IF(!string.isBlank(so....


3

Ajax toolkit is a Javascript wrapper over SOAP based API .While ajax toolkit is a good option ,the problem with Ajax toolkit has been the no of API calls consumed .It will count against the API limit . The other option is to use Javascript remoting .Please take a look at docs. With javascript remoting you will need apex behind scenes and you can bulk ...


3

I don't believe it's possible (can't see any list methods in the API). So you only option if you want to use Remote Objects is looping on create - not a great way to do it. However, there is an alternative that has no more overhead than Remote Objects - the AJAX Toolkit. To include the library, you do this: <script src="../../soap/ajax/36.0/connection....


3

You should be simply be able to use the list . Do not try to DeSerialize ,its already deserialized and you can consume the list as it is public static string getSave (list<tier> tiers, string recordId){ //do some stuf here and return a string for(StaffelPricingController.tier t:tiers){ } }


3

String.split() expects a regular expression, not a string. Use myString.Split('\\$\\$\\$'); (Thanks to @Mugambo) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm#apex_System_String_split


3

You can load the city codes in a Data Extension and do a lookup. %%[ var @cityCode, @city set @cityCode = AttributeValue("cityCode") set @city = Lookup("cities", "city", "cityCode", @cityCode) ]%% <br>cityCode: %%=v(@cityCode)=%% <br>City: %%=v(@city)=%%


3

This is a bug as reported in salesforce issue: Workaround: Set an empty array before setting the actual array of items. Note: This workaround will rerender the whole array. Code: cmp.set("v.someListAttribute", [].concat(updatedArray)); or cmp.set("v.someListAttribute", []); cmp.set("v.someListAttribute", [].concat(updatedArray));


3

I think that this error is misleading. At least I'm getting nothing from it. My first suspicion what is wrong: You're trying to use your custom created class as a map key but you don't have equals and hashcode methods implemented for it. Normally when you're using SObjects or primitive data types, you dont need to do that. Example implemantation here: ...


3

You need to start from your existing data rather than initializing an empty array. var objs = component.get('v.objs'); objs.push(event.getSource().get("v.name")); component.set('v.objs', objs); Your current code will not accumulate objects because it always overwrites from a blank array plus the latest value.


3

Aura:iteration has an attribute called as indexVar, why not use it? Also from Event docs: In the client-side controller, you can use one of the following methods to find out which button was clicked. event.getSource().getLocalId() returns the aura:id of the clicked button. event.getSource().get("v.name") returns the name of the clicked ...


2

You will have to write a get-method (Integer) for every option. I have written an example for option one below. I have taken out the for-loop and put it in another method, so all three options can be calculated in one for-loop. public Integer optionOne {get;set;} public Integer optionOneVal; public Integer getOptionOne(){ if(this.optionOneVal == null) ...


2

You will have to use two for loops For(List< String> inner : wdays){ for(String day : inner){ System.debug(day); } }


2

If you know the quantity upfront in your controller, then you can instantiate multiple objects to serve as placeholders and chuck them in a map with the key being an Integer index (1 to MAX_QUANTITY). Then you can iterate through the indexes and pull the corresponding placeholder object instance from the map and display it on the page. A quick starting point ...


2

It is very likely - a test would confirm - that Apex uses an array-backed list for its lists and a quick check of the typical source code or typical documentation: The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. indicates that access speed at the various indexes is constant for such a list.


2

In Salesforce, Lists and Arrays are treated as same. e.g. Below two statements are equivalent: String[] colors = new List< String >(); and List< String > colors = new List< String >(); Please refer to this for more detailed explanation.


2

I have coded it with the same result, but I have found some interesting thing, you can call Retrieve method filtering by "isActive" parameter and "true" value, and after repeat the call filtering by "isActive" parameter and "false" value, and you will have the full set result of automations. The only thing is that I have to do in Async mode because of .Net ...


2

check this post: https://salesforce.stackexchange.com/a/62739/28187 you need "ProgramID" in attributes, and a simple filter rr.Properties = new string[] { "Name","ProgramID" }; Although I received a different error: "no rows found"... "No rows were found" on “Automation” SOAP RetrieveRequest Let me know how you go Update: Finally I found ...


2

You should make your code to look next way: List<Blob> pdf_data = new List<Blob>(); Integer form_number = Integer.valueOf(formquantity); while (form_number > 0) { PageReference pafe_ref = new PageReference( '/apex/FormTemplatePrinter?id=a4VM0000000HtpOMAS&param1=' + form_number.toString());//Change ...


2

You want to set after push into a product List handleProduct: function(cmp, evt){ var Product = cmp.find("productType").get("v.value"); cmp.set("v.options", Product); var PL = cmp.get("v.productList"); PL.push(Product); cmp.set("v.productList",PL); } And another bug in your code you iterating over list of Id that you are pushing in aura:iteration ...


2

Sadly, this doesn't work, because collection inheritance is broken. As I outlined in my previous answer, the following code demonstrates the inheritance problem: class c1 { } class c2 extends c1 { } // All C2s are C1s, but this won't compile Map<String, c2> m1 = new Map<String, c1>(); // Not all C2s are C1s, but this compiles and can crash. ...


2

Usage of String.split method doesn't fit your requirements, as you will have '(1' first element and '2)' third element. Use String.splitByCharacterType method. Splits the current String by character type and returns a list of contiguous character groups of the same type as complete tokens. This will split and extract correct parts of your string. ...


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