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.

Filter by
Sorted by
Tagged with
-2
votes
1answer
15 views

Stop displaying “Maximum view state size limit (170KB) exceeded”

i have a VF page in which users can upload files. The issue i'm encountering is if the file is a certain size (Which is a relatively small size), the user is shown a screen that says " Maximum ...
0
votes
0answers
4 views

Folder structure in Notes & Attachments

We will use "Notes and Attachments" in Opportunity record to upload some documents. Those documents are related to Electricity supplies (e.g. Id card, last copy of bill etc). Is there a &...
8
votes
2answers
8k views

How do I access Custom Settings in Apex?

If I have a hierarchical custom setting: Custom_Page__c With one field: Url__c Using apex, how can I surface this field in a visualforce page? Can I just query it as if I was querying a custom ...
1
vote
0answers
27 views

Just In Time controller showing User.surname and User.FirstName all null

I have written Just in Time (JIT) controller to handle JIT scenarios. Azure is passing the Identity provider details. But in salesforce, all values like below showing null, despite those are in the ...
0
votes
2answers
39 views

I want to insert multiple Account Records with visualforce but i am getting error(Formula Expression is required on the action attributes.)

//My visualforce page code <apex:page controller="AddMulAccountContr" > <apex:form > <apex:pageblock > <apex:pageblockTable value="{! listaccount}&...
1
vote
0answers
18 views

Trigger with callout not updating a field on Case object

I have a future callout which is triggered after case creation/update. The callout sends a request to my backend to create a resource there, then, it returns the resource ID, and it should ideally add ...
0
votes
3answers
8k views

How do I send report results to non Salesforce users by email?

I am trying to automate a report by scheduling the report to run at a date/time and emailing the results to mail group. How do I send report results to mail group? Apparently via the standard ...
-1
votes
0answers
16 views

Automated email pdf attachment created using visualforce

I want to send automated email every month to Primary_Contact_Email__c and attach visualforce renderas pdf file in it, which is taking dynamic values from my controller extension apex class. Right now ...
2
votes
1answer
328 views

What is the correct way to return validation errors from a lightning Apex controller?

What is the correct approach to return validation errors from lightning controller? Suppose we have an aura method that takes some parameters. We need to validate these parameters in order to make ...
0
votes
0answers
16 views

Trigger on account object to create contact related to Two fields [closed]

So there are three fields on Account object, 1. Contact details 2. Move to contact, (Both long text area) 3. Move To Account ( Lookup to Account) Now when we enter value in Contact details fields for ...
0
votes
0answers
9 views

How to access and set login hours programatically for a given profile

We have a requirement to set the login hours programatically via apex for some profiles. Any idea how to set the same ?
1
vote
1answer
40 views

Uploading files to the wrong related list

I am trying to upload files to one record while displaying the CombinedAttachments related lists for multiple records. No matter which related list I use to upload files, they always get attached to ...
0
votes
1answer
25 views

update records in APEX from a list of record

I have a component where, when the user click on Save it fires an apex class that is supposed to update the records The way it work is that onClick on save it creates a list of dict with the relevant ...
1
vote
2answers
3k views

QuoteLineItem test class

I need to create test class for quote and quotelineitem, but i still get error message like this "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, ...
0
votes
1answer
21 views

How to write test class for metadata which is dependent on post deployment steps?

We have a functionality in our managed package which is dependent on Knowledge__kav. So we have an object Test which has a lookup on Knowledge object. And a custom permission CS1 which is given to ...
5
votes
1answer
93 views

Queueable apex runs in System admin mode even after written in System.runAs mode

Queueable class from Test context runs in test runner mode and not in System.runAs user. This is strange behaviour. Here is the snippet. Any idea? User internalUser = // Created Internal User with ...
0
votes
0answers
19 views

Detect password change via APEX

I'm using the SF Service Cloud for handling customer queries. I'd like to detect password changes in apex (possibly via a trigger) so that I'm able to send out a follow-up response to the user about ...
2
votes
1answer
59 views

