Questions tagged [polymorphism]
The polymorphism tag has no usage guidance.
49
questions
0
votes
3
answers
100
views
can we override start() method for batch apex
can we override start() method of the Batchable interface? If no please specify why?
7
votes
1
answer
203
views
Covariant Return Types in Interfaces
Having recently rolled out a beta version of my open source project, I started looking for ways to optimize it, and accidentally came across the fact that apex actually supports covariant return types ...
7
votes
1
answer
2k
views
Invoking Interface Method in Abstract Class Method
Assume we have some interface, abstract class and contrete class:
interface I {
void foo();
void bar();
}
abstract class A implements I {
public void barFoo() {
bar(); // Compile ...
0
votes
1
answer
231
views
Execute Overriden method when Base Class is executed - Salesforce Apex
I have the following scenario, where i have overriden the base class method. When i am testing it, the parent class's Initial code is what gets executed. What should be done to get the overriden code ...
15
votes
1
answer
936
views
Interface method can be implemented as static
Assume we have some simple interface:
public interface IExecutable {
void execute();
}
and some class that implements the interface:
public class Executor implements IExecutable {
public ...
0
votes
1
answer
874
views
Acccessing SOQL query data values in Lighting Web Component
I am trying to figure out how to display the values for a couple of fields in a Lightning Web Component that is driven by the following SOQL query: SELECT Id, ActivityDateTime, Account.Name, Who.Name, ...
4
votes
1
answer
596
views
Some doubts regarding apex best practices and SOLID principles
I have a lightning component controller class:
public class ComponentVisibilityController {
@AuraEnabled
public static Boolean checkToDisplayComponent(Id recordId) {
return ...
0
votes
1
answer
179
views
Design Pattern Help: Extended Interfaces with methods that shared the same functionality/code
I'm trying to figure out the best pattern for the code below (example: not actual code). IOpportunitiesA and IOpportunitiesB are extending the base interface and they have a similar method, ...
12
votes
1
answer
319
views
Why is CaseFeed.CreatedById Polymorphic?
A polymorphic lookup is, by definition, one where the SObjectType of the parent be multiple different values. That was the basis for how I compiled Polymorphic keys - definitive list?
However, a ...
0
votes
1
answer
76
views
Code efficiency when using same content in multiple method in same class
what I should learn and do if I have 3 different methods that are essentially doing the same thing but only the query statement that makes the differences.
For instance my code below have 2 methods ...
2
votes
0
answers
970
views
DescribeFieldResult.getReferenceTo returns only one type in a specific scenario
I am seeing some strange behavior where DescribeFieldResult.getReferenceTo returns only one type for the Lead.OwnerId field in some cases when invoked in a trigger context.
The code below displays ...
7
votes
1
answer
502
views
Polymorphic keys - definitive list?
I am working with salesforce data within SQL, and am trying to come up with a proper solution to handle polymorphism/polymorphic keys. I am aware of the easy ones (whatid/whoid in task and event), ...
1
vote
2
answers
228
views
Unexpected constructor execution with subclasses - bug?
I've distilled a real-world issue down to an example to show my question:
public class SubclassTrial {
virtual class BaseClass {
public string label { get; set;}
public integer value { get;...
1
vote
2
answers
813
views
Extending class variable does not exist on properties
I defined a virtual class and two classes that extend it with additional properties.
After creating the class instance and trying to initialize it's properties i get a "Variable does not exist" error ...
0
votes
1
answer
98
views
Polymorphic Lookup fails to disable other fields on page
I'm replicating the "New Task" page, with "Log Activity" branding instead of "Log a Call" & removing the extra "Follow-up Task" section.
As part of the standard behavior, the polymorphic WhoId ...
5
votes
1
answer
2k
views
Overriding Getters and Setters from Base Class
I'm trying to convert an old global class to be a virtual class so I can have some variations on its implementation. There is some existing behavior on the property Getters that I'd like to preserve ...
6
votes
1
answer
233
views
Dynamic Polymorphic Lightning Components
I have a Parent component rendering child components. I want this to happen dynamically, meaning that I can pass in a child component definition and fill it with data afterwards.
<!--c:child-->
...
2
votes
1
answer
670
views
Lightning Component Polymorphism is not working:
I am trying to use Bob Buzzard approach to get Lightning Component Polymorphism working, so I have method
myAction: function(component) {
component.getConcreteComponent().getDef().getHelper()....
0
votes
2
answers
1k
views
Task related to (whatId) lookup field for upsert : error Entity type for the polymorphic foreign key reference
I am trying to load data via talend ETL, where my Related to (whatId) is a lookup on a custom object's external id.
I am stuck, and I believe i have everything set up correctly
my salesforce shows ...
2
votes
1
answer
305
views
Unexpected difference using List<sObject> vs using Set<sObject> [duplicate]
I have sets of objects CustomObjectA, CustomObjectB, CustomObjectC... that I need to pass to a method.
I would like to put them in a Map of type Map< String, Set< sObject > >, but when I ...
6
votes
2
answers
2k
views
In Apex, is it possible to use Polymorphism and Overloading to mitigate the need for conditional logic?
While working-on/playing with the Build a Restaurant-Locator Lightning Component Trailhead, I wanted to develop a more clever (possibly read over-engineered) way of selecting address from either the ...
9
votes
2
answers
2k
views
Ambiguous method signature on NULL value
I know that all primitive types are objects and can be null in Apex
But is there a way to handle the null value when doing polymorphism ?
public class myClass{
public myClass(String name){
...
0
votes
2
answers
1k
views
How to retrieve Profile name using typeof clause in SOQL for getting Hierarchy(User) type of custom settings
I want to retrieve name of Profile for which a hierarchy type of custom setting is defined. This custom setting is not organisation wide default, but is specific for a profile. I got to know recently ...
9
votes
3
answers
3k
views
Polymorphism for Batch Processing in Salesforce
Edit: Have edited the title in the hopes that anyone in the future looking for help on a related topic can find this easily. Here is a great way to implement polymophism with batch classes: https://...
1
vote
1
answer
523
views
Query custom fields from object with a polymorphic field
I am trying to query the ProcessInstanceWorkitem object which has a relationship to the ProcessInstance object, however the ProcessInstance object has a polymorphic relationship by using the ...
28
votes
2
answers
272
views
Unintended polymorphic private method
I've run into an odd case where a base class is calling a private method in a subclass that isn't defined as an override.
It's a bit contrived, but demonstrates the issue:
public virtual with ...
9
votes
1
answer
838
views
Do the *Result objects in Database have a common ancestor?
I'm doing some polymorphic programming, and I decided that I wanted to be able to gracefully handle partial saves using SaveResult without blocking the user experience. The code looks roughly like ...
21
votes
1
answer
2k
views
Abstract, Interface, Classes OH MY - Question on Approach
So I believe that I have a real world use case for an object model that uses abstract classes and interface. I do however have a few questions about the best way to go about it:
Interface
public ...
15
votes
2
answers
5k
views
apex String instanceof Object?
given: Map<String, String> m = new Map<String, String>();
m instanceof Map<String, Object> is always true
then why is m instanceof Map<Object, Object> always false?
2
votes
1
answer
203
views
Owner PhotoUrl VisualForce
Is it possible to display the FullPhotoUrl or SmallPhotoUrl of a User owner with Visualforce only? I know how I would implement with an extension but I would like to avoid writing one if possible. I'...
4
votes
1
answer
1k
views
Abstract Class Constructor: Possible to Inherit? [duplicate]
I have tried the following:
public class OuterClass
{
abstract class abstract AbstractInnerClass
{
final Object member;
public Abstract InnerClass(Object member) { this.member ...
1
vote
1
answer
73
views
Compare Contract End Date to ActivityDate on Task of Child Custom Object
I'm going round in circles trying to figure out how to approach this one -
I have a Contract with an end date
The Contract has a child object (Contract Work)
Contract Work has tasks
I want to write ...
2
votes
2
answers
159
views
Developer Console throws Type Exception
I have a base class that's a mash up of the base classes here. What's important is that this class contains the following property and method:
public CommunicationBase Owner { get; set; }
public ...
4
votes
1
answer
2k
views
Is SOQL Polymorphism also supported in WHERE clause?
I am using the polymorphism in my SOQL queries which is working fine, an generic example of the query is below
SELECT
TYPEOF What
WHEN Account THEN Phone, NumberOfEmployees
...
30
votes
2
answers
760
views
When is SOQL Polymorphism going to be enabled by default?
SOQL Polymorphism (SELECT TYPEOF) was introduced in Winter 13, API version 26 for developer organization.
Is this feature going to be enabled by default for production organizations also sometime in ...
3
votes
2
answers
9k
views
Determine Case owner is queue or user?
how to check whether a case owner is a queue or a user? I am writing a validation rule where i need to check who is the owner of the case.
3
votes
2
answers
1k
views
Custom object parent relationship similar to "Attachment" object
Can we have a custom object similar to Attachment object where the parent can be any of the "Account", "Contact", "Lead" etc?
https://www.salesforce.com/us/developer/docs/api/Content/...
5
votes
3
answers
515
views
How can I get a polymorphic relationship to update a user lookup field?
Why isn't this code writing the lead owner's manager to the Lead_Owner_Manager__c field?
if(Trigger.isUpdate && System.Trigger.oldMap.get(x.Id).OwnerId != x.OwnerId){
dh.Old_Value__c =...
7
votes
1
answer
1k
views
Custom Settings are NO SObjects - How to use them polymorphic?
My app uses different types of custom settings. Let's call them SettingA__c and SettingC_c.
I want a method that handles both types of settings polymorphically.
private void handle(SObject setting) {...
6
votes
1
answer
849
views
Polymorphic ID does not accept external ID, or does it?
Requirement:
Via APEX dataloader upload attachments (standard object) and link it via ParentId to a custom object's record. This works easily when the SFDC ID is provided for the polymorphic ParentId ...
2
votes
1
answer
2k
views
Polymorphic Lookups - How to pull the
I have a query in my class where I'm trying to pull in the position name from a task that is being created on an application.
So I have Position, Application, and Candidate. The task is created on ...
8
votes
4
answers
1k
views
Typecasting for VisualForce?
I am not sure how to word the question; I apologize if the title is not relevant to my problem.
Please pretend the following three classes are inner classes in a controller.
I have a base class with ...
10
votes
2
answers
3k
views
Determine if a Type implements an interface
I've created an interface within a managed package that installers can implement (much like the example here and Making your managed package extensible with Apex Plugins). Clients can then configure ...
13
votes
1
answer
2k
views
Can I create a polymorphic key from a custom object?
I'm creating a custom object that needs to be related to multiple other objects (but only one per record). I.e. via a ParentId field it could be related to a Opportunity, a Contact, an Account, or ...
1
vote
2
answers
1k
views
Is the OwnerId field in the Report object a polymorphic key or not?
Is the OwnerId field in the Report object a polymorphic key or not?
So the OwnerId field in the Report object can be either a reference to a Folder, Account, or User, doesn't this make it a ...
7
votes
2
answers
1k
views
Is SOQL Polymorphism enabled by default in API 26?
Is SOQL Polymorphism enabled by default in API 26? I'm getting the error 'SOQL TYPEOF expressions are not supported in this organization' error when deploying to my test org that's on API 26.
2
votes
3
answers
1k
views
SOQL Polymorphism Results
What kind of result set is returned from this SOQL and can I write this inside a for loop?
[SELECT Name, Description,
TYPEOF OwnerId
WHEN Folder THEN Name
END
FROM Report]
8
votes
1
answer
2k
views
SOQL query on fields related by polymorphic lookups
Here is the SOQL query I am trying to make:
List<Task> tasks = [
SELECT Id,ActivityDate,Status,Subject
FROM Task
WHERE What.Type = 'nexus__Goal__c'
AND (What....
18
votes
1
answer
9k
views
What are the best practices for using polymorphism in Apex?
Apex provides at least two different methods for polymorphism (that is, writing code that can use objects of different classes in a uniform way):
Standard inheritance-based polymorphism, where code ...