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.

7,031 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
16 votes
0 answers
2k views

Custom Labels in Packages - Potential BUG in Winter 19 (Confirmed as Known 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 ...
Uwe Heim's user avatar
  • 28.3k
15 votes
1 answer
5k views

Multiple future method from Queueable Apex

As per the documentation we can only call 1 future from Queueable context. But in below code I am able to call multiple future methods from same queueable class and no error is being thrown. public ...
Elijah's user avatar
  • 819
14 votes
0 answers
2k 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: ...
VarunC's user avatar
  • 5,920
13 votes
0 answers
4k 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 ...
Daniel Ballinger's user avatar
12 votes
1 answer
716 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. ...
Chris Duncombe's user avatar
11 votes
0 answers
471 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 ...
Shanerk's user avatar
  • 1,042
11 votes
1 answer
1k 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 ...
Robert Sösemann's user avatar
11 votes
0 answers
2k 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 ...
jon_wu's user avatar
  • 777
10 votes
0 answers
2k views

Update user email without email confirmation via Apex

I have been trying to update the user email via scheduled apex, but it seems I am out of luck! User u = [Select Id, email from user where email = '[email protected]' limit 1]; u.isactive = ...
Santanu Halder's user avatar
10 votes
0 answers
561 views

Salesforce External Service - Capturing Request and Response

We are doing POC to use external services for integrating with external systems. It works well.With spring 20 as per preview release notes enhanced external service is going GA. Question: Is ...
RedDevil's user avatar
  • 7,775
10 votes
0 answers
184 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 QuickAction....
sv-alex's user avatar
  • 131
10 votes
1 answer
430 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 ...
dsharrison's user avatar
  • 3,992
10 votes
2 answers
987 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 ...
Ashwani's user avatar
  • 22.6k
10 votes
1 answer
186 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 ...
Eric's user avatar
  • 54k
10 votes
0 answers
2k 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 '&...
Melbin T's user avatar
  • 383
10 votes
1 answer
277 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 ...
Steve MunLeeuw's user avatar
10 votes
1 answer
2k views

Do not send email when activating a user

I'm writing some code that should (de-)activate some users based on some criteria. This part was easy, but one of the requirements is also that this user should NOT get an email. So when I create a ...
Novarg's user avatar
  • 5,236
10 votes
0 answers
809 views

Implement Domain Event Pattern in Apex - can and should it be done?

In Domain Driven Design a single pattern is drawing a lot of attention to itself - Domain Events and Event Queues. (slide via http://de.slideshare.net/andysal/never-mind-the-bollocks-heres-the-domain-...
Robert Sösemann's user avatar
9 votes
0 answers
650 views

Formula.recalculateFormulas producing gack

Winter 20 release is in live, so I wanted to use this glorious feature Formula.recalculateFormulas Thus I tried the below block of code: Opportunity opp = new Opportunity(Purchase_Price__c=2000 , ...
Pranay Jaiswal's user avatar
9 votes
0 answers
810 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 ...
Arthlete's user avatar
  • 4,855
9 votes
0 answers
1k 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 ...
Shridhar Puntambekar's user avatar
9 votes
0 answers
840 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 ...
Renato Oliveira's user avatar
9 votes
0 answers
227 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 ...
Pavel Slepiankou's user avatar
9 votes
1 answer
185 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 ...
Venko's user avatar
  • 1,030
9 votes
0 answers
625 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 ...
Robert Sösemann's user avatar
9 votes
2 answers
2k 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() {}...
AnuRaj's user avatar
  • 2,482
8 votes
1 answer
243 views

Query highest value of custom Field on Large Object

Existing Logic: We have a trigger that gets the highest value of a custom Field "UIN__c" on various Objects and increments the value by 1 on each new Record. This Field functions as an ID ...
César Antonio Villalta's user avatar
8 votes
0 answers
408 views

Uncrustify with VS Code is overindenting SOQL Lines

I use VS Code and use Uncrustify to format the apex code As per this article. This was working fine for me until all of a sudden my SOQL lines are now automatically indented after the WHERE clause. ...
Z33dawg's user avatar
  • 1,361
8 votes
0 answers
786 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: ...
vt89's user avatar
  • 725
8 votes
0 answers
3k views

getRecordTypeInfosByDeveloperName doesn't work with duplicate Developer names

Our product comes with a couple objects including RecordTypes. In our customer org I'm adding some RecordTypes and experienced, that I can give them names that the packaged types already have. So now ...
itsmebasti's user avatar
  • 6,359
8 votes
0 answers
8k views

System.SetPassword During User Creation Sets Password But User Cannot Login?

Background: We've created a pseudo-single-sign-on integration between our external cloud program and our Salesforce environment, allowing our users to log in to our Lightning Community Site via a ...
Morgan Marchese's user avatar
8 votes
1 answer
468 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. ...
LucidLunatic's user avatar
8 votes
0 answers
1k 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 ...
lastYorsh's user avatar
  • 331
8 votes
1 answer
3k 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 ...
apn's user avatar
  • 1,722
7 votes
0 answers
484 views

how to write test class from Apex ConnectApi.Wave.executeQuery?

How to write the Apex test class for ConnectApi.Wave.executeQuery? ConnectApi.LiteralJson result = ConnectApi.Wave.executeQuery(JSONString);
Mahesh Joshi's user avatar
7 votes
1 answer
423 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 ...
RedQueries's user avatar
7 votes
1 answer
2k 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 ...
Andy Hitchings's user avatar
7 votes
0 answers
2k 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 ...
Keith Mancuso's user avatar
7 votes
1 answer
2k views

Could not evaluate formula for value passed to Flow

Has anyone come across this error when trying to use Process Builder/@InvocableMethod to call an Apex class? This is the error I see in the Debug log: Could not evaluate formula for value passed to ...
Phil Hawthorn's user avatar
6 votes
0 answers
72 views

Handling uncatchable exceptions from chained queueable - finalizer hitting retry limit

We have a need to process a number of records (several thousand) using methods from a third-party managed package, which also involves callouts. We've achieved this by passing in the list of objects ...
James's user avatar
  • 173
6 votes
0 answers
106 views

Transactions Committed After Lock Not Queryable?

I have created a function that is: Run every hour in a batch job. May be called on demand. May be called on-demand by a webservice method. It is summarised as follows: Lock the parent records. ...
Sean's user avatar
  • 61
6 votes
0 answers
274 views

APEX Schema ChildRelationships: why have some relationships their relationshipName = null?

There is some strangeness in the some standard Childrelationships. Most Relationships are as expected, but let us take Account and Quote as an example: On Quote we have a standard lookup field Quote....
Uwe Heim's user avatar
  • 28.3k
6 votes
1 answer
949 views

Can I get all existing Pages for a Community using Apex?

I would like to create a custom component to use in Experience Builder, and this component will allow a configurable navigation to another page. I would like to use a dynamic picklist with Apex to get ...
Fabien Taillon's user avatar
6 votes
0 answers
526 views

System.Quiddity Enum sync vs async

With the new Winter '21 release, salesforce makes it much easier to detect what is a current running context by means of Request.getCurrent().getQuiddity() method. This is great, thank you, ...
Oleksandr Berehovskyi's user avatar
6 votes
0 answers
2k views

How to get a PageReference from Site.login(username, password, url) in an Apex Test

When I run this code from within a LWC controller: ApexPages.PageReference pageRef = Site.login(username, password, url); It returns a valid PageReference instance. But when I test the code in a ...
Robs's user avatar
  • 9,187
6 votes
0 answers
729 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 ...
Andy Hitchings's user avatar
6 votes
0 answers
431 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 ...
Olivia's user avatar
  • 3,431
6 votes
0 answers
854 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 ...
Kruse in Salesforce's user avatar
6 votes
0 answers
3k 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 ...
Jonathan Miller's user avatar
6 votes
0 answers
154 views

how to access patch version in Salesforce managed package post install script

We have been trying to access the salesforce patch version from post install script part of our managed package. System.requestVersion().patch() always returns null. It's mentioned in the SF ...
user360's user avatar
  • 445

1
2 3 4 5
141