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
0 answers
23 views

DML Exception not being caught

ClassA { Method1() { Method2(); } Method2() { ClassB.Method3(); } } ClassB { Method3() { //Failing DML Operation } } How come I can only ...
user avatar
  • 1
1 vote
1 answer
43 views

Relating Child<->Parent records using External Id is throwing DML Error

I am following this post to related parent child objects. Please review below code which I am testing but getting a DML error. I could not figure out the mistake I am doing. Any guidance will be ...
user avatar
  • 35
1 vote
0 answers
18 views

How to open and close a visualForce page with ba related list?

So I am trying to create a VF page where it will be easy to manage multiples records of a related list at a time. My problems are: I don't know how to launch the page from a new button on the related ...
user avatar
  • 23
-1 votes
0 answers
18 views

Auto Response Emails, date time format change

can anyone please explain me about the scenarios mentioned down below: I am trying to trigger the auto response emails between 12-4pm on a particular day. Date & time format needs to change from ...
user avatar
-3 votes
1 answer
34 views

I have text field on lightning web component but I want user to be allowed to put only numbers, please help [closed]

I have one field on lightning component which is text field but I want user to be allowed to put only number and incase of text it will throw error. Please help
user avatar
  • 1
0 votes
1 answer
17 views

How to get Test Coverage on a Simple Wrapper Class

I'm trying to get a test class to cover a few wrapper classes I've created in Apex, but for some reason one of the wrapper classes doesn't gain coverage (0%) like the other one does (70%). I read in a ...
user avatar
0 votes
1 answer
23 views

How to set StatusCode on Test.setMock [duplicate]

I have a simple class that just calls the generic HTTPCallOUt method for its test class. I want it to be able to fail in order to catch all the code. Here is my code: Test.startTest(); Test....
user avatar
0 votes
2 answers
43 views

Strange String behavior in Apex

I have old code where VF page is doing URL redirection with appending query params in URL. like URL="https://UatTest.com?target=FGI" - this is from label then we are appending params with ...
user avatar
  • 1,277
0 votes
1 answer
22 views

Evalution criteria in record-triggered flows vs apex trigger

Due to some performance issues, I plan to migrate the Record-Triggered flows to the Apex trigger code. I wrote all the criteria logic and updated the records in the Before Insert and BeforeUpdate ...
user avatar
  • 233
0 votes
0 answers
41 views

How to make specific range search filters in lwc & apex?

I'm a freshman who just started developing apex and lwc. I'm developing a search filter.The hard part is this. After searching for a number, it is a logic that allows all values within the error range ...
user avatar
1 vote
1 answer
22 views

Test Method Issue for removing duplicates from List

I have a requirement to remove the duplicate objects from a list at several places in my integration code and I have developed a method in the Util class to remove the duplicate objects from the list. ...
user avatar
0 votes
1 answer
39 views

Conditionally displaying multiple Lightning Datatables

I have an issue as i want to be able to conditionally create a a new Lightning Datatable based off an selection on another datatable. to break it down. i have a datatable on account with related ...
user avatar
0 votes
1 answer
22 views

Get Data of Sobject dynamically

I'm trying to get a field value of a Sobject. for example for Case. String cas = 'Case'; String caseid = '5003O000008QNUOQA4'; String query = 'SELECT Id,RecordTypeId,Answer_Type__c FROM ' + cas+ ' ...
user avatar
  • 963
-4 votes
1 answer
71 views

System.LimitException: Too many Email Invocations: 11 - Line: 63, Column: 1

Could Not find proper solution for this Fatal Error. I have to send single single mail project wise. global class CollectionDefaulterEmail2 implements Schedulable { global void execute(...
user avatar
  • 1
0 votes
1 answer
43 views

How to add lightning toggle button lightining:buttonStateful in lwc component js file

I have a search page that searches the records and displays in table.I am trying to use lightning:buttonStateful in LWC js file to display a toggle button (follow/unfollow) in the column. But it is ...
user avatar
  • 29
-1 votes
0 answers
39 views

too many soql queries: 101 error

I am trying to complete the Understand Execution Context trailhead and getting the too many soql queries: 101 error, it works fine when the test limit is 100, but doesn't work when it is 200. below is ...
user avatar
-4 votes
1 answer
45 views

Apex passing parameters to Batch job during scheduling [closed]

I need to pass the query to the batch class while scheduling it. How could i send the query as a parameter from the schedule class to batch class?
user avatar
0 votes
0 answers
23 views

Need help with code coverage for trigger and for loop [duplicate]

I'm new to Salesforce unit tests and am stuck on how to get coverage for the for loop below. The trigger inserts requirements based on their contact record type and which department they are in. I'd ...
user avatar
  • 1
0 votes
0 answers
37 views

How to get 100% test coverage for an apex trigger associated with an asynchronous callout?

I am looking for assistance on why 'zipCodeTimeZone.makeCallout(objLead.Id)' in both places on the trigger is not being covered/triggered by my test method while it is providing 100% coverage for the ...
user avatar
  • 1
0 votes
0 answers
13 views

test class coverage for User EscalationManager(string QueueName) [duplicate]

Public static User EscalationManager(string QueueName){ system.debug('@@@@@@@ QueueName '+ QueueName); User groupMember = new User(); if(checkRecursive.runOnce()){ Set<Id> ...
user avatar
0 votes
0 answers
37 views

Modifications to be made in an apex class of an lwc component(clone a component and place it in another object)

I have created an apex class and it is working perfectly. Now I have to make some modifications in the apex class. Apex Class: public with sharing class ComponentTable { @AuraEnabled(cacheable=...
user avatar
  • 47
0 votes
0 answers
31 views

System.UserManagement.initSelfRegistration​ does not exist [closed]

I'm trying to use the method initSelfRegistration for self-registration on my custom page, but I'm getting that error: "Method does not exist or incorrect signature: void initSelfRegistration​(...
user avatar
  • 1
0 votes
1 answer
22 views

Any way to find the deleted workflow rules?

I was helping my company to mass update CASE records in one of our sandboxes. In order to expedite the process, I deactived all its workflow rules (object Case) before the update. After the update is ...
user avatar
  • 11
0 votes
0 answers
47 views

Inserting Content Notes as Experience(Community) user in test class fails

Getting an error trying to insert a ContentNote in a test class as a community user: insert new ContentNote(Title = 'Cancellation evidence', Content = Blob.valueOf(body)); ...
user avatar
0 votes
2 answers
45 views

Change the format of all Contacts phone numbers to 1234567891

Some of the phone numbers of Contacts are formatted as (123) 456-7891 I need to change the format of all phone numbers to 1234567891. I don't want to create another formula field that contains the ...
user avatar
  • 37
3 votes
1 answer
47 views

File corrupted on sending data to create file via workbench using REST API

I am trying to create a file in in salesforce via workbench. The file is getting created although the file is corrupted. I feel there is some issue in binary data. What I am doing to get the binary ...
user avatar
  • 51
0 votes
1 answer
42 views

Unable to update my contact records

I have written a trigger to update the contact's individual balance field depending on the number of contacts associated with the account but I am unable to view it on the UI trigger ContactTrigger on ...
user avatar
  • 53
0 votes
2 answers
59 views

Trigger for Case's Subject but change of Owner To Queue Not happening

At a conceptual level, below is what Trigger code is doing Query for Salesforce queue name Prepaid Iterate over the Email 2 Case records for Record Type as "Executive Response " I get (...
user avatar
0 votes
0 answers
41 views

Implementing autocomplete suggestion for record ids

The LWC app that I am currently working on has a feature that lets users fetch information for a record whose record ID is entered. I am looking forward to implementing a feature that proactively ...
user avatar
0 votes
1 answer
29 views

Add Opportunity Contact role from account contacts

I have a requirement to creates an opportunity contact role record whenever an opportunity is created. The records should be created from the account's related contacts. I have written the following ...
user avatar
  • 53
0 votes
1 answer
36 views

How can I optimize the code below?

Problem statement: I need to prevent the user from creating more than 10 Opportunities per month. public static void createOpportunity(List<Opportunity> newOpportunityList){ for(...
user avatar
0 votes
2 answers
34 views

unable to lock rows when mass deleting

I am helping my company to delete millions of records from object 'Case' in one of our sandboxes. Now matter how big or small the batch size I set, i always receive the 'unable to lock row' error. ...
user avatar
  • 11
1 vote
1 answer
15 views

EventRelations not showing up on Event with multiple attendees

So I have a piece of code that takes contactIds and creates EventRelations for an event during a piece of Apex code. //looping through each contact EventRelation er = new EventRelation(); er.EventId = ...
user avatar
  • 11
0 votes
1 answer
17 views

reference a VisualForce component attribute to use in itself

I would like to know how to get an attribute of a component in a visualForce code. In this code, wrappers is a map and I would like to put the value of the pageBlocktable to a List which is contained ...
user avatar
  • 23
0 votes
1 answer
34 views

Update Custom Metadata Type Record

I have a controller that updates/creates metadata type records. It works fine for the creation of new records, but when I try to update existing records, I get this error duplicate value found: ...
user avatar
  • 1
0 votes
0 answers
30 views

How to Find Debug Logs in Apex Test Class

Hey there this is my first Apex code and I'm having trouble finding my debug logs. Heres my Trigger and Test Class First, then below I'll try and explain all that I've tried so far. trigger ...
user avatar
0 votes
1 answer
52 views

Is Apex Code Consolidated per object the best way?

Our vendor has consolidated apex per object, however, when they added new apex code for us under a specific object - it is now throwing an error (exceeded CPU limit). When looking at this code, is ...
user avatar
0 votes
0 answers
17 views

Clone value using lightning dual Listbox

I need some help please . What I want from this code is that once the button is clicked Clone, we clone the name of the template, and generate Template Name Id which is concatination between the name ...
user avatar
-1 votes
1 answer
41 views

Can someone explain me the difference between these two queries [Select a.Name From account a] and [Select Name From account ]

Why do we need to create instance of an object in an query and what difference does it make from normal query. I tried running these query and couldn't notice a difference I was going through some old ...
user avatar
0 votes
0 answers
20 views

Hide action (custom button) after use it

Hi everybody I have a detail page of X custom object that has a custom button (Action that display a Flow that has a LWC form). This button creates a record of Y custom object. I want that after the ...
user avatar
0 votes
0 answers
29 views

Custom Lightning Page Template Component not able to find apex method

Hi when I tried to cal the apex method from the Custom Lightning Page Template Component it is a throwing error. .cmp <aura:component implements="lightning:recordHomeTemplate" controller= ...
user avatar
0 votes
1 answer
78 views

Count the number of child records on the each parent record

I'm stuck here and not sure why this code is not working. I want to throw error if the child record (Contact)is more than 5 records per Parent record (Account) Question: I want to restrict the user to ...
user avatar
  • 6,614
0 votes
1 answer
25 views

Test Class Error for Apex Class meant to filter Quote Lines on a VF Email Template

I'm just starting out with Apex, really any SF development. I've been lucky enough to be able to learn and practice what I've been learning in real-life scenarios, but I've depleted my googling skills ...
user avatar
  • 5
0 votes
1 answer
39 views

Show popup with confirmation button using addMessage and commandlink

I have a requirement where I have to create a popup (using addMessage) that display two options: confirm and cancel, each of these options has an action. I already tried passing a command link in the ...
user avatar
0 votes
1 answer
43 views

Future Callout and Invocable Apex

I have an invocable apex method that calls to a future (callout=true) method. The callout returns a response that needs to be returned to the front end. I am stuck because I can't return a value from ...
user avatar
  • 3,179
0 votes
0 answers
36 views

Avoid query inside for in Trigger

Hi I am new at Salesforce I did a LWC form that creates a record. Some fields of this record can´t be filled by the user so I did a Trigger for the custom object that creates this record. The problem ...
user avatar
0 votes
1 answer
25 views

To disable an apex trigger from managed package

I am helping the release engineering to team to update the records in one of our sfdc sandbox environment. However, for a object named 'case', no matter how small the bulk batch size I set, I always ...
user avatar
  • 11
0 votes
1 answer
67 views

batch class to update the field after record insertion

I have one custom object(Import__c) where I am dumping all the records through data loader and runs a batch class to query the Import__c object and create respective records in another object (...
user avatar
0 votes
0 answers
25 views

Compose a multipart/mixed HTTP request [duplicate]

How do I set the request body of a POST request in Apex in the raw format. Below is the sample raw body that I am trying to set, --foo_bar Content-Type: application/http GET /gmail/v1/users/test@gmail....
user avatar
-1 votes
1 answer
28 views

Validation rule to prevent change if Status has specific value but let change status

I have a situation where I want to prevent some Profiles from changing any value of field after certain status but I can change the status no other fields values. i.e. I have status as picklist values:...
user avatar

1
3 4
5
6 7
686