Insert with Throw Exception

In the code below: try { //code here } catch (Exception e) { Account a = new Account; insert a; Throw new Exception ('test') } Apparently on Platform Event objects, executing the command: ...
0
votes
0answers
20 views

How to change FileName in Trigger | APEX

I have a custom object that gets created via a Flow, in that Custom Object I have a 'Type' and if Type is "A" then it allows users to UploadFiles, these files then end up in Related Files. I ...
0
votes
2answers
30 views

How can I update a record with information obtained from a @future callout?

I have a trigger which executes a callout on the Case object to create a resource in my backend. The callout returns the ID of the created resource, which should then be added to the Case the trigger ...
0
votes
1answer
213 views

Sync LastLoginDate from User object to Contact object (Community Portals)

Using this as a reference: https://developer.salesforce.com/page/Synchronizing_Portal_Users_with_Contact_Record_Data I am trying to sync the date in the LastLoginDate field on the user object with a ...
1
vote
2answers
68 views

Are there any risks/issues using a List's hashCode as key for caching results?

I'm considering using a combination of static variables and the List object's hashCode method to cache the results of a SOQL call based on the values being passed in (accountIds). The methods will be ...
4
votes
4answers
2k views

convert hex value to integer

I am working on a method defined in a class that controls the lead object. The desired end result is to produce a unique number for each Lead record. I currently have this working, but the out put is ...
0
votes
0answers
20 views

How to execute a method after an apex rest callout is finished

I'm executing a rest callout in apex to create a new field. I'd like to execute a method that adds that field to a permission set to allow users to use it, right after this callout is finished. Is ...
0
votes
0answers
7 views

partial collapsing of groups in full-calender.? [closed]

We are using fullcalender- Timeline View with multiple parent resources and related childs. I'm trying to implement a feature whenever the view loads , I want to collapse all parent resources except ...
0
votes
0answers
18 views

What are possible side effects of “Compile all classes” in production? [duplicate]

When I validate a change set with RunLocalTests in production (as well as using the CLI with that flag for CI/CD and packaging integration) there was a class that was erroring out as a dependency. I'...
0
votes
1answer
41 views

Apex trigger to prevent duplicate account on creation

I have written the following class for preventing an Account with the same name to get created in the org. The issue with the trigger is that it is not allowing the record to be saved but the error ...
0
votes
1answer
23 views

Security with Mixed SObjects

I am attempting to find best practices around mixed SObject security. When I am using DML statements I validate either through "with SECURITY_ENFORCED" or through {SObject}.SObjectType....
0
votes
0answers
15 views

create asset record when order record is created [closed]

When an Order is created AND there is a Order Product where the Product Family = “Software”, an Asset record will be created for the OrderProduct.Quantity (e.g. Quantity = 8, 8 Asset Records created) ...
32
votes
3answers
5k views

Why is Schema.describeSObjects(types) Slower Than Schema.getGlobalDescribe()?

I was about to reconfigure some of my code to use the newer Schema.describeSObjects(types) method that I had heard was faster than using a globalDescribe. I made some code to quickly check this and ...
0
votes
2answers
167 views

Encoding and Decoding BLOB due to error 'BLOB is not a valid UTF-8 string'

I try to encode and decode a BLOB in order to avoid the 'BLOB is not valid UTF-8 string' error, but when I encode the BLOB in UTF-8, decode it again and use the .toString-method, I stil get the error. ...
2
votes
2answers
332 views

A simple try for deploying gets an “An internal server error” from the production

I have installed and configured the Ubuntu 20.04 and Visual Studio Code. It is connected to the my org. But a simple deploying in the production I gets "An internal server error". Sometimes ...
3
votes
1answer
693 views

Remote Action Issues

Below is my Apex and JS code for my remote action. When I try to run this code I get an error message that says 'Unable to invoke action 'CheckOutLoadingDock.saveNewOrder': no controller and/or ...
0
votes
0answers
29 views

Apex: How to automate page layout assignments using Apex [closed]

I would need help in automating page layout assignment using Apex. Please help guys :)
3
votes
2answers
2k views

