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.

Filter by
Sorted by
Tagged with
6 votes
3 answers
3k views

Which object stores Content Library-Members list?

Which object stores Content Library-Members list? I need to find if current logged in user has just read(Viewer) access to a Library or write(Admin/Author) access.
user avatar
  • 1,099
13 votes
4 answers
19k views

How to query more than 50000 records in apex and bind it in vf page in jqgrid and paging?

How to query more than 50000 records (78000 records) in apex and bind it in vf page in jqgrid and implement paging in it? I tried querying through SOQL and assigning it to list.. Am unable to query ...
user avatar
  • 3,102
9 votes
7 answers
4k views

Is it possible to create a reusable inline Visualforce page?

I'm working on a Visualforce page that (forgetting about page layouts for a moment) takes in a Record Id (from one of a variety of objects), does some querying for Content based on that Record Id, and ...
user avatar
9 votes
1 answer
4k views

Authenticate 3rd party Application with OAuth2

The PHP getting started guide for interacting with Force.com seems to indicate that a user always needs to reauthenticate for each session with OAuth2, and that's my understanding of the protocol as ...
user avatar
7 votes
3 answers
4k views

Apex: Calculate hour ranges

Given a start time (datetime) and a finish time (datetime) how can I easily calculate the number of hours that fell between 6:00am - 12:00pm (day hours) and 12:00 - 6:00am (night hours). They would be ...
user avatar
  • 505
6 votes
4 answers
2k views

Generating notification for user to confirm that a field has the correct value

I have a custom field called Pipeline which is a required Yes/No picklist that defaults to No. When the user makes some specific changes to the record, and Pipeline=No, I would like them to confirm ...
user avatar
9 votes
4 answers
10k views

Isn't ContentVersion 'VersionData' Updateable (Amendable)?

I'm developing an file (attachments/contents) upload app and the process of my upload is that I upload file in chunks to ensure I'm not hitting view state. For first chunk insert new attachment ...
user avatar
  • 1,099
7 votes
3 answers
11k views

Create Chatter post with mix of HyperLinks and text in the Body (in Apex code)

How to create a chatter post in the body I want to add Links in between. (in Apex code) its not complete link or complete plain text. I am looking at mix of both Example Chatter post - just has ...
user avatar
2 votes
1 answer
121 views

Triggering to check for changes in org level sharing rules

Does anyone have a solution for checking for changes in sObject__Share settings on particular objects in APEX
user avatar
6 votes
2 answers
6k views

Retrieving custom fields from a standard controller in an extension

How do I retrieve custom fields from a standard controller in a Visualforce extension controller? In the code below, if I remove the hard-coded ID "this.personParentId = '001Z000000CkZ4m';", it fails ...
user avatar
6 votes
3 answers
2k views

Is there some way to view a history of anonymous block executions?

I use the Force.com IDE and sometimes execute anonymous blocks of code through the Execute Anonymous view. I have used other tools like SQL Developer from Oracle and they keep a persistent history of ...
user avatar
  • 28.7k
22 votes
2 answers
8k views

What are the implications of implementing Database.Stateful?

I've recently implemented a batch apex class that initially did not implement Database.Stateful. After using it for a while as-is I decided to implemente better error handling via a simple Map to ...
user avatar
  • 22.2k
6 votes
1 answer
3k views

Create a custom object via the API (define the object, similar to DDL)

I was looking through the Metadata API (and Partner) but can't find anywhere described how I can define via the API a custom object. We have specific datasets which have to translate into Custom ...
user avatar
38 votes
8 answers
5k views

Is there a way to setup continous integration for apex tests?

I would like to have continous integration (with Jenkins) for my apex code in order to run them automatically after each push to my git repository. Does anyone know a way how to do that?
user avatar
  • 2,182
10 votes
3 answers
5k views

Optimal way to get Case.Id from Case.Thread_Id

We've implemented a custom Apex Email Service to extend the standard Email-to-Case functionality, and one area we're struggling to do efficiently is figure out the CaseId when all that is known is the ...
user avatar
  • 2,918
4 votes
1 answer
1k views

PageLayouts and Fieldsets in APEX

We've repeatedly tried to figure out ways to display a Pagelayout and/or FieldSet settings in our custom VF pages without having to rely on the standard controller. For example to display a fieldset ...
user avatar
4 votes
1 answer
328 views

