Questions tagged [polymorphism]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
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?
sfdcinfant's user avatar
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 ...
Oleh Berehovskyi's user avatar
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 ...
Oleh Berehovskyi's user avatar
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 ...
Sarkkunan's user avatar
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 ...
Oleh Berehovskyi's user avatar
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, ...
Smart Systems's user avatar
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 ...
nSv23's user avatar
  • 494
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, ...
Andrew L.'s user avatar
  • 805
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 ...
Adrian Larson's user avatar
  • 148k
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 ...
Adnan Zahry's user avatar
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 ...
Jelle van Geuns's user avatar
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), ...
TestMcTesterson's user avatar
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;...
Jason Clark's user avatar
  • 11.4k
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 ...
RealGigex's user avatar
  • 175
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 ...
battery.cord's user avatar
  • 8,686
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 ...
zeneto's user avatar
  • 107
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--> ...
itsmebasti's user avatar
  • 6,280
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()....
Patlatus's user avatar
  • 15k
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 ...
Jay Rizzi's user avatar
  • 455
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 ...
moth's user avatar
  • 454
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 ...
Brian Kessler's user avatar
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){ ...
benahm's user avatar
  • 2,517
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 ...
Sarang's user avatar
  • 2,550
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://...
coldspeed's user avatar
  • 681
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 ...
realtek's user avatar
  • 163
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 ...
Daniel Ballinger's user avatar
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 ...
sfdcfox's user avatar
  • 468k
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 ...
Eric's user avatar
  • 53.7k
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?
davec's user avatar
  • 161
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'...
Adrian Larson's user avatar
  • 148k
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 ...
Adrian Larson's user avatar
  • 148k
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 ...
MikeA's user avatar
  • 1,015
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 ...
ricksmt's user avatar
  • 602
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 ...
Anil Shivaraj's user avatar
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 ...
Tzach's user avatar
  • 684
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.
user8132's user avatar
  • 343
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/...
Jonna's user avatar
  • 131
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 =...
Rob Alexander's user avatar
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) {...
Robert Sösemann's user avatar
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 ...
snstulemeijer's user avatar
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 ...
gato negro's user avatar
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 ...
Matthew Moisen's user avatar
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 ...
Daniel Ballinger's user avatar
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 ...
Daniel Ballinger's user avatar
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 ...
fourq's user avatar
  • 2,091
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.
fourq's user avatar
  • 2,091
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]
fourq's user avatar
  • 2,091
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....
zachelrath's user avatar
  • 9,503
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 ...
Jeff Trull's user avatar