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.

5,159 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
20
votes
1answer
376 views

Email value is saved without parentheses (label) when using DML

When an email contains a label enclosed in parentheses, the value can be saved as typed in via SF UI. (Note: the email value "as is" is only seen when in Edit mode.) However, when the record is saved ...
16
votes
0answers
379 views

Custom Labels in Packages - Potential BUG in Winter 19 (Confirmed as Know Issue by Salesforce)

We have an unmanaged package using 167 custom labels to use the Translation Workbench in Salesforce and to be able to translate texts into different languages. Until now, all our custom labels have ...
15
votes
0answers
1k views

Using apex class as attribute type for component - Summer '14 IDE issue

I have a component that gets an instance custom Apex Class as an attribute, ie: <apex:component controller="ComponentController"> <apex:attribute name="myAttr" assignTo="{!attr}" type="...
14
votes
0answers
377 views

Continuation Apex Unit Testing - Lightning

With Summer'19 release continuation is available in Lightning. To make long running callouts. Continuation - Aura Dev Guide: https://developer.salesforce.com/docs/atlas.en-us.220.0.lightning.meta/...
13
votes
0answers
1k views

Managed Package error “Dependent class is invalid and needs recompilation”

I'm getting an exception email from a client who has installed my Managed Package in his org. The error message I receive is: Apex script unhandled trigger exception by user/organization: ...
11
votes
2answers
394 views

Security Review Preparation: Checking isAccessible on each object and field in complex SOQL queries for whole codebase

We are preparing our managed package for security review. And as a part of this we need to enforce not just create/update/delete but also read (i.e. select) permissions. That means basically checking ...
11
votes
1answer
546 views

Creating Idea Votes from portal user in Test code. DML Exception

I Wrote a very simple VF Page and Controller to show the Accounts that voted on certain Ideas. Here is the controller. Just aggregates the Up and Down votes on the Idea excluding internal votes. ...
10
votes
0answers
117 views

Cache.Session not honoring ttlSecs argument?

I'm using session cache and trying to set the TTL (lifetime) to 60 minutes. However it is expiring much more quickly (it appears to be using the default 5 minute expiry). The docs say TTLs is ...
9
votes
2answers
200 views

Field filter does not Work for Text Formula field used in SOQL

I have a simple SOQL query on Account which has a field Full_Address__c which is joint of Billing Street, City Zip. When I use this field as a filter it doesn't return the records: Example: String ...
9
votes
1answer
100 views

Non-Selective Query Async (fails) vs Sync (works) - Is that supposed to happen?

Running into the following issue only during async processes (i.e. Batch Apex): Code used is same for both sync and async apex. Both essentially pass a single record into the method Batch scope is 1 ...
9
votes
0answers
800 views

Error parsing json response: 'expected expression, got '<''. Logged in?

I'm calling a remote action which returns a wrapper. It works without any issues on most of the time. But sometimes, it throwing an error: Error parsing json response: 'expected expression, got '&...
9
votes
1answer
147 views

Read access denied: getQueryLocator(soql) vs. query(soql)

I am attempting to add pagination, and I followed this great article by Jeff Douglas. I am an admin so when I run the page it runs great, I can navigate forwards, back. When I log in as a user my ...
9
votes
2answers
218 views

System.RequiredFeatureMissingException: Object 'GroupSubscription' is not supported

I have developed an app which can mass clone any sObject, which clones the records using the batch process and it runs dynamically(object and its field are fetched dynamically), Its working fine when ...
8
votes
0answers
84 views

Rethrowing an exception is missing the stackTraceString

I have code that is wrapped into a main try-catch block and then inside of that I have another try-catch which I am using for a specific use case. If the inner try-catch gets triggered I then use a ...
8
votes
0answers
80 views

QuickAction.DescribeQuickActions Broken In Managed Packages

QuickAction.DescribeQuickActions() will return different results when called from a managed package context and unmanaged code. For a given entity type, for example Contacts, you must call ...
8
votes
0answers
137 views

@deprecated annotation issue in Managed Apex

We have 2 managed packages. Let's name those MPMAIN and MPCHILD. MPCHILD package is dependent on MPMAIN. In MPCHILD we have a class: @deprecated global class ChildClass extends MPMAIN.MainClass { ...
8
votes
0answers
286 views

