Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [apex]

Questions relating to Apex, the native programming language for the Force.com platform. Use it for general questions on syntax, errors, constructs, and rules of use. Most questions should include a code *excerpt* to help answerers understand specifically what has gone wrong or why you need help.

97
votes
10answers
29k views

How do I start to debug my own Apex code?

Sometimes questions are posted here that would best be answered by helping the questioner learn how to do their own debugging. (Remember that proverb?) I'd like to have something to link to on this ...
44
votes
3answers
11k views

General trigger bulkification - best practices

A general question asked from time to time on stack exchange is question of trigger bulkification. Therefore I have 2 questions: Which best practices are you using? What is the best way to handle ...
56
votes
8answers
33k views

Get lists of dependent picklist options in Apex

I have a pair of dependent picklists. In Apex code, how can I determine what options are valid in the dependent field for each option in the controlling field? I've tried using getPicklistValues(), ...
15
votes
4answers
5k views

System.Exception: Too many SOQL queries: 101 [duplicate]

I am getting a Too many SOQL queries: 101 error on a trigger when I am trying to deploy another trigger. I am posting the trigger which is causing the error. trigger rollupAccountShowings on Account ...
12
votes
1answer
27k views

How to deserialize a JSON String to Apex

How can I deserialize this json object: { "response": { "count": 1, "benchmark": 0.22567009925842, "requests": [ { "request": { ...
10
votes
2answers
2k views

Parent and children relationships accessible via trigger?

I'm sure this has been addressed before but I can't seem to find the answer. In a trigger on a record, aside from the actual fields on the record, what do I have access to? The parent info? that ...
126
votes
8answers
17k views

Unit testing code which has logic around the CreatedDate

An example of the problem would be trying to test a trigger on a case which will fire on update, and look for time differences between when a case was created and now. Ideally in the unit tests I want ...
27
votes
7answers
53k views

Where To start Learning With Salesforce Development

Where should I start learning? There are various topics to learn like Objects, Classes, Apex, Visualforce, SOSL, SOQL, Triggers, etc. There are so many options out there to start learning. I couldn't ...
29
votes
2answers
28k views

HTTP Callout from Triggers

I have a trigger on the Custom Object that calls a class. That class makes an HTTP GET request to a Web Service. However I get the following error: Callout from triggers are currently not supported. ...
34
votes
6answers
17k views

Using APEX to assemble HTML Letterhead Emails

I am looking to assemble an HTML Letterhead Email Template for an email service integration project. There are two sObjects that hold this information - EmailTemplate and BrandTemplate. ...
51
votes
10answers
60k views

What would be the best approach to get the recordtype id

I know of two approaches to get the recordtype id of a particular record type Use SOQL RecordType RecType = [Select Id From RecordType Where SobjectType = 'Account' and DeveloperName = 'Business'];...
47
votes
2answers
15k views

Lead Conversion Trigger Order of Execution

I've got a project where I'm looking to tweak the standard lead conversion process. Triggers and lead conversion has always been funky in past projects so I was hoping to start the design off by ...
16
votes
2answers
19k views

System.CalloutException: You have uncommitted work pending

I have same exception can please Click Here The previous post issue is resolved. Exception: :System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out ...
118
votes
2answers
23k views

How to reduce a large internal view state / what is in the internal view state?

I'm building an account search page that lets users select accounts and then pass them to other pages to perform various actions on them. Unfortunately users are reporting hitting the view state ...
94
votes
3answers
50k views

How can I efficiently generate a Set<Id> from a List<SObject> structure?

I have a bit of code where I've written a SOQL query that returns a list of SObject records, however I need a Set<Id> structure to pass to another method that I don't have control of (and thus ...
19
votes
2answers
19k views

How can i integrate one SFDC org to another SFDC using Rest Api

I am trying to integrate one Salesforce org to other org by using Oauth setup, I wanted to use use consumer key and consumer secret key in my REST class to connect with the org, after connection part ...
41
votes
4answers
1k views

Why Are Data Silos Important in Unit Tests?

I have a lot of strong opinions about this issue, but had a hard time finding official documents today to back up my position. A lot of times we say it is bad practice to use seeAllData=true, but we ...
34
votes
2answers
3k views

Ghost Schedulable Classes Blocking Deployment

Recently I've been running into issues where deployments were blocked due to a Schedulable job pending or in progress when I'd already cleared the Schedulable job from that class. Any tips for ...
19
votes
1answer
48k views

Can anybody explain the UNABLE_TO_LOCK_ROW error?

Error Message: Developer script exception from Nicomatic : quotepotential : quotepotential: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with ...
15
votes
1answer
674 views

Set Relationship Via Name Pointing Field?

One of the most startling things I ever learned from @BobBuzzard is that you can update a lookup by using the name pointing field. At least, I thought that's what I learned, until a recent debate cast ...
52
votes
6answers
24k views

Can report data be accessed programatically?

Is there any way to access existing reports and their data to be used in apex? Sure, I could write the SOQL manually but if I want it to mirror a specific report I would have to make code changes ...
43
votes
5answers
14k views

How do you deserialize json properties that are reserved words in apex?

Is there any way to deserialize JSON into an object using JSON.deserialize if some of the property names in the JSON are reserved words in apex? I want to do something like this: string jsonString = '...
34
votes
6answers
8k views

Is it possible to test apex that relies on field history tracking?

I have some code that relies on field history tracking by querying the History for a custom object. This works fine, but it appears that the history records aren't created during the test so none of ...
4
votes
1answer
794 views

Help on Invokable Apex Test class and @Future callout Apex test Class

I am pretty new to Apex and trying to learn as much as possible. Any help would be really appreciated. I have two classes. Invokeable Apex Class: This class is just getting called by a Process (...
72
votes
7answers
11k views

Apex static code analysis

What static code analysis tools are there for apex? The only one I seem to be able to find is the Force.com Security Source Code Scanner but that has the draw back of placing your request into a queue ...
36
votes
3answers
45k views

Difference between controller and extensions

Can any one explain the usage of controller and extensions in Visualforce? In which scenario we have to use controller and extensions? Thanks in advance
55
votes
2answers
4k views

Salesforce, Oracle and the Seven Dwarfs

Over my time as a Salesforce developer, I've written some code which on occasion managed to surface Oracle plsql exceptions and curiously the error text contains the name of one of Disney's Seven ...
57
votes
4answers
31k views

SFDC: Understanding With Sharing, Without Sharing & Unspecified Sharing Classes

Per my understanding of With Sharing, Without Sharing and non-sharing-specified Classes in Apex, I would like to jot down the following notes and leave certain blanks for not sure answers; I wanted to ...
47
votes
4answers
49k views

How to run a scheduled job every 15 minutes?

Using the salesforce GUI it seams impossible to schedule a job every 15 minutes. Or more than once a day.
19
votes
2answers
44k views

how to get a picklist all values in apex controller

I have a Student object and have a pick list field "Student Status" in this object. Status can be Full-Time OR Part Time. Now my requirement is i want this student status list, Part-Time or Full-Time ...
84
votes
3answers
3k views

Any reason to skip DML on empty lists?

In parts of my code I have DML statements with an if around to only do the DML if the list is not empty: if( !recordsToUpdate.isEmpty() ) { update recordsToUpdate; } Couldn't I just write? ...
41
votes
7answers
26k views

How Can I Tell the Day of the Week of a Date?

I'd like to build in some logic based on the weekday (e.g. Monday, Tuesday, Wednesday) of a given date. How can I identify the date, using either formulas or Apex code?
15
votes
1answer
44k views

How to pass javascript value to controller..?

I want to pass the java-script value to controller.I am using repeat on VF page. VF page <apex:repeat value="{!listAdj}" var="Adj" id="hrs"> <td><div class="requiredInput"&...
38
votes
4answers
26k 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 ...
14
votes
4answers
16k views

apex:inputFile can't be used in conjunction with an action component when deleting a row

When working on a visualforce page, I encountered this error: "apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a ...
26
votes
1answer
17k views

Error: MIXED_DML_OPERATION on setup and non-setup objects

In my test class i have the creation of a dummy custom setting and a dummy lead: Group g1 = new Group(Name='group name', type='Queue'); insert g1; QueuesObject q1 = new ...
14
votes
2answers
15k views

Exeception on After Insert, Record is read only

I'm writing a trigger for new opportunity products to populate a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product). This is my trigger: ...
5
votes
3answers
3k views

How to get the entity ID for a custom field in Apex?

I am looking for a way to get the 15 character entity ID for a custom field on my Lead object in an Apex controller. I have tried this: private String getEntityIdFor(String fieldName) { Map&...
34
votes
5answers
18k views

How to generate a GUID/UUID?

What is the best way to generate a GUID/UUID from Apex code (such as a trigger)? Preferably in the following format: nnnnnnnn-nnnn-nnnn-nnnnnnnnnnnnnnnnn Example: 13219ec0-3a81-44c5-a300-...
69
votes
4answers
22k views

Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison

When I have a Set of Id's and I want to do a dynamic SOQL query that I want to use it in for an IN comparison, I have to convert the Set to string in the format of: ('id1','id2',id3',...) The way I ...
14
votes
3answers
50k views

System.FinalException: Record is read-only: Trigger.updateCompetitors: line 24

I am writing a trigger to get all the Opportunity competitors into a field on Opportunity, however, getting an error while testing it. Error: updateCompetitors: execution of AfterUpdate caused by: ...
9
votes
2answers
6k views

screen scrape Salesforce with REST GET call from Apex

Consider this code snippet from my answer to rao's question: String requestUrl = '/services/data/v26.0/sobjects/User/describe'; Http http = new Http(); HttpRequest req = new HttpRequest(); req....
7
votes
1answer
10k views

Why does apex:param assignTo work with apex:commandLink but not apex:commandButton?

How do command buttons and command links differ when it comes to using <apex:param>? The param value is not being passed to the controller. I have the following code in a Controller : public ...
61
votes
5answers
16k views

What is a good set of naming conventions to use when developing on the Force.com platform?

I've looked in the Apex developer's guide and a saw the Naming Conventions section which has basically only has this: We recommend following Java standards for naming, that is, classes start with a ...
55
votes
1answer
3k views

InstallHandler runs under a special ghost user. What rights does it have?

When you install a managed package with a post-install script, Salesforce creates a special ghost user under which all of the post install activities occur. I think this is undocumented. Here are some ...
24
votes
2answers
26k views

Apex Cast sObject list dynamically to a specific sObject Type

The upsert() DML operation requires a specific List based on a specific sObject type, for instance:List<Account> lstAccount = new List<Account>(); However, we are trying to generate a ...
26
votes
2answers
18k views

@AuraEnabled Support for Apex Class Return Types?

Beginning on page 141 of The Lightning Components Developer Guide, they list the valid types for aura attributes. Apex Classes and collections are included, so I've written an apex controller method ...
21
votes
3answers
755 views

What is a use case where one would use an SObject as a Map key?

In Dan Appleman's book Advanced Apex Programming, he explains how using SObjects as Map keys (i.e. Map<SObject, *value*>) is supported but it's poor practice, since the key is actually ...
11
votes
3answers
3k views

What is the best practice re: API Version of your Apex Classes?

I'm in the process of pushing some updates to some code I originally wrote 12-18 months ago, and the API Version is between 27.0 and 29.0 I know this is to protect the integrity of the test classes ...
9
votes
3answers
11k views

Make Validation Rule bypass if TRIGGER is run?

Is there a way to make a Validation Rule BYPASS via it's logic when a Trigger is doing it's job? I've already tried various methods including setting a hidden field on the object in the Trigger (can'...