The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [class]

A class is a template or blueprint from which objects are created. An object is an instance of a class.

Filter by
Sorted by
Tagged with
43
votes
5answers
2k views

What are all of the reasons why Salesforce customers should upgrade the API version on their Apex classes, triggers, and pages?

I haven't been able to find any official documentation or community discussion of the compelling reasons to upgrade the API version on Apex classes, triggers, and pages. I know there is the general ...
43
votes
4answers
31k views

Deleting Triggers/Classes from Production

I was recently told ( Deleting a Class with IDE - cannot delete from Production? ): You cannot delete a class in production directly. You will need delete the class from your sandbox and then ...
42
votes
2answers
5k views

Inheriting non-implicit constructors on Apex classes

If I have an abstract parent class like this: abstract class Vehicle { public Vehicle(Person driver) { // } } and then I create a child class like this: public class MagicCarpet ...
32
votes
3answers
14k views

Return Name of class from instance of that class

I need a quick approach to something like: MyClass mc = new MyClass(); String theName = ClassNameProvider.getName(mc); // returns 'MyClass'
31
votes
0answers
731 views

Best practices for designing and maintaining Global classes?

We've always been conservative when it comes to exposing Globals for use by extension packages or subscriber extensions, and perhaps too conservative. We're considering being more proactive wth our ...
19
votes
3answers
3k views

How to delete a Test Class WITHOUT using eclipse

I cannot install Eclipse, even if I wanted to. It is not approved software for my org. How can test classes be deleted from production, using deployments? There no 'active' checkbox when I am ...
18
votes
4answers
6k views

Why use an interface in Apex?

I'm studying for my Platform Dev I exam, and I've been reading about interfaces. I understand how they work in abstraction, but what I don't understand is why you would use them. The documentation ...
15
votes
3answers
11k views

Can we access class properties dynamically with Object class?

Is it possible to access Apex class properties dynamically? While we can create Object's, and assign any other class to an Object, I'm not sure how I can access the properties of these Object's. Can ...
15
votes
1answer
3k views

When to add apex class permissions to a profile

The apex class permissions are a bit confusing to me. For example, classes used by page controllers do not need to be added to the profile. Can anyone give a complete list of scenarios on when you ...
13
votes
1answer
3k views

Exclude properties from Apex class when serializing to JSON

Is it possible to delete class properties dynamically in Apex Example: public class BananaHolder() { public boolean isRipe; public boolean isDelicious; public integer ...
12
votes
3answers
2k views

Difficulties with Appleman's Trigger Classes

I'm working on a major project that has numerous triggers creating new records on 4 objects while also syncing updates back and forth between 3 of the 4 objects. The new records are primarily created ...
10
votes
4answers
17k views

How to delete a class from production using destructiveChanges.xml

Can any one tell me the steps to delete a class using destructiveChanges.xml
10
votes
7answers
3k views

How to get a list of Test Classes in an org

I need to get all test classes (classes with isTest Annotation) in an Org.. Is there anyway to filter test classes out of all the Apex Classes
10
votes
2answers
7k views

APEX: Use a dynamic string to create an instance of a class

I have an abstract class called Process that I extend to create a list of processes (List<Process>); each in relation to an object. For now everything works as expected but I'm really hoping to ...
10
votes
2answers
231 views

System classes are being shadowed by my Apex classes

When I create a class called Process it looks like I'm experiencing class shadowing. For example: public class Process { //... } The existence of the above class prevents me implementing the ...
10
votes
2answers
159 views

Incomplete code blocks vulnerability

I've submitted my application for Security Review and I've got this problem in the report. I'm not sure how to fix it. Let's see the First case: I have some classes that don't have any code like ...
10
votes
1answer
506 views

Why can I not reuse the name of Apex classes deleted in previous releases?

Because the documentation defines it that way. Yes since Winter'15 it explicitly states: Although a component is deleted, its Name remains within Salesforce. You can never create another ...
10
votes
1answer
1k views

How to avoid circular dependancy and understand how salesforce compiles classes

I have 4 classes which are dependent on each other and i am always running into circular dependencies which is causing the code not to compile. I have a controller which has a reference to a ...
10
votes
1answer
558 views

Why are static variables allowed only in outer classes?

According to the documentation, static variables are allowed only in outer classes. Why is that? Is it because you'd need to instantiate the inner class first?
9
votes
1answer
7k views

Too many query rows 50001

Can anyone please tell me if there is something wrong with the scrip below. I am using LIMIT 50000 but still getting this error. I will appreciate any help! code: //for mws chart ...
9
votes
1answer
3k views

Creating a class by consuming a WSDL document Schema:attribute

I have a problem with salesforce functionality. I've created flat WSDL file but when I am trying to create class in salesforce I still get this error: Error: Failed to parse wsdl: Unsupported ...
9
votes
2answers
5k views

How to invoke a method of an apex class at run time

We have a usecase where we need to invoke an instance of a class and invoke a method at run time using string. I know with reflection i can instantiate a class. But how do we invoke a method of a ...
9
votes
2answers
612 views

Strange Behavior with null sObject in Apex Class

I've observed some strange behavior with null sObjects which are members of an Apex class. Consider the following anonymous block: public class test { public Contact tc; public test(){} } ...
9
votes
1answer
1k views

How to deserialize JSON to a class where the same variable name has different data types?

I am trying to deserialize some JSON to a class using JSON.deserialize. My JSON looks like this { "type": "GeometryCollection", "geometries": [ { "type": "Point", ...
8
votes
2answers
5k views

Set Contains method is not working correctly after overriding equals() and hashcode() methods

I have created one class name like Test and have overriden its equals() and hashcode() methods and then created its 2 objects like below - Test obj1 = new Test (); Test obj2 = new Test (); and now ...
8
votes
2answers
440 views

First trigger: coding - best practices

This is my first production trigger and I'm just wondering if there is a more efficient way to write this code. Basically, if a campaign meets the criteria in the IF statement, I want it to create a ...
8
votes
2answers
6k views

Is it possible to compare DateTime and Date in SOQL

I was wondering if it is possible to compare a DateTime and Date in SOQL. I am trying to pull data for the product that where sold today Date.Today(). Purchase_Date__c is a DATETIME field Date d ...
7
votes
1answer
206 views

Can class be made virtual after it has been packaged?

Can you make a global class virtual after it has been packaged? Salesforce documentation states that: You cannot add an abstract method to a global class after the class has been uploaded in a ...
7
votes
1answer
513 views

How to search through global methods of managed packages?

You can see global methods in the managed package classes via Web UI. I have hundreds of managed package API classes that I need to search through by a keyword, to find a method that does what I need ...
7
votes
1answer
5k views

Is anyone using classes in anonymous apex?

I can't find anyone writing about this, but this works when executed anonymously: public class foo { public void bar() { system.debug('\n\n#### FOO BAR ####\n\n'); } } foo f = new foo(...
7
votes
2answers
2k views

Getting the right converted currency in SOQL

What is the right way to get the converted currency in SOQL? I've got this in my query: SELECT Owner.UserRole.Name, Id, Name, Include_in_Forecast__c, convertCurrency(Amount) FROM Opportunity ...
7
votes
2answers
911 views

DML not allowed on ApexClass

I am trying to move around 80 classes and visualforce pages from sandbox to production by using change set but i got an error One or more components failed Version Compatibility Check. This ...
6
votes
4answers
3k views

SOLVED! Multiplication in SOQL

Is it possible to multiply this values, something like this: Qty__c * NRPrice__c in the query below PODetails2 = [SELECT Qty__c, NRPrice__c FROM o_Bundle__c ]; or I have to do it in the VF page ...
6
votes
2answers
2k views

How to prevent users from viewing apex code?

There are many apex classes and triggers in my production org. Despite 'System Administrator' being the only enabled profile, (in Develop>>Apex Classes>>"Class Name">>Security) users can still view ...
6
votes
4answers
7k views

Compile All Classes?

Does anyone know of any documentation on this function, "compile all classes" on the Apex Classes page? I'm finding nothing on help.salesforce.com or elsewhere. (UPDATE regarding desire to automate ...
6
votes
2answers
1k views

Moving Triggers to Utility Class

I am beginning the process of moving all of my Sampling triggers to a utility class, and I am hitting a few snags. I have the following line of code to which I am getting the following error Field ...
6
votes
1answer
1k views

Return different data type using only one method

Is it possible to make an apex method wherein you can return different kind of data type (e.g. Integer, String, Double, etc.)?
6
votes
1answer
1k views

Is there a Class.forName() equivalent for Apex

I'm looking to dynamically instantiate a class by its name. How can I do that in Apex? I thought about a factory method with a series of if-else statements, but am not satisfied with that as it isn't ...
6
votes
3answers
472 views

Dynamic implementation of class using with sharing or without sharing based on certain conditions

I have one checkbox on my vf page.when i select this i want that the class to which this VF page is referring should work in with sharing mode and when i deselect it class should work in without ...
6
votes
1answer
1k views

Possible to declare static constants in an inner class?

I want to define an outer class with two inner classes, the inner classes containing specific constants related to each of them. For example: public class Stuff{ public class Letters{ ...
6
votes
2answers
1k views

What is the correct way to check if two dates overlap

I have 2 object. They both have a start date and an end date. How can I check if they overlap? now I have: if((item1.DateStart__c >= item2.DateStart__c && item1.DateStart__c <= item2....
6
votes
3answers
2k views

Test Class - How to create a Partner Account

My need would be to create a Partner Account (that is: an Account with field isPartner set to true!) in test class, having checkbox PartnerAccount set to true, but I'm not having success with this ...
5
votes
3answers
9k views

Compile Error: Method does not exist or incorrect signature: Test.startTest()

I am experiencing something weird on the Sandbox with all the test classes. whenever I run a test class I get the error: Method does not exist or incorrect signature: Test.startTest(). I am ...
5
votes
3answers
3k views

Insert List of Parent and Child Records in One DML Statement

I saw an example how to insert Parent and Child Record in one DML Statement from Developer Guide and It's Working Fine no issue in that. Here In my case I would like insert List Of Both Parent and ...
5
votes
2answers
6k views

IN operator must be used with an iterable expression : For loop

I am getting Subject header error at below line. Can someone let me know what is the issue? Line: for (Compliance_Incident_abv__c myContact : [select ID,ManagerEmail_abv__c,RepEmail_abv__c,...
5
votes
2answers
866 views

Trigger to update sibling records after inserting a new child

How do I update children of the same parent after insert of a new child? For example, if I insert a new Contact with role of 'CEO' for an Account, then any Contact related to the Account with the ...
5
votes
2answers
9k views

Scheduled Job does not execute. Though shows in GUI

I have a scheduled class that is seen and setup within the Gui. Setup->Monitoring->Scheduled Jobs It is set to run everday at 6PM. It shows started and next scheduled run. However, I started it over ...
5
votes
1answer
963 views

Deployment Test Failure - Too Many SOQL Queries: 101 but Query isn't in a Loop

First: I know this question has been posted many times so I apologize for making a new one, but I read over a lot of the old ones and they almost always seem to be that the SOQL query is inside of a ...
5
votes
2answers
2k views

Test classes with Developer Console

Is there any way of solving this bug? Basically, whenever I try to run a test (Username > Developer Console) I can run the tests and all but when I get to the part where I want to check the red & ...
5
votes
1answer
2k views

find out dependent fields, object and classes in salesforce

I want to know class is dependent to which class, object, and Field. I have tried to retrieve data from SymbolTable but it doesn't show me dependent Class Name or ID. Is there any another way to ...