Formula using INCLUDES function - how to reference merge field?

I need help creating this formula field. I am getting this error: 'Incorrect parameter type for function 'TEXT()'. Expected Number, Date, DateTime, Picklist, received Text (Related field: Formula)' ...
0
votes
2answers
713 views

Salesforce SelectOption and For loop problem…Class and Controller

VF Page Updated to complete product 04/17/2017 <apex:page standardController="Position__c" extensions="Editpositions"> <apex:sectionHeader title="{!Position__c.Name}" subtitle="Edit ...
1
vote
0answers
7 views

Getting available time slots in Lightning Scheduler

When creating a Service Appointment in Lightning Scheduler there is no standard validation to prevent from booking a Service Resource multiple times during the same time slot. How can we get available ...
0
votes
0answers
22 views

how do i find # of days in each month in a date range

I have 2 date fields: Date From and Date To (e.g. Date From = 04/11/2021; Date To = 06/15/2021. I need to find the number of days in each month by month (e.g. there are 19 days in April, 31 days in ...
1
vote
1answer
23 views

Parsing map to get list of objects based on Key

Is there an easy way to extract the list of objects from a map containing list of objects? For ex, below is an example map that I need to deal with. map<Id, List<Contact>> ...
1
vote
3answers
2k views

Is there a way to conveniently preview a Visual Force Page in VS Code?

So I'm trying to switch my IDE from the Developer Console to VS Code. But the thing is that the changes we make to a lightning component or a vf page in the dev console reflect in seconds on the app ...
1
vote
1answer
34 views

LWC variable not defined

I am creating a LWC data table and I would like that when the user click on "Edit Table" The fields in the table will get the inline edit true import { LightningElement, wire, api } from '...
4
votes
1answer
1k views

Why can't I Insert ContentDocumentLink linking to Community user?

I have written a trigger class on content document link to create a task whenever a community user creates a task on a case. Currently, the trigger works perfectly when attaching a case through the UI,...
1
vote
1answer
496 views

Example usage of ConnectApi.ClientInfo?

I'm trying to put together a FeedItem trigger that has slightly different behavior if the chatter post comes from a particular Connected App. My understanding is that the ConnectedApi includes a ...
0
votes
0answers
10 views

How to get ConnectApi ManagedContent by folder name in apex?

I can get cms ConnectApi.​ManagedContent​Version by topic, content id, content key, content type. But is it possible to get contents by folder name?
0
votes
2answers
457 views

Dependent picklist error: “Validation Error: Value is not valid”

I have a table, where each Wrapper instance corresponds to each row of the table. On select of Project - tasks of selected project should be rendered. If i'm trying to pick task and add a new row VF ...
1
vote
1answer
978 views

show error message after delay in lightning

Here is the situation. I have a @Future method which has callouts is running along side of actual main CLASS. in the callout response, I am receiving some error/success XML, I am saving them in a ...
0
votes
1answer
695 views

Trigger to Prevent more than one Child record as primary under Parent record

We have a parent object 'Object_x' that may have multiple child records 'Object_y' and they are associated with lookup relation.We had a field called 'Primary' on 'Object_y' to mark it as a primary....
3
votes
1answer
1k views

Webservice callout - Test class - not working

I have batch class that makes a HTTP callout to a remote web service. To deploy into production, I have created a test class with StaticResourceCalloutMock. I am executing the test class in a full ...
5
votes
2answers
264 views

System.assert() in production code? (vs. custom exception)

It's come to my attention that you can use System.assert(), System.assertEquals(), etc. outside of test classes in Apex. I've seen a lot of custom Exception classes written that do nothing but extend ...
0
votes
2answers
2k views

Recall Approval Process From Apex for non-admin profile

I have a business Requirement, where i have to provide an option for some users to recall the approval process. To my understanding I have created a button on Object. On click of this button I'm ...

1
2 3 4 5
636