Hot answers tagged

14

A Lightning attribute like v.body, which is typed as Aura.Component[], is called a facet. It's perfectly legal to have multiple facets in your component. You'd have to do something more like this, if I may modify your example component to suit. Note the Aura.Component[]-typed attributes: these behave like v.body in that they hold dynamically-instantiated ...


13

Your strategy will work, but your constructor must contain no parameters, and the same goes for your newInstance() call. You pass the name of the Type you want to construct into the Type.forName method. Type customType = Type.forName('SomeClass'); SomeClass instance = (SomeClass)customType.newInstance(); You probably will want to implement an interface ...


12

The new Tooling API provides this access. Access to this data through Apex Code may be limited, however, depending on the size of the classes, etc involved. This is definitely something that would work through Visualforce though (which is basically how the Developer Console works; by leveraging the Tooling API to deploy code and build symbol maps).


11

On the question "is it possible" the answer is obviously yes; the real question is whether the effort is justified for your project or product. A good way to proceed with writing your own is to port already working code to Apex. An example I Googled quite quickly (not saying this is the best starting point) is A Java expression parser. Look for ones that ...


11

Try using string.valueOf(variableName); That should solve your problem.


10

No, there's no way to do a dynamic typecast in apex. However what you can do to work around this is make a virtual or abstract class with all of the logic using the dynamic apex form (e.g. record.put). Then have a subclass for the Lead type that wraps this method's return type in a Lead cast. For example: public abstract class GenericFactory{ public ...


9

You referred to <c:{!@label.ComponentName} /> as the kind of solution you want. While it probably won't involve Custom Labels, you are definitely close with Dynamic Visualforce. To do this in a package does require a number of moving parts, but the following is probably the most native-friendly and future-proof approach. And it works! Hope this gets ...


9

If you do have a need to pass parameters to the dynamically created class, a way to do that is to create the class by using JSON.deserialize: Type t = Type.forName('Process'); Process p = (Process) JSON.deserialize('{}', t); so that if the class has e.g. fields x and y: public virtual class Process { Integer x; String y; } you can set values in ...


9

Sorry can't comment yet. But i have the same problem when using cmp.find() to get a dynamically created component the return value is always undefined. I even tried it with the code provided in the documentation(https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_dynamic_cmp_async.htm). <!--c:createComponent--> <aura:...


9

The issue comes from the Sender Profile (SP) being processed prior to the email. This means that any variables set inside the email will not be rendered as they are set after the variable is called in the SP. The logic you used above utilizing variables from the email works for subject line and preheader as they are processed after the email, so the ...


8

Depending on the number of objects you have, it may be more efficient to perform a query instead. If you're truly interested in all objects and their record types, you can do this: RecordType[] recordtypes = [SELECT Id, Name, DeveloperName, IsActive, SObjectType FROM RecordType]; This uses a SOQL query, and is so limited as such (100 queries per ...


8

Approval processes route a record to one or more approvers, specifying the steps necessary for a record to be approved, and who must approve it at each step. In a typical approval process (what you're calling a "static" approval process), the approvers at each step are explicitly specified in each step approval process. You have a little flexibility -- for ...


7

Using "List of Lists" try the following: if (myList == null) { myList = new List <List <Event>> (); } for (i = 0; i < x; i++) { if (myList.size() == 0) { myList.add(new List <Event> ()); } else if (myList[i] == null) { myList.add(i, new List <Event> ()); } // your code // ...


7

Believe it or not, I was very, very close. JSON.deserialize may not be able to provide me a Map, but JSON.deserializeUntyped can. Once I found out I could utilize that, I came up with the following code: AggregateResult results = [SELECT COUNT_DISTINCT(ParentId) FROM Account]; Map<String, Object> aggregateResultMap = (Map<String, Object>)...


7

I believe this issue is related to Dynamically created component with aura:id, set as a Facet inside a parent component, is not found when calling find() and passing in aura:id Have a look at the answer from Trevor Bliss


6

Not directly; Apex Code is a strongly typed language, and doesn't really have the capacity to evaluate code in an interpreted manner. The closest you'd probably get is either rigging your own interface, or using Visualforce expression evaluation, which is fraught with limitations and pitfalls. For example, let's say you built this interface: interface ...


6

This isn't a "dynamic" query. A dynamic query is one that has variable fields, objects, or filter conditions. Unless you have a strong, compelling reason, simply use an inline query: SOject[] results = [Select id, name From selectedObject Where selectedField LIKE :'%'+userInput+'%']; Alternatively, you can use binding directly, but you'...


6

AggregateResult can't be reliably created or modified. They're a construct for querying aggregate data from the database. Instead, consider using a Map<Id, Object>: public static Map<Id, Object> extractValues(SObject[] records, SObjectField field) { Map<Id, Object> results = new Map<Id, Object>(); for(SObject record: records) { ...


6

It appears as if the issue is related to the $A.createComponents being in a for loop. I readjusted my code to the following to fix this issue: populateRow: function (component) { var record = component.get("v.record"); var fields = component.get("v.fields"); // Array of components to create var newComponents = []; for (var idx in ...


6

You can't initialize an aura:set component. It causes Bad Things to happen. The label attribute is a Component[] value so you need to create an aura:text component and then assign it to the label after component generation. The code should look something more like this: ({ createTabset: function(component) { var newComponents = []; ...


6

You really should be using aura:if for rendering elements: <aura:if isTrue="{!v.IsTest}"><div>test</div></aura:if> You don't need to compare a Boolean value to true, it's already true. That said, the following should also work: <div class="{!v.IsTest? '': 'slds-hide'}">test</div>


6

I think the key thing is that you need to set the tab body on component creation. Here's an example (minus error handling) that sets the tab body to a ui:outputText Notice that the components are created as an array. $A.createComponents([ ['lightning:tab', { 'aura:id': 'accountViewTab', 'label': 'Account Detail' }], ["...


6

When you iterate over a map, you're actually getting the key, not the value. That means you need to access the value from record map: <apex:pageBlockTable value="{!leadMap}" var="key" id="leadTable"> <apex:repeat value="{!leadCols}" var="FieldLabel"> <apex:column value="{!leadMap[key][FieldLabel]}"/> </apex:repeat> </...


5

The expression value can be set in an Apex controller using a dynamiccomponent. Because the expression is built outside of Visualforce, it can be dynamically set based on a Custom Setting. Here's what I ended up with: Visualforce <apex:dynamicComponent componentValue="{!SectionsAndFields}"/> Apex public Component.Apex.OutputPanel ...


5

This is a partial answer as I was very recently faced with this but could be a helpful starting point - evaluates expressions using Reverse Polish Notation // -------------------------------------------------------------------- // rpnCalculate : calculates an expression using reverse polish notation // --------------------------------------------------...


5

That is correct, you cannot upsert on a List of SObject when you specify external ID. Error: "Upsert with a field specification requires a concrete SObject type" Please vote for the idea here : https://success.salesforce.com/ideaView?id=08730000000aNhVAAU Conceptually what you require is : DYNAMIC TYPECASTING. But I am not sure if dynamic typecasting can ...


5

You need to include a string in quotes, or, even better, simply use a bind variable, which reduces the odds of SOQL injection: listAccount = Database.query('select name, billingstate, phone, website '+ 'from account where name like :searchString'); Generally speaking, though, a query like this can be inlined, since you don't ...


5

The snippet you posted in the comments is failing due to a common mistake. Its an order of operations error, because you're adding an extra string to your comparison, it gets merged into your string value, and screws up your comparison. Your code is evaluated like this: '==>' + 'ab' == 'ab' ('==>' + 'ab') == 'ab' '==>ab' == 'ab' // false If you ...


5

I always recommend using the serialize method to generate correct JSON: String payload = JSON.serialize( new Map<String, Object> { 'UserID' => username }); This will emit the correct JSON, even if your username were to contain special characters, etc.


5

You would normally upload a ZIP file, and use it in the manner described in the docs: import TRAILHEAD_CHARACTERS from '@salesforce/resourceUrl/trailhead_characters'; // ... einsteinUrl = TRAILHEAD_CHARACTERS + '/images/einstein.png'; Loading a dynamic resource name directly is not supported; this is because the compiler will verify the resource name ...


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