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
14
votes
6answers
8k views

Why is the count() query in salesforce not counting the no. of query rows returned as 1?

Sample code on a custom object, Asset__c, containing 78,000 rows: Integer number1 = [SELECT count() FROM Asset__c ]; system.debug('Query Rows used by count():'+Limits.getQueryRows()); If i do this.....
1
vote
2answers
1k views

Display Articles in a tree like structure

I am trying to create a VisualForce page where I display our articles in a tree like structure. There are only 2 levels in the tree, so like: +Root ++Geography ++Politics ++Economy There are ...
6
votes
3answers
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.
13
votes
4answers
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 ...
9
votes
7answers
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 ...
9
votes
1answer
3k 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 ...
7
votes
3answers
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 ...
6
votes
4answers
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 ...
9
votes
4answers
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 ...
7
votes
3answers
10k 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 ...
2
votes
1answer
119 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
6
votes
2answers
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 ...
6
votes
3answers
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 ...
22
votes
2answers
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 ...
6
votes
1answer
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 ...
38
votes
8answers
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?
10
votes
3answers
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 ...
4
votes
1answer
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 ...
4
votes
1answer
318 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 ...
7
votes
1answer
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 ...
11
votes
5answers
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: @...
3
votes
3answers
340 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 ...
2
votes
1answer
438 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 ...
13
votes
2answers
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 ...
7
votes
2answers
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 ...
7
votes
2answers
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 ...
18
votes
1answer
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 ...
23
votes
5answers
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 ...
2
votes
2answers
733 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 ...
7
votes
4answers
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'...
32
votes
5answers
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., ...
11
votes
1answer
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 ...
10
votes
4answers
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 ...
10
votes
6answers
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 ...
5
votes
3answers
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 ...
4
votes
3answers
852 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 ...
54
votes
6answers
29k 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 ...
6
votes
4answers
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 ...
15
votes
2answers
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 ...
15
votes
3answers
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 ...
22
votes
9answers
20k 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.
7
votes
6answers
2k 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 ...
11
votes
1answer
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 ...
3
votes
1answer
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?
8
votes
2answers
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 ...
8
votes
8answers
11k 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 ...
5
votes
2answers
722 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 ...
5
votes
1answer
3k 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 ...
7
votes
5answers
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 ...
3
votes
1answer
154 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 ...