Questions tagged [apex-code]

A proprietary Java-like programming language for the Force.com Platform, not to be confused with Oracle's Application Express (oracle-apex).

From the Salesforce.com page What is Apex?:

Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Force.com platform server in conjunction with calls to the Force.com​ API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.

For questions that are related to this tag you can use shorter tag - .

(Please use to refer to Oracle Application Express.)

Useful links:

Force.com Apex Code Developer's Guide

1514 questions
33
votes
5 answers

How to avoid MIXED_DML_OPERATION error in Salesforce tests that create Users

Sometimes in Salesforce tests you need to create User objects to run part of the test as a speciifc type of user. However since the Salesforce Summer 08 update, attempts to create both User objects and normal objects (such as Accounts) in the same…
codeulike
  • 22,514
  • 29
  • 120
  • 167
25
votes
5 answers

Salesforce - How to Deploy between Environments (Sandboxes, Live etc)

We're looking into setting up a proper deployment process. From what I've read there seems to be 4 methods of doing this. Copy & Paste -- We don't want to do this Using the "Package" mechanism built into the Salesforce Web Interface Eclipse Force…
danswain
  • 4,171
  • 5
  • 37
  • 43
20
votes
2 answers

Join an array of strings in Apex

Using Apex, I want to split a string and then rejoin it with the 'AND' operator as the separator. I split the string successfully but having an issue in rejoining it. String [] ideaSearchText = searchText.Split(' '); // How to rejoin the array of…
Kp Gupta
  • 483
  • 2
  • 7
  • 23
20
votes
5 answers

How do I avoid STANDARD_PRICE_NOT_DEFINED when unit-testing an OpportunityLineItem in Apex v24.0?

Apparently a new feature of the Spring '12 / v24.0 release of Apex in Salesforce.com is that unit tests no longer have access to 'real' data -- thus (if I'm understanding the change correctly) a SOQL query will now only retrieve objects that have…
Ben Dunlap
  • 1,838
  • 1
  • 16
  • 17
18
votes
10 answers

How do I detect the environment in Salesforce?

I am integrating our back end systems with Salesforce using the web services. I have production and stage environments running on different URLs. I need to be able to have the endpoint of the web service call be different depending on whether the…
Craig Harris
  • 536
  • 1
  • 3
  • 11
16
votes
3 answers

Detect when a record is being cloned in trigger

Is there a way to detect that a record being inserted is the result of a clone operation in a trigger? As part of a managed package, I'd like to clear out some of the custom fields when Opportunity and OpportunityLineItem records are cloned. Or is a…
Daniel Ballinger
  • 13,187
  • 11
  • 69
  • 96
14
votes
8 answers

Retrieve salesforce instance URL instead of visualforce instance

From a visualforce page, I need to retrieve our organization's salesforce instance's URL, and not the visual force URL. For example I need https://cs1.salesforce.com instead of https://c.cs1.visual.force.com Here's what I've tried so far and the…
Jan Julian
  • 473
  • 2
  • 4
  • 15
13
votes
2 answers

Salesforce.com Id attribute seems to have a 15 and 18 character value, whats the difference?

When using the SOAP API to work with salesforce.com (SFDC) it seems that the primary key in the underlying database is Id. Well there seems to be two representations of this value as either a 15 character version or an 18 character version. I have…
geoffc
  • 4,030
  • 7
  • 44
  • 51
12
votes
3 answers

Organizing Apex Classes under Namespace

Is there any way in Salesforce to group apex classes under a package or namespace? Can we use managed package for internal organization purpose?
Mitul Makadia
  • 398
  • 6
  • 24
11
votes
2 answers

Salesforce Apex Triggers - How to check if field is included in update trigger?

I would really appreciate if someone can guide me to check if a particular field is included in update call inside a before/after update trigger. Many thanks.
Mustafa Turab Ali
  • 111
  • 1
  • 1
  • 3
11
votes
1 answer

Check if an apex list contains an object

Is there any way to check if a list contains a certain element? I looked at the List functions and did not see any contain() function like Java or C# , so I was wondering how other people are handling this. I really need to use a List I cant use a…
raym0nd
  • 3,172
  • 7
  • 36
  • 73
10
votes
2 answers

Apex unit test sees no data

I have created a task in my org with subject "Email Task" i have written apex code as public class TaskInfoDAOClass { public static List queryTaskInfo () { integer count = [SELECT count() FROM Task]; System.debug('Row Count :'+…
Deepak Mule
  • 437
  • 5
  • 21
10
votes
6 answers

How to check the user's CRUD permissions for an object in Salesforce?

According to a requirement, i have to change the owner of an account if the user does not have read access to a third object. I need a functionality similar to the isAccessible() method of Describe Field Result, but it is only available for the…
ntnng
  • 303
  • 4
  • 7
  • 12
9
votes
2 answers

How to refer html element id specified in visualforce and pass onto javascript function?

I have apex tag that generate input text field. When someone clicks this field, I want to execute javascript. But when I check the HTML source, this…
Meow
  • 18,371
  • 52
  • 136
  • 180
9
votes
1 answer

SOQL query with subquery

I'm having trouble getting the results I want from a Salesforce/Apex/SOQL query. I want: A list of Contact objects containing only contacts who are CampaignMembers of a set of campaigns; and they should have the data from that Campaign member easily…
Benj
  • 1,853
  • 4
  • 18
  • 27
1
2 3
99 100