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
6 votes
1 answer
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 ...
1 vote
1 answer
628 views

APEX testing a List variable

I am currently looking at more tests in Salesforce - I have made a new lightning app(just an expense application) and I am now just going through my controller and writing tests for it. I have been ...
0 votes
1 answer
636 views

Render as PDF not showing the file in proper format header/content/footer issue

I am having an issue with generating a pdf file with the following code. The issue I am facing is that I want the header to show on every page of the pdf and the content not to go out of bounds. Can ...
0 votes
1 answer
43 views

Test class for schedulable apex sending email with list of opportunities

Hi please help me write a test class for a schedulable apex class that sends an email to all users who have a checkbox on their user checked. //Send email to users where receive Grants email = TRUE ...
1 vote
1 answer
715 views

Get ActivityId From SingleEmailMessage

When sending a SingleEmailMessage from apex to a Contact, activities are automatically created for that Contact. I also want to log an activity on records that are related to this email. I can't use a ...
1 vote
1 answer
27 views

what are the components of the variable assignment log entry

on finest, my log entry looks like this: 09:30:19.490 (8458283328)|VARIABLE_ASSIGNMENT|[231]|this|{"c":"0x2980752a","tasks":"0x6e159af1"}|0x3de7ae9e It's a ...
1 vote
1 answer
47 views

JSON String Passed from LWC to Apex Becomes Null?

SOLVED BY Felix van Hove Issue: the parameter name of my Apex method did not match the name of the variable when I called the method in JavaScript. ORIGINAL QUESTION I've never touched frontend ...
3 votes
2 answers
1k views

Merge duplicate Contacts across different Accounts does not create AccountContactRelation

In cleaning up our database and using the new AccountContactRelation to allow a Contact to link to multiple Accounts, I need to merge all the duplicated Contacts into one Contact with ...
0 votes
0 answers
23 views

Is there a way to limit computer device login access through Transaction Security Policies?

I have a use case where a company wants to restrict salesforce login access to non-company computers. Can this be done using an Apex Transaction Security Policy?
-1 votes
0 answers
13 views

Can we update <apex:outputField value="" in VF page with data from email template which user receives through Visualforce trigger

Once user receives an email and click on link, Visualforce page will be display. Can we update the page content with content used in email. Each user will get unique details on page content.
-1 votes
0 answers
4 views

Can we update <apex:outputField value="" in VF page with data from email template which user receives through Visualforce trigger [duplicate]

Once user receives an email and click on link, Visualforce page will be display. Can we update the page content with content used in email. Each user will get unique details on page content.
3 votes
0 answers
64 views

Apex tests fail in Dev Console Test Suite but pass when run individually

Background There is a test utility class Class is marked as @isTest There are 5 methods Methods are not marked as @isTest because they have parameters All methods are static All methods call ...
0 votes
1 answer
24 views

Is Apex Callout chaining from Javascript controller using Async/await or Promise possible?

I need to make 5 callouts serially. I have written 5 different apex classes. I want to chain these callouts from JavaScript controller using Async/Await or Promises. Had anyone worked on such scenario?...
0 votes
1 answer
38 views

How to show results of map<> written in Apex from LWC JS and HTML

