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
7
votes
2 answers

Salesforce Apex: ISO Timestamp Format Function

I was wondering if there is an apex date or datetime function to format a date/time to the ISO formatted timestamp "2007-04-05T12:30-02:00" or would this have to be created by another means? Thanks.
SalesforceQueries
  • 319
  • 3
  • 7
  • 18
7
votes
2 answers

Foreach with a select/from in square brackets?

I was recently looking at wrapper classes and googled the following page...http://wiki.developerforce.com/page/Wrapper_Class While I understood wrapper classes, I was baffled by the following... public List getContacts() { …
Christopher Rucinski
  • 4,737
  • 2
  • 27
  • 58
7
votes
1 answer

Documenting Salesforce.com Apex class files

Since the Salesforce.com Apex language is "Java-like", I'd like to use javadoc or Doxygen to generate API documentation for the package we plan to release on App Exchange. I found an ApexDoc project on Google Code, but it's severely limited and uses…
tomlogic
  • 11,489
  • 3
  • 33
  • 59
7
votes
2 answers

Why does "||".split("\\|").length return 0 and not 3?

When there are adjacent separators in the split expression I expect null or an empty string--not have it eliminated. The Java code is below: public class splitter { public static void main(String args[]) { int size =…
tggagne
  • 2,864
  • 1
  • 21
  • 15
7
votes
2 answers

CSRF safe Custom button linked to Apex method

I'm looking for a technique to execute Apex code from a custom button added to the Opportunity object in a way that protects the user against CSRF. The current approach being used comes from the question - Custom Button or Link to a Visualforce page…
Daniel Ballinger
  • 13,187
  • 11
  • 69
  • 96
7
votes
4 answers

newline character on text area

I have a custom field called Current_Address__c which is of datatype textarea. I need to populate this field in the format below. ie a newline char after street and another newline after zip. street City state Zip Country The values of city state…
Prady
  • 10,978
  • 39
  • 124
  • 176
6
votes
3 answers

How can I parse a String and return an Enum value in Apex Code?

I want to use Enum values in my Apex code as we have some strict types when working with an external service, however when I get a response from the external service I'm struggling to convert the String Representation of the Enum value back to the…
thegogz
  • 654
  • 6
  • 14
6
votes
7 answers

How do I introspect the class of a variable in APEX?

I would like to know the class of a variable/property at runtime. For example: Integer i = 5; //pseudo-code if (i.className == 'Integer') { System.debug('This is an integer.'); } else { System.debug('This is not an integer, but a ' +…
barelyknown
  • 5,510
  • 3
  • 34
  • 46
6
votes
2 answers

How can I stop a managed trigger from executing while running a test class?

Usually, when a trigger runs, we check what kind of a profile the user has, and if it's the kind where we don't want the triggers to run, then we exit the trigger before running any other code. Problem: we have a SF package installed that we…
Kirill Yunussov
  • 1,955
  • 1
  • 21
  • 24
6
votes
3 answers

How can do code alignment in Eclipse base Force.com IDE

How can do code alignment with Eclipse base Force.com IDE. Alignment shortcut key 'CTRL+SHIFT+F' is not working for Apex code.
Channa
  • 4,963
  • 14
  • 65
  • 97
6
votes
1 answer

Fire a update trigger when particular field is updated

How do I fire a before update trigger only one or some particular fields are updated and not fire when other fields are updated as it causes duplicate record in other object
user1048080
  • 187
  • 2
  • 6
  • 12
6
votes
1 answer

Reference a remote site setting URL in Apex class?

I have a webservice class that will be in a managed package and distributed to multiple clients. The class currently has a variable with the hardcoded value of the server it's hitting. The problem: the server will be different for each client, so a…
CDelaney
  • 1,238
  • 4
  • 19
  • 36
6
votes
2 answers

Can we Cast SObject dynamically in Salesforce(apex)?

Is it possible to Cast SObject dynamically? Example : I know we can do this : (Account) Sobject But I want to do this as the return type of sObject changes based on certain parameters. (Dynamically Passing the Name) SObject Any Kind of way around…
AtNeo
  • 61
  • 1
  • 2
6
votes
1 answer

unable to access RESTful services which build on force.com platform using Apex

I have create a RESTful service on Force.com using Apex below is my code. @RestResource(urlMapping='/helloWorld/*') global with sharing class RestWebservice { @HttpGet global static String helloWorld(){ return 'HelloWorld'; } } I am…
Vivek P
  • 3,050
  • 6
  • 27
  • 31
6
votes
3 answers

How can I get the key as well as the value in an apex for loop?

I have a map object which stores where the Id is a contact Id, and the String is a generated email message. I have successfully looped through the map and have been able to pull out the values (The String portion) as I iterate through…
VictorKilo
  • 1,839
  • 3
  • 24
  • 39