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,163 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
24
votes
2answers
498 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 ...
17
votes
1answer
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="...
16
votes
0answers
890 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 ...
13
votes
0answers
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: ...
11
votes
0answers
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 ...
11
votes
1answer
613 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
217 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
1answer
68 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 ...
9
votes
0answers
333 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 ...
9
votes
2answers
452 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
121 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
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 '&...
9
votes
1answer
190 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
282 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
460 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 , ...
8
votes
0answers
357 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
122 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
485 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
0answers
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 ...
8
votes
1answer
564 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
0answers
196 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 ...
8
votes
1answer
166 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
2answers
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() {}...
7
votes
0answers
279 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. ...
7
votes
0answers
529 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: ...
7
votes
0answers
751 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 ...
7
votes
0answers
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 ...
7
votes
0answers
1k views

How to debug Post-Install script?

We don't get much information on email received by subscriber if Post-install script fails. Problem: Unexpected Error The package installation failed. Please provide the following ...
7
votes
0answers
607 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
1answer
408 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. ...
7
votes
0answers
840 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 ...
7
votes
1answer
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 ...
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
584 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
398 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 ...
6
votes
0answers
4k 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 ...
6
votes
0answers
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 ...
6
votes
1answer
310 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
79 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 ...
6
votes
0answers
467 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
1answer
5k 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 ...
6
votes
0answers
651 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
124 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
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 ...
6
votes
0answers
1k views

Site.getBaseUrl returns empty string in test method

I'm writing tests for the community site controller class and I've faced with some problem. When I invoke a controller method that includes Site.getBaseUrl() from test method I get an empty string. I ...
6
votes
2answers
1k views

How to Reproduce the Concurrent Requests Limit?

I'm trying to write code that will reproduce the Concurrent Requests limit (10 requests longer than 5 seconds, described here: https://developer.salesforce.com/blogs/engineering/2013/05/force-com-...
6
votes
1answer
430 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
53 views

Error when using FIELDS(STANDARD) in an Apex SOQL query : System.QueryException: No such column 'EffectiveDate' on entity 'Quote'

I recently implemented the new FIELDS(STANDARD) functionality in Apex queries and I am using the following query now: SELECT FIELDS(STANDARD), Custom1__c, ... , CustomN__c FROM Quote WHERE Id =: ...
5
votes
0answers
81 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 ...
5
votes
0answers
136 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, ...

1
2 3 4 5
124