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
0
votes
1answer
16 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 ...
2
votes
1answer
22 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
1answer
19 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 ...
2
votes
1answer
44 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
19 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 ...
1
vote
2answers
66 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 ...
0
votes
2answers
21 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
0answers
16 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.?

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
16 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
39 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
0answers
13 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) ...
0
votes
2answers
33 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}&...
0
votes
0answers
28 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 :)
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
20 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
32 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 '...
0
votes
0answers
9 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?
1
vote
1answer
22 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
1answer
55 views

Any risk in recompiling all Apex classes in org?

Running into an issue with a deployment, getting a ton of errors of the following flavor: line -1, column -1: Dependent class is invalid and needs recompilation: Class MeansRegisterCustomerTest : ...
0
votes
0answers
25 views

Bulkify Apex Methods Using Collections In Methods warning in Checkmarx

We are facing Bulkify Apex Methods Using Collections In Methods error in few classes: We have a below code: public static void myMethod1(Id oppId, obj__c ob, List < customObject__c > cobj) { ......
0
votes
1answer
38 views

Upsert parent and child in single DML using there own ExternalIDs

I have a requirement to upsert parent records by External ID ExtParent__c field. And upsert child records by its External ID ExtChild__c field. For this, I used: upsert parentRecord ExtParent__c; //...
0
votes
2answers
46 views

Date formatting not working properly [duplicate]

I have my locale set at (GMT-05:00) Central Daylight Time (America/Chicago). And I am using the below Apex. DateTime d2 = System.Today() ; system.debug('date is '+d2); // date is 2021-04-10 00:00:00 ...
0
votes
1answer
43 views

Help with storing JSON data

I'm new to salesforce and I have to parse this JSON and store the values in variables. I have used json2apex which generated 2 classes for me. When I use system.debug I can see it's reading the JSON ...
0
votes
1answer
16 views

Disable VFP Command Button on Click

I currently have an issue where users are button mashing a custom VFP Lead convert page and converting a lead into multiple Accounts. Based on the direction of this POST I was able to partially ...
0
votes
1answer
40 views

How to change field permissions in a permission set or profile programmatically (APEX)

I've been testing out a component where one can programmatically create a field in the user object. It's being used to allow a user to check a few boxes that'll filter components in pages (using the ...
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
1answer
18 views

Navigation Operator for lookup field null check

I am trying to use Navigation Operator. But not getting how to use it for this situation. I want to do something like this if ( Account != null && Account.xyz__c != null && Account....
1
vote
1answer
29 views

Performance : Removing null from Set

From a performance view point which is better: Set<String> uniqueStrings = new Set<String>(); // Keep checking for null and then add to Set for (Integer i = 0; i < 100; i++) { if(...
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 ...
0
votes
0answers
19 views

How to sort columns in VF page, displaying fields from wrapper class

I have a VF page displaying a pageblocktable, and I need to be able to sort the columns (most importantly the "name" column. Can anybody assist. Here are the relevant snippets of code from ...
1
vote
0answers
10 views

AuthProvider Interaction Troubleshooting

In trying to talk with an auth provider to get a token response for a process I'm working on I'm running into issues with the redirect/callback portion of the communication after logging in to the ...
0
votes
0answers
20 views

Add createddate and file size to wrapper class of contentdocumentlink

I am working on a visualforce page that displays names of contentdocumentlinks, and as the page is currently, it shows 2 columns: numbers and names of the contentdocuments. I want to add a couple more ...
0
votes
1answer
31 views

Salesforce Trigger help

Hi I am trying to write a trigger on custom object Quote_Request__c - where I want to run the trigger when any field changes are performed on the Quote request records (except profile ids id1 or id2) ...
0
votes
1answer
20 views

Fill and Launch a FLOW from APEX after submitting a form from LWC

So instead of inserting directly using apex a new record of which the fields are being filled in a form by the user ! I want to do that using a FLOW, so I want to fill the FLOW by the form values and ...
0
votes
1answer
10 views

Pre populating fields (like Account) from URL constructed in Apex - Parameters not working (Lightning)

We have an intermediary VF page that lets users select certain values to auto fill the new record form for an object. When a user clicks Continue on our page, they are taken to the standard Salesforce ...
0
votes
0answers
15 views

deserialize response from Google Contacts API [duplicate]

I Created a google contact from apex trigger by using API. Now I need to access the id of created google contact (from the response ). Can anyone please help me . I am finding it very difficult to ...
0
votes
0answers
10 views

Customer wants to talk to a particular agent (Einstein Bot, Transfer to Agent Option)

We have implemented einstein bot for our customers. In transfer to agent option, we want our customers to type the agent name and the chat should go to this particular agent. What we have tried: We ...
0
votes
0answers
15 views

How to scan QR Code in a PDF file? [closed]

I need to scan a QR code in a PDF file, which is stored as Attachment. This code can be anywhere in the document, position is not fixed. Document contains other information in text, and just one QR ...
0
votes
2answers
29 views

Why should we use Queueable apex when we can perform chaining of batches in batch apex (when we can call another batch in the finish method)

We can call another batch from the finish method of one batch, then why do we need Queueable apex
0
votes
1answer
29 views

Insert Contact into Case - Lookup(Contact) with APEX

I have created a simple form that creates a new record in a Case when submitted. I can populate the text/String fields ok but the "Contact" field is giving me trouble because it is a Lookup(...
0
votes
1answer
19 views

value from javascript-controller to be used as global variable in apex controller

i want to pass a string from my javascript-controller to apex controller so that it can be used as a global variable(string) in Apex controller below is the code {.....user is selecting a group name ...
0
votes
1answer
24 views

Apex Code for Campaign Member List

I've been struggling with creating code (I am not a developer) for a VP where all Campaign Members with certain fields completed (CampaignMember.Article_Link__c) are displayed in a table. The goal is ...
-1
votes
1answer
46 views

Error Non static method cannot be referenced from a static context

Test class: @isTest private with sharing class Genereratortest { @TestSetup static void createPayloadtest() { List<_Site__c> studySites = new List<_Study_Site__c>{ ...
0
votes
1answer
15 views

conversion of JS button to Lightning salesforce

I have a JS button, which is calling a web service class method and doing some process. I am trying to convert that to call a VF page and make it lightning compatible. But I am stuck on an error while ...
0
votes
1answer
19 views

Test with QuoteLineItem insert fails in some sandboxes but not all with REQUIRED_FIELD_MISSING UnitPrice error

I have a test class with setup method which creates an account, opportunity, quote. Then the test method retrieves the quote and sets up a QuoteLineItem . The insert of this QuoteLineItem fails with a ...
0
votes
0answers
9 views

Delete call recording and call transcript without deleting voice call record in Service Cloud Voice

We are using Service Cloud voice. We have a requirement to delete call recording and call transcript without deleting voice call record. From initial investigation, the findings are we cannot query ...
1
vote
1answer
46 views

Custom Metadata types not supported in Apex Classes?

I'm using a Custom Metadata type to hold the counter for a round robin. The following code provokes an error: Account_Managers_List__mdt AMList = Account_Managers_List__mdt.getInstance('...
0
votes
1answer
33 views

Opportunity LineItems is deleted when trying to sync quote

I am adding an Opportunity Line Item within my Apex code. When I create a Quote, I would like that quote to sync automatically and use the Opportunity Line Item and copy it in the Quote Line Item. I ...
1
vote
1answer
21 views

Issue with Salesforce API version(Allowing to give wrong API version in package.xml)

I was doing one of the trailhead modules Package.Xml and one of the steps to retrieve metadata from org. When I gave the wrong API version(60.0), I was able to extract the data from salesforce. Is ...

1
2 3 4 5
636