How to get Chatter limits in apex?

There is currently a limit that a single user can only follow 500 entities on Chatter. This is very low for a Social Enterprise, in my opinion, and I figure that it will have to get increased once ...
user avatar
  • 28.7k
7 votes
1 answer
5k views

Handling Record Errors in a Batch Process

How does one handle individual record errors in a Batch Process? Tried the following example below, but once I iterate through wlist after the batch has completed (checking the job status through an ...
user avatar
  • 6,191
11 votes
5 answers
2k views

RemoteAction Insert Error: "Please provide an id or sobjectType value"

I posted this to Twitter a couple of times but I'm still stumped. I have an Apex class called "TestRemoteActionClass" with a method marked as a @RemoteAction that looks something like this: @...
user avatar
  • 183
3 votes
3 answers
342 views

API Limits Exception

We have a customer whom is hitting API limits in their org: More than 50,000 API call per-day. They're trying to isolate an installed package that might be to blame, and the only thing they've given ...
user avatar
2 votes
1 answer
458 views

Creating a method that ensures safe HTML input

We're building an app that requires the user to be able to input raw HTML (for a design template) and then be able to display that within SFDC. The challenge we've found in a security process is that ...
user avatar
  • 153
13 votes
2 answers
3k views

Using transient keyword to store password in hierarchy custom setting

Per a security review, we've found that the use of transient keyword is required to store variables within custom settings. There's a great link that's been provided to help us get pointed in the ...
user avatar
  • 153
7 votes
2 answers
2k views

How do you deprecate a global method in a managed package?

This is semi-related to another question of mine: Is there any way to clean up redundant tabs/settings/pages/etc from managed packages? However, it is a bit different. Once you've added a global ...
user avatar
  • 7,537
7 votes
2 answers
4k views

Case Assignment Notification Suppression

I am trying to determine if it is possible to suppress the Case Assignment Notification email from within a Before Update Trigger. Or confirm that this is a newly introduced bug since I believe I was ...
user avatar
18 votes
1 answer
8k 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 ...
user avatar
23 votes
5 answers
6k views

What is an easy (and fast) way to find a object named based on a parentid?

I have an app which is fired from a trigger on FeedItem and FeedComment. I can easily grab the posting user, date, parentid and type. However I am finding it difficult to rapidly determine the object ...
user avatar
  • 231
2 votes
2 answers
766 views

Workflow not evaluating to true when it should

I have a Workflow on Leads, which is a formula (also tried as a Filter), the content: Days_from_Creation__c = 1 && HasOptedOutOfEmail = False && My_Drip__c = null This is from the ...
user avatar
7 votes
4 answers
3k views

Run anonymous apex as if it were a test case

Is there any way to run anonymous apex so that it is treated the same way as a unit test? Sometimes it would be ideal to just try some code out and know that any DML operations that get performed won'...
user avatar
32 votes
5 answers
3k views

Is there a defacto 3rd party utilities library for Apex such as Apache Commons is for Java?

I have been developing in Java for some time and have grown accustom to using third party libraries such as Apache Commons for some of the more mundane functions needed in most applications (e.g., ...
user avatar
  • 28.7k
11 votes
1 answer
2k views

Deleting a class without IDE

Salesforce makes it hard to delete classes in a production org. Our change control policy doesn't allow for the use of the IDE to make changes to the production org...everything goes through change ...
user avatar
10 votes
4 answers
5k views

Linking CronTrigger sObjects to Scheduled Jobs listings

When using System.schedule to add apex jobs to the scheduled jobs listing it creates a CronTrigger sObject containing the expression determining when the job is set to run. However this CronTrigger ...
user avatar
  • 22.2k
11 votes
6 answers
2k views

How do you unit test a trigger when you don't know the required fields?

This is another issue addressed largely towards app developers. Let's say I write an insert trigger. When I write the test case for it, what I would normally do is create a new object, insert it, and ...
user avatar
  • 7,537
5 votes
3 answers
1k views

Getting LastModifiedDate of Admin changes

Let's say you have a details page of a Contact. I would like to be able to track changes that were made to Contact, such as field name changes, field type changes, etc. I assumed that there ...
user avatar
  • 2,700
4 votes
3 answers
861 views

Is there any way to clean up redundant tabs/settings/pages/etc from managed packages?

I have a mangaged package that has seen a lot of updates over time. Some parts have become redundant and aren't used at all anymore. However, with SFDC's rules about managed packages, many of these ...
user avatar
  • 7,537
56 votes
6 answers
30k 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 ...
user avatar
  • 7,537
6 votes
4 answers
9k views

Error: Could not resolve the entity from <apex:inputField> value binding '{!variable}'

This seems like it should be very simple and I have no idea why it isn't working. I have a VF page with a controller. The controller has the following property (yes, I made sure to save): public ...
user avatar
  • 7,537
15 votes
2 answers
5k views

How do you write a unit test for a trigger whose only function is to make a callout?

What is considered a best practice for writing a unit test (to maintain code coverage) on a trigger whose sole function is making a callout (Which also means it has to use a future method)? Neither ...
user avatar
  • 7,537
15 votes
3 answers
1k views

Batch Apex in AppExchange package and orgs with related triggers that call @Future methods

Here's the problem: when an org has a trigger that calls an @Future method, any batch Apex that fires that trigger will fail, since you cannot call an @Future method from an @Future method OR from ...
user avatar
  • 4,248
22 votes
9 answers
21k views

What is a concise function that formats a (String) decimal into a currency format in Apex?

goal: write the most concise function that formats a (String) decimal into a currency format in Apex. Feel free to trainwreck the code for points, I've kept mine exploded for readability purposes.
user avatar
  • 2,775
7 votes
6 answers
3k views

Clone SObject Relationships

Is it possible to use a database query to get a set of related records and clone them into new related records. sObject[] sObjectsWithChildRelationships = [SELECT Id, (SELECT Id, myObject__c FROM ...
user avatar
11 votes
1 answer
5k views

Detecting governor limits through apex

Is it possible to programatically detect if you have reached a governor limit? For example, you can make 200 future calls per license per 24 hours. IF you hit that limit SFDC just starts to blow up ...
user avatar
  • 7,537
3 votes
1 answer
1k views

Can you query/write to a MySQL database from apex code?

Is it possible to work with a MySQL database directly from Salesforce? If not, is the main approach to create some sort of web service to sit in the middle between the two?
user avatar
  • 7,537
8 votes
2 answers
2k views

Can you get Apex in a Home page component without using an iframe?

The question is fairly straightforward - is there a way to get apex into a home page component (left side/narrow component) without resorting to loading a visualforce page in to an iframe? I can't ...
user avatar
  • 7,537
8 votes
8 answers
12k views

How to export debug logs?

I spend my days waiting on the Force.com Console and it makes me crazy, I have a pretty nice machine and it still chokes on the details sometimes. Anyways, I saw Loggly had given a presentation at DF ...
user avatar
5 votes
2 answers
731 views

Can someone provide good examples or pointers on how to integrate LDAP with Apex?

Does anyone have examples or pointers on how to integrate LDAP with Apex? We are running Apache DS and are looking to use our existing LDAP system to manage roles in our customer portal. Before I ...
user avatar
  • 2,775
5 votes
1 answer
4k views

Re-set user.IsPortalEnabled field?

I can't figure out how to set IsPortalEnabled to true, once it has been set to false. Not a critical issue, just trying to increase my knowledge and understanding of the platform. I was playing ...
user avatar
7 votes
5 answers
13k views

How do we create a popup from VF page?

I have a VF page with couple of buttons. I need to show a popup when one of the buttons is clicked. Something like a modal popup where user has to fill in something or click the cancel button in the ...
user avatar
  • 11.9k
3 votes
1 answer
156 views

How can I reference a test Remote Access application while testing my managed package?

In my managed package I have included a Remote Access application that references my external web site to handle various integration tasks including: Product fulfillment requests/cancellations Client ...
user avatar
  • 1,357
14 votes
3 answers
26k views

ID for Contact portion of Person Account

Is it possible to get the ID of a Contact which is part of a Person Account? I have a custom object which has a custom field referencing the Person Account, though it seems to be referencing the ...
user avatar
  • 471
4 votes
2 answers
3k views

Call a @RemoteAction from a custom button

I would like to call an @RemoteAction method from a custom button. I am aware that it is already possible to call a WebService method. The view page of my object is already a visualforce page ...
user avatar