Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

15
votes
0answers
149 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 ...
14
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="...
11
votes
0answers
988 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: ...
10
votes
0answers
181 views

toLabel in @AuraEnabled Apex Lightning controller

The SOQL toLabel function doesn't work in my @AuraEnabled method when called from a Lightning component. UserInfo.getLanguage returns "fi" (for Finnish) but the Record Type Name field that's supposed ...
9
votes
0answers
690 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 '&...
8
votes
0answers
79 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 ...
8
votes
0answers
71 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
232 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
163 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
249 views

Recreating the Event Notification Email

Is there a way to determine what the aid parameter is for a given event relation record? We would like to add Invitee's to events and send a custom email notification to them allowing for the ...
7
votes
0answers
150 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
540 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 ...
7
votes
0answers
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() {}...
6
votes
0answers
33 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 ...
6
votes
0answers
248 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
0answers
227 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 ...
6
votes
0answers
60 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
190 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
2k 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
575 views

Apex equivalent of REST api's nextRecordsUrl

When you run a query through the REST api and the number of records returned exceeds the default 2000, or the batch size set in the Sforce-Query-Options header, the query will return a nextRecordsUrl ...
6
votes
0answers
358 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
72 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
0answers
390 views

How to retrieve connected app using metada API?

I have created connected App using metadata API,Now I have to retrieve connected App's Information using metadata API,The code is working fine for the Apps which is created manually but not for the ...
6
votes
0answers
951 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 ...
5
votes
0answers
207 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
79 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
0answers
369 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 ...
5
votes
0answers
126 views

Is User Interface API accessible via JS from a Helper of a Lightning Component?

Can we use the UI API in Lightning Components directly from within a Helper JS? https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_get_started.htm I've just read the docs and ...
5
votes
0answers
170 views

Recalculating Apex Managed Sharing

I am studying "Apex Managed Sharing" but I have a problem with "Recalculating Apex Managed Sharing". The Apex Developer Guide says: Every time a custom object's organization-wide sharing default ...
5
votes
0answers
39 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 ...
5
votes
0answers
155 views

Possible to create a generic “invocable class” per object?

My organization is starting to feel some pain around using Process Builder + Flow (error handling mostly, but also inherent Flow inefficiencies and the inability to run Flow in system context). Thus, ...
5
votes
0answers
77 views

record.clone().clone() instead of .clone()?

We are using Andrew Fawcett's SObjectDataloader Library where I fixed a couple things and stumbled over odd behavior that I couldn't find valid explanation for. So in the Library, records are ...
5
votes
0answers
288 views

How to run a macro using apex class?

How can I run a macro using apex class? I have used a Visualforce Page to run the macro with standard method "sforce.console.runmacro" in javascript. Similarly, I need to call it in an apex class ...
5
votes
0answers
323 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 ...
5
votes
0answers
157 views

Working with Very Large SOQL Queries

Background This is a question about your experiences managing huge amount of data for UIs. With an ERD like this, where the arrow directions reflect the fields lookup directions. (e.g. entity "B" ...
5
votes
0answers
231 views

Hitting error when trying to save HTML5 canvas in VisualForce Page

We have a requirement to open an image attachment in a VisualForce page, the user should be able to draw on the image and those edits should be updated in the attachment on save. So to achieve this, ...
5
votes
0answers
206 views

Dynamic trigger creation from managed package

I have a requirement to create triggers dynamically after a managed package is installed. I have read that the tooling API can be used to create triggers dynamically however it cannot be used in ...
5
votes
0answers
468 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 ...
5
votes
0answers
215 views

question on crontrigger and possible state values

Whenever a scheduled Apex Job is submitted, an entry is made in the CronTrigger table. What I see is, when this job is completed successfully, I see the State changed to "DELETED". Based on the SOAP ...
5
votes
0answers
350 views

How do I create a User without asking them to set their password?

I'm developing a new integration between SFDC and an external system. Almost everything is working fine, but I'm facing some issues when creating a new user. For now, the main problem is when I ...
5
votes
0answers
140 views

Postinstallscript fails to insert child records

I have a post install script that executes after the package has been installed and it worked perfectly. But recently it had to be changed to include some dummy data as an example. So I added the code ...
5
votes
0answers
532 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 ...
5
votes
0answers
637 views

Amazon SES Sending email with attachments

I am trying to send emails for salesforce with attachments HttpRequest httpReq = new HttpRequest(); httpReq.setMethod('POST'); httpReq.setEndpoint('https://email.us-east-1.amazonaws.com');...
5
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 ...
5
votes
0answers
247 views

JSON.serialize alternative which support more objects like HttpRequest or Schema Describes

Often I need a easy and robust way to convert huge nested data structures into an string. Mostly for dumps, logs and debug. JSON.serializePretty() comes close but does not support all Object types ...
4
votes
0answers
76 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....
4
votes
0answers
43 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 ...
4
votes
0answers
40 views

Visualforce page not displaying correct Devnagiri words when it render as pdf

I am using Arial Unicode MS font in the visual force page. I need to render it as pdf. The HTML contains Devanagari words. HTML is displayed properly but the words are broken in the generated pdf. e.g ...
4
votes
0answers
36 views

How does one get the active app in Lightning?

In Classic, one can use code like this to determine the app the current user is currently working in public static String getActiveTab(){ String tabLabel; for(Schema.DescribeTabSetResult i : ...