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.

6,469 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
18 votes
1 answer
2k 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="...
user avatar
17 votes
0 answers
1k 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 ...
user avatar
  • 33.6k
13 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: ...
user avatar
  • 5,606
12 votes
0 answers
3k 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 ...
user avatar
11 votes
1 answer
190 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 ...
user avatar
  • 617
11 votes
1 answer
642 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. ...
user avatar
10 votes
0 answers
299 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 ...
user avatar
  • 930
9 votes
1 answer
84 views

Why the Sorting Logic in Salesforce SOQL and UI is VERY different from other Systems?

The ordering mechanisms in Salesforce are really odd. Take any SObject having any Text field (e.g. Name on Account) and create some Records. Do that on an Org with no other Records of the type (e.g. a ...
user avatar
  • 33.6k
9 votes
0 answers
144 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 ...
user avatar
  • 121
9 votes
0 answers
350 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 ...
user avatar
  • 3,952
9 votes
0 answers
1k 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 ...
user avatar
  • 747
9 votes
2 answers
658 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 ...
user avatar
  • 22.2k
9 votes
1 answer
152 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 ...
user avatar
  • 53.1k
9 votes
0 answers
1k 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 '&...
user avatar
  • 373
9 votes
1 answer
215 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 ...
user avatar
9 votes
2 answers
398 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 ...
user avatar
8 votes
0 answers
322 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 ...
user avatar
  • 7,543
8 votes
0 answers
549 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 , ...
user avatar
8 votes
0 answers
540 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 ...
user avatar
  • 4,441
8 votes
0 answers
638 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 ...
user avatar
8 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 ...
user avatar
  • 4,972
8 votes
1 answer
704 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 ...
user avatar
  • 836
8 votes
0 answers
213 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 ...
user avatar
8 votes
1 answer
174 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 ...
user avatar
  • 990
8 votes
0 answers
595 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 ...
user avatar
8 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() {}...
user avatar
  • 2,452
7 votes
1 answer
90 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 ...
user avatar
7 votes
0 answers
322 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. ...
user avatar
  • 1,204
7 votes
0 answers
653 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: ...
user avatar
  • 685
7 votes
0 answers
925 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 ...
user avatar
7 votes
0 answers
2k 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 ...
user avatar
  • 6,130
7 votes
0 answers
5k 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 ...
user avatar
7 votes
0 answers
688 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 ...
user avatar
7 votes
1 answer
442 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. ...
user avatar
7 votes
0 answers
924 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 ...
user avatar
  • 321
7 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 ...
user avatar
  • 1,702
7 votes
1 answer
592 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 ...
user avatar
7 votes
0 answers
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 ...
user avatar
7 votes
1 answer
1k 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 ...
user avatar
6 votes
0 answers
89 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. ...
user avatar
  • 61
6 votes
0 answers
69 views

Visualforce Action Button on Lightning Record Page leaves an entry in browser history causing re-execution. Can this be prevented?

(NOT SURE, BUT THIS ISSUE MIGHT BE A SALESFORCE BUG OR AT LEAST AN INCONSISTENCY) I have defined an Action of type "Custom Visualforce" like this The button for this Action is "◈ Clone&...
user avatar
  • 33.6k
6 votes
0 answers
109 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....
user avatar
  • 33.6k
6 votes
0 answers
824 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 ...
user avatar
  • 8,262
6 votes
0 answers
319 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);
user avatar
6 votes
0 answers
2k 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 ...
user avatar
6 votes
1 answer
379 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 ...
user avatar
6 votes
0 answers
96 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 ...
user avatar
  • 365
6 votes
0 answers
612 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 ...
user avatar
6 votes
1 answer
6k 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 ...
user avatar
6 votes
0 answers
699 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....
user avatar

1
2 3 4 5
130