This is my Apex Class: public without sharing class VF_SurveyResponsePOC { public static Set<Id> setOfResponseId = new Set<Id>(); @AuraEnabled(Cacheable= true) public static ...
10 votes
3 answers
8k views

How can I upload/change user's profile image programatically or via API?

I know, that there is no way to mass-upload these images via dataloader as described here can I upload user's profile image via data loader https://success.salesforce.com/ideaView?id=...
-1 votes
1 answer
34 views

Day calculation is not correct

Why this code is not providing the exact day of the week? Date d = System.today(); Datetime dt = (DateTime)d; String dayOfWeek = dt.format('EEEE'); System.debug('Day:'+dayOfWeek); When I execute this,...
0 votes
2 answers
124 views

Upsert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION Invalid vote type '5-star(db=6,api=5)'

//This method is used to upsert an vote for article @AuraEnabled public static String upsertVote(Id voteId, String kbId, String val){ System.debug('voteId::'+voteId); System.debug('kbId::'+...
1 vote
1 answer
32 views

"Variable does not exist" error where variable is a class does exist

I have an Apex class OpportunityUpserter with a static method, where the static method makes a call to another static method in a class called IntegrationUtilities, as shown below. This gives me a ...
0 votes
1 answer
38 views

How to populate records into specific wrapper structure?

There is an external system, from which I need to pull (via REST request) information about, let's say, brands and their categories. After the request, I need to collect the data in such structure: ...
4 votes
1 answer
617 views

What mechanisms are available for firing Update triggers on Opportunity during a "Mass Transfer" action?

In this case the "Mass Transfer" action being performed is clicking the Change Owner link on the parent Account record which subsequently bulk-reassigns the child Opportunity owners and does not ...
0 votes
1 answer
38 views

How to assign the lead owner data to contact in a trigger?

I'm trying to create a trigger that creates an account and contact when the lead status is changed to a given value. The contact value needs to come from the Lead Owner User. How can I achieve that? ...
0 votes
0 answers
22 views

Community/Experience Profile User does not obey DMLOptions - triggerAutoResponseEmail = false

When running this code as a community user to create a case the Auto-Response email rule is being triggered Case myCase = new Case( AccountId = company.Id, ContactId = ...
0 votes
2 answers
894 views

How to reference history records from inner query

I'm trying to find field history information for a few fields that I'm querying inside a loop. This is what I'm doing : Set<String> setHistoryFields = new Set<String>{'ASIN__c','...
1 vote
0 answers
23 views

How to make a single column editable in Visual Force?

I am using visual force to show the parent and child at a single table. Now I want to make a child column editable. When I click on Class Notes Only the first row is editable but another row is not ...
-1 votes
0 answers
14 views

Script or any way to change all my org Profile session time out time in session settings

Is there any way to create a script to change sessions setting to over 60 profiles in my org? I need to change the session time out option in profile session settings for all profiles (over 60). If ...
1 vote
2 answers
36 views

Prepopulating company name in Lead object

I want to prepopulate the Company field in the Lead object. The idea here is that I don't want a Company Name in my Leads ie the Account object is not necessary for me. Now, as you know the company ...
-1 votes
0 answers
20 views

Duplicate object with same field

With this code , I successfully duplicate the object Template__c by creating a new one . I need to do the same thing for the object Template_Section__c . Using the same function , and I want to have ...
0 votes
0 answers
63 views

Omission Problem in Query Salesforce

When I execute this query List<AggregateResult> query = [ SELECT Max(Id) Id, AccountId, Max(CustomField__c) FROM Asset WHERE Status = 'X' AND (CustomField__c = 'Z' OR ...
-2 votes
0 answers
29 views

Constructor not defined: [GenerateGLpostingBatch].<Constructor>()

I'm trying to delete a trigger (a simple task) but for some reason, I keep receiving the following error no matter how I delete/amend the trigger. Constructor not defined: [GenerateGLpostingBatch].<...
0 votes
1 answer
156 views

SFDX test suite running issue

I've created my test suite and trying to run using sfdx command. this way, i'm getting error while running below command test file <?xml version="1.0" encoding="UTF-8"?> <...
0 votes
1 answer
44 views

Apex Class CallOut

I'd like to apologize in advance as I'm quite new to writing APEX Classes / Triggers. I've followed a tutoriel of which the aim is to POST a comment to an external system, in this case it's Jira. I ...
0 votes
1 answer
14 views

Run Trigger handler class in execute anonymous with old map newmap

Trigger createCbQuoteTriggerHandler.getOpps(Trigger.new,Trigger.oldMap); Handler class public static void CreateOpportunity(Map<Id,Opportunity> oldData, List<Opportunity> newData){ ...
-1 votes
0 answers
33 views

Write the following apex trigger [closed]

Anyone can help me to write following trigger: Find the first 2 contacts with the highest salary and update the name in a custom field separated by a “,”. Create a new custom text field on account ...
0 votes
2 answers
30 views

How to rewrite that ternary operator code to if-else?

I can't understand that part of the code - how to rewrite this to if-s and else? Especially the partthis.map1?.containsKey(custom_object__c?.workflow_status__c) List<custom_object_2__c> ...
0 votes
1 answer
29 views

Aggregate result not working in soql query

im new to visualforce and i have this problem: I have a sObject with customField1__c, customField2__c, customField3__c. In my main page (with a standard controller and an extension) i want to display ...
8 votes
2 answers
2k views

Get currently installed package version from Apex Class

In my managed package I have a Setup page that should only display setup steps relevant for the currently installed version of my package. I know in InstallHandler implementations there are way to ...
0 votes
0 answers
39 views

Is it right way to check CRUD Permission in LWC?

import { LightningElement, wire } from 'lwc'; import { getObjectInfo } from 'lightning/uiObjectInfoApi'; import ACCOUNT_OBJECT from '@salesforce/schema/Account'; export default class CheckPermission ...
0 votes
1 answer
1k views

Trouble getting multi-select filter checkbox to work on LWC datatable

I am currently trying to implement a filter menu dropdown with multi-select checkboxes. When a user checks two "groups" or more, the lightning datatable will display/filter only records from the ...
0 votes
1 answer
824 views

Calling a void apex method from LWC

I am currently stuck. All I have is a simple component that is supposed to submit the record for approval on button click. I am having trouble on load of the component ( it is being called as a ...
0 votes
0 answers
46 views

Apex Wrapper Metadata API Takes Time to Reflect the Change

I don't know if my question fits to ask here, but let me ask it anyway. I'm building a several features using Apex Wrapper Salesforce Metadata API: https://github.com/financialforcedev/apex-mdapi ...
21 votes
3 answers
7k views

How to clone an Object (NOT an SObject!) with apex?

Assume there is a custom class foo: class foo { // ... some member variables here } and an instance of it foo fooInstance1 = new foo(); how to make an independent copy fooInstance2 and not only ...
0 votes
1 answer
649 views

issue with userdata in test class for auto registration handler class

I have a test class which is as below @isTest private class KC_Reg_Handler_Test { static testMethod void testCreateAndUpdateUser() { KC_RegHandler handler = new KC_RegHandler (); ...
0 votes
0 answers
31 views

Calculate end date from supplied number of days [duplicate]

I am trying to calculate the end date when a user supplies the number of days. Issue is How do I take into account weekends and Holidays. I have code to calculate the number of business days when a ...
0 votes
1 answer
19 views

How do you identify OpportunityLineitems that span 12 consecutive months?

I'm trying to identify Opportunity products from the same Opportunity and the same product that spans 12 consecutive months based on start date/end date fields. I can easily tell if one line is 12 ...
-1 votes
0 answers
21 views

Execute trigger event if data is came from authorized app [duplicate]

I have created an apex trigger on behalf of client using rest API for an update event on case object. I want to execute this trigger only when the case is created using rest api through my connected ...
2 votes
1 answer
35 views

First Apex Test Class | FIELD_INTEGRITY_EXCEPTION

Struggling with building my first test class so I can deploy an Apex trigger. The trigger converts an Opportunity/Opportunity Products into a Sales Order/Order Items. Receiving the below error message:...
-1 votes
0 answers
25 views

Too many SOQL queries: 101 stack [closed]

I have a AccountTest class which run with more than 75% coverage in dev env. But when I tried same class in a another sandbox without any code change give this too many soql error. Can someone have ...
0 votes
1 answer
707 views

Get custom field in user object

In my object manage runder User I have a custom field named Business Type, in my apex class I want to retreive the current logged in users Business Type. It can only be Commerical Or Residential. I do:...
-1 votes
1 answer
32 views

Get all records created by user today

We are about to perform Load Testing and we are performing some complex scenarios. We use a CPQ tool that has many custom object records being involved and inserted. Is there an easy way to get ...
0 votes
0 answers
18 views

Implementation restriction: TopicAssignment

Using this within digital experience. Works when logged in, but not for non-signed in users. The APEX function: @AuraEnabled(cacheable=true) public static List<Knowledge__kav> searchByTopic(...

1
2 3 4 5
685