Spring 18 breaks overridden apex methods in lightning components

We have an overridden @auraEnabled method that returns an array of custom apex class objects with @auraEnabled get methods. This has worked since it was built. However, one of our customers just ...
8
votes
0answers
235 views

Salesforce doesn't merge fields on email sent in platform event context

I have a process that runs every day in the morning. It is a scheduled class that publishes a platform event. When this event is run by the system, it collects some records and sends emails to some ...
8
votes
1answer
380 views

SOQL Error Only When Accessing Lead.Address Standard Compound Address Field From WorkFlow Triggered Task Insert

I've added a section of code to our task trigger that retrieves two sets of address fields from the lead or contact the task is being made on - see below-. private static void ...
8
votes
1answer
149 views

How can I reproduce the EmailAuthor native SFDC application?

I'm comfortable with sending emails using APEX and using mailmerge within that process. What I want to do now is load an email template, mailmerge it automatically using a predetermined contact ID and ...
8
votes
1answer
1k views

Test class showing error : Converted Account empty for a Converted Lead.: [ConvertedAccountId]

I need to write as test class to cover public without sharing class CMassConvert { public boolean hasErrors; public String errorMsg {get; set;} //constructora public CMassConvert() {}...
7
votes
0answers
956 views

Test cases failing with “Could not run tests on class 01pXXX because: connection was cancelled here”

When running all the test classes in my dev org I'm getting intermittent failures on some of them with: Could not run tests on class 01p400000000001 because: connection was cancelled here The ...
7
votes
0answers
328 views

Total Batches increase during the run of a batch (again)

I experienced a batch that changed (increased) the #TotalBatches during its execution. 104 total batches Reload. 106 total batches I experienced this year ago (see this question Total number of ...
7
votes
0answers
536 views

How do you use a mock response when calling Auth.JWTBearerTokenExchange.getAccessToken()?

Let's say I have a class like this /** * Example of using JWTBearerTokenExchange to demonstrate issues with testing and mocks */ public class JwtBearerTokenExample { public static String ...
7
votes
0answers
167 views

Exception during Inserting attachment from managed package

I'm working on managed package and I have to insert Attachment record from my apex code. The code is pretty simple, that's just create and insert Attachment, something like that: Attachment ...
7
votes
0answers
1k views

Email chatter followers on every post to record

I want to email all the followers of a record anytime anyone posts to the chatter feed. I assumed this would be simple but it doesnt seem to be built into the system? It seems like im gonna have to ...
7
votes
0answers
552 views

Trigger page message in the parent page from the Controller Extension of a custom list view button

Is there any way to trigger the display of a page message in the embedding Detail page from the Controller Extension of a Custom list view button? I create my list view buttons with this technique ...
6
votes
0answers
675 views

Why does SOQl query for Owner.UserRole.Name on Opportunity cause error in Opportunity Territory Assignment apex class

I've been working on an Apex class to do our Opportunity territory assignments based on the example here. I needed to modify it to support our rules that included checking the User Role on the ...
6
votes
1answer
111 views

Locale Supported Format For Visualforce Input Field

I've been rewriting a Visualforce page to use SLDS styling. Part of this requires rewriting dynamics DateTIme fields to SLDS Date time picker. This therefore means writing the Date part of the ...
6
votes
0answers
76 views

Is there is any way to get standard field api name from standard report types reports in apex?

I want to get the api name of the standard field being used in Reports of Standard report types. I used describe methods to get the columns used in a report. I analysed some of standard reports ...
6
votes
0answers
279 views

What headers are returned in RestRequest.headers property?

Question Is there an official list of which headers are returned when using the RestContext.request.headers property? Background I know that the returned data is limited, e.g. it excludes the ...
6
votes
0answers
3k views

ContentDocumentLink Apex after insert trigger error

Edit: I've built an after insert trigger on ContentDocumentLink. On cropredy's direction, I've bulkified my code and I think improved it generally. It "works" in that it accomplishes my business ...
6
votes
0answers
441 views

“Variable not visible” error in production, but fine in development

My managed package works fine in development. When it runs from client orgs, as an installed managed package, this error occurs: "VisualForce Error Variable is not visible: [PackagePrefix....
6
votes
0answers
83 views

What's happening upon deletion of a Group record

I just ran a few consecutive tests of inserting and deleting a bunch of groups via the developer console (execute anonymous). Inserted 50 Group records: List <Group> groups = new List <...
6
votes
1answer
1k views

What does '?scontrolCaching=1' mean in a URL from a Visualforce page?

I have a custom list button on the Account object that, once clicked on, auto-navigates a user to the defined Visualforce page which uses the Opportunity standardController. I notice in the URL, it ...
6
votes
1answer
311 views

API Call in Managed Package behaving differently in Scheduled Apex

I have a Scheduled Apex job, 'scheduleUnsub,' which calls a class 'resubscribeCall,' which runs some code including a method in a Managed Package (ExactTarget) which makes an API call to ExactTarget. ...
6
votes
0answers
686 views

Append content to a document

I need to create a huge document. Naturally I face up the apex's limits such that heap size and string length. I can split the creation of the document using a batch job. I thought to create the rows ...
6
votes
0answers
2k views

error from test method - “apex job is already scheduled for execution”

I have a batch apex which starts itself after x mins. this is done in finish() method using , system.scheduleBatch() method. below is how the batch looks like, global class my_ProcessPurge_Batch ...
6
votes
0answers
275 views

What determines the permissions for a profile deployed with change sets?

Question For a new profile created in a sandbox and deployed with a change set it'll carry with it the settings for all other metadata in the change set plus all settings that aren't specifically ...
5
votes
0answers
141 views

Verify Member Identities for Community Self-Registration

I'm trying to test the new feature for the Salesforce Community: "Verify Member Identities for Community Self-Registration". I want to create a Custom Verify Page and I'm reading the official docs: ...
5
votes
0answers
242 views

Issue with receiving HTTP with Content-Type:application/x-www-form-urlencoded

I've faced a strange issue during my development related to the API. My goal was to create a web service that will receive POST requests from different sources. First service: It passes all the ...
5
votes
0answers
276 views

Sync with Pardot by Apex Trigger | Duplicate send to Pardot button in Apex

I have Pardot installed in my SF sandbox and it is connected to a Pardot Sandbox. [Use Case]: If a prospect is in the recycle bin in Pardot, then it does not sync with Salesforce. If from a ...
5
votes
0answers
229 views

Apex trigger takes a lot of time to access items in list

I have a simple Contact trigger in a sandbox org that is exhibiting some serious performance issues. After doing some debugging it looks like the issue boils down to accessing the items inside Trigger....
5
votes
0answers
131 views

How to create custom rules for PMD Apex static code analyzer?

How can I create custom rules for PMD? For example, if I want to create a rule to say 'all code should be in allman style and therefore, any line with { should be the only character on the line', how ...
5
votes
0answers
329 views

Test Failed 'Validation Errors While Saving Record(s)' when loading Accounts with Test.LoadData

Background When I use the Test.LoadData method to load Account records: List<Account> accountList = (List<Account>) Test.loadData(Account.sObjectType, 'account_test_data'); I get this ...
5
votes
0answers
429 views

Named credential does not work with client credentials

I have read the full documentation and have few questions on how named credential works. I have written a custom provider like this: /** * Description of the class * <p /><p /> * @...
5
votes
0answers
124 views

No DML_END Issue

Yet another "what gives" question. I have a custom object that is updated upon a button click on a VisualForce Page. I can see in my debug logs that the object has been updated. But when I refresh ...
5
votes
1answer
112 views

Set.retainAll() empties set with custom classes

Consider this minimal example: class Test { private String val; public Test(String str) { this.val = str.toLowerCase(); } public Boolean equals(Object obj) { if (obj ...
5
votes
0answers
835 views

How to create an EmailMessage record with DML having HasAttachment to be 'true'?

I'm creating EmailMessage records via DML EmailMessage createWhatEmail = new EmailMessage( Subject = 'test' ,Status = '3' ,ToAddress = 'heim@...
5
votes
0answers
436 views

Visualforce Remoting: Javascript proxies were not generated for controller QuoteLayout: may not use public remoted methods inside an iframe

I've looked at all of these solutions here on SFDC stack exchange (1) (2) (3). I followed them for what applied to what I'm doing and I'm still getting this error. I made my apex class global ...