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
1
vote
1answer
15 views

Same SObject Upsert Parent Lookup record using an external Id

Following this document - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_foreign_keys.htm But I'm trying to create a Parent and child records from the same ...
0
votes
1answer
25 views

Analysis for SFDX Apex || sonarqube Community Edition

Is there a way to support SFDX Apex Analysis with sonarqube Community Edition version 7.2 or above. If not then is there any previous Community version which may support it ? Many thanks in advance.
1
vote
1answer
31 views

LWC function calls - Apex Method Imperatively

import { LightningElement, track, api} from 'lwc'; import saveRecord from '@salesforce/apex/Controller.saveRecord'; export default class CreateModel extends LightningElement { @track showModal=...
0
votes
0answers
13 views

Need help add a column to a visual force page table with combine two list

I need help combining two list and show it on a table in SalesForce. Below is my apex controller class and my apex page and screenshot of my visual force page. Apex controller public with ...
0
votes
2answers
338 views

Trigger to update fields on record create or edit

I have a trigger on the OpportunityLineItem object that we use to update 4 revenue fields with specific calculations when the record is either created or updated. For some reason it seems the trigger ...
1
vote
1answer
830 views

Javascript error on Button click

I am using one custom list button on one of the related list. But sometime when I click on this button I am getting the below error message: A problem with the OnClick javascript for this button or ...
1
vote
1answer
40 views

salesforce identify if current time in a timezone exists between a particular time range (only time not date)

It may be a stupid question but i am trying from couple of hours and also searched on google but did not find anything. List<User> users = [Select id, TimeZoneSidKey from User]; system.debug(...
-3
votes
3answers
37 views

How to get the Latest record created date in salesforce?

I have a field called "Date" on custom object "TestData__c". If I create a record today I need to display today date.If I create a record tomorrow I need to display Tomorrow date.How Can I achieve ...
6
votes
2answers
2k views

How do invoke an apex method of one org, from another org?

I have already connected both orgs using REST API web-server flow. What should I use, Tooling API? APEX REST? How do I connect them?
1
vote
2answers
84 views

Outer Class can have how many inner class(es)

In Apex, how many inner classes can an outer class have?
1
vote
1answer
946 views

Embed report chart to visualforce filter issue

How can I apply filter for the <analytics:reportChart> tag? I created a report chart for my Fuel__c object with a filter of date_log__c (Datetime) field, by enddate and startdate. When I embed ...
3
votes
2answers
914 views

How to get contentData and ContentFileName for FeedComment Post

Can anyone tell me how to get the contentData and contentFileName for FeedComment ? I can get same for FeedItem using below query. [select Id,RelatedRecordId,Type,Body,CreatedDate,CreatedBy....
1
vote
2answers
2k views

Test that a Platform Event was published?

We have custom object CustomObject__c and platform event Platform_Event__e. Whenever any of CustomObject__c records are modified, platform event should be published. We need to write test class to ...
-1
votes
1answer
31 views

SObject row was retrieved via SOQL without querying the requested field: Webinar_Attendees__c.Voucher_Assign_Date__c

'm trying display parent fields and sub query fields in a table.But I'm unable to display sub query fields.Could anyone suggest an idea for me Page : ====== ...
0
votes
3answers
2k views

Rerender output panel when action method using pageReference

Can anyone tell me how to rerender a particular pageblock when the action method using pageReference? My use case is I want to rerender a particular block when I click the command button ...
0
votes
0answers
20 views

Best plugins for Upload file in Share Point through Salesforce [on hold]

I have to upload the files in Sharepoint through salesforce. Can anyone suggest the best plugin for upload the files.
0
votes
1answer
36 views

Batch Test class not calling execute method

I have created below batch apex class. I have also created test class for this. But this test class is only covering 27% of batch apex class. Also, it is not calling execute method of batch apex class....
-1
votes
1answer
21 views

Loop must iterate over collection: Webinar_Attendees__c

I'm trying to print sub query fields but I got the error like "Loop must iterate over collection: Webinar_Attendees__c". list<Webinar_Attendees__c> re = [SELECT Id,Login__c,Name,...
0
votes
1answer
686 views

Custom Settings values not being queried

I have a custom settings which has the following columns: Department || Sub Department || Employee || Serial Number My code is : for(CustomSettings__c cst: CustomSettings__c.getAll().values()) { ...
2
votes
1answer
343 views

Content security policy error while loading apex iframe

Issue: We get CSP (Content Security Policy) error with our Visualforce page integration. The issue is that when we access this in sandbox testing, we find that our content is wrapped in an iframe, ...
2
votes
2answers
48 views

Can APEX perform a bulk INSERT INTO…SELECT FROM like statement dynamically?

The basic question is if it's possible to create an INSERT operation using a SELECT statement as the source, rather than selecting individual records, pulling them out of the Salesforce database into ...
4
votes
3answers
89 views

How to mock ApexTestQueueItem, AsyncApexJob, and ApexTestResult for test coverage?

I'm currently working on a set of classes that do the following: A class that when instantiated and executed, queues all Test classes in Apex to run by inserting ApexTestQueueItems. I call this one ...
2
votes
2answers
1k views

List view filter criteria via Apex or Query or API

Is there any way we can get ListView Filter criteria using API or APEX or SOQL.
0
votes
1answer
32 views

How to get file name in http response?

I am using apex code to get file from url and able to insert it as attachment. I would like to know file name as well while insert ? When I open link in chrome it save the file with file name. ...
6
votes
4answers
740 views

Lightning: Getting a 401 when calling @AuraEnabled Apex method to do a REST call

Trying to write an Apex method that accesses Chatter REST api using this technique: https://chintanblog.blogspot.com/2017/02/call-salesforce-rest-api-from-apex.html This method is @AuraEnabled - so ...
3
votes
1answer
998 views

Salesforce to SFTP

I have requirement wherein a csv file should generate with some users data and need to place the same file in a SFTP path without using any external tool. Can I have an alternative approach to proceed ...
-5
votes
0answers
49 views

http request issue [on hold]

HttpRequest req = new HttpRequest(); req.setEndpoint('https://www.impots.gouv.fr/secavis/faces/commun/index.jsf '); req.setMethod('POST'); // our code has to specify: // - The required numeroFiscal ...
1
vote
1answer
23 views

Total number of batches in a job is different in UI and SOQL

Total Batches shown for a job in the APex Jobs page is different from TotalJobItems value in AsyncApexJob query. In the UI: In the Query: In the query result, TotalJobItems != JobItemsProcessed + ...
0
votes
1answer
42 views

Invalid Conversion Runtime Type List<> to Map<>

I understand I am getting this error on the map line but I do not understand why. As the method does return the list I am constructing. What am I missing about this exactly? The dataRequest starts as ...
0
votes
1answer
18 views

How can I save fetched JSON to a custom object's custom field. JSON parameters do not have same name as custom fields

On doing Something like this: o.FieldName__c = str[i].FieldName; //o instance of Custom Object and str is deserialized List. An error pops up showing 'variable does not exist: FieldName'. If I use ...
0
votes
0answers
34 views

Escaping HTML in JSON in rest callout

I am sending some html content inside json in the body of a REST callout from Salesforce to Dotdigital per their specs which is working well overall. string.escapeHTML4 is handling most of the ...
0
votes
2answers
17 views

Custom field inside WSDL without having this field on the object

is it possible to have a custom field inside the WSDL like: <xsd:element name="CustomField_1__c" minOccurs="0" type="xsd:string" nillable="true"/> but do not have the field on the object ...
0
votes
1answer
392 views

Cannot Create Entity Subscription to Portal User

I am trying to create entity subscription for a Portal User(Isportalenabled = true) to an opportunity, but I'm ending up with the following error on insert of entity subscription. 11:40:06:128 ...
-2
votes
1answer
12 views

Records are not displaying immediately,It needs to refresh page again.How can I display records without refreshing page?

I'm trying to display records in panel2 after clicking a button in panel 1.But records are not displaying immediately after clicking a button.Initially panel2 displays empty,after refreshing page ...
5
votes
0answers
32 views

How can I unit test a http callout that uses a certificate?

The .setClientCertificateName method of the HttpRequest class requires a string that is the name of a certificate in the organization. In a unit test class, is it possible to mock this method? When I ...
0
votes
0answers
17 views

Flow is not loading in Flow Builder

We have a custom app that creates a flow through apex and there's url redirect button once the flow is created. I am getting below error when i click on the redirect button. I can see the flowId (...
0
votes
1answer
27 views

attachment pdf loop not working

I have a problem with a oncomplete button. The goal is to do a loop throughout all my custom object and to generate a pdf and attach it to my custom object. I manage with the following loop to attach ...
-2
votes
1answer
22 views

Encountering “Missing targetObjectId with template” error when trying to send email template using Apex trigger

Goal: Send an email template using Apex. Error encountering: Error: There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered ...
0
votes
2answers
21 views

How to simulate visualforce page button in test class in order to deploy it?

Hi I have an Apex class which is called/invoked from a custom button called "desiredLocationsPage" , I have created the custom button in production like below; I have tested my test class in sandbox ...
2
votes
1answer
45 views

Using lazy-init pattern properties on Apex data objects in LWC

More of a technical question than a philosophical, because I am mainly interested in the intelligence of the LWC cache and any performance implications. I use the lazy-init pattern extensively in ...
0
votes
0answers
29 views

After Insert and After Update Trigger Handler delay in UI

I am new to APEX and I created two Trigger Handlers. They are identical but for different objects. This is for SF Billing Credit and Debits. Everything works, but one is delayed and the other shows ...
0
votes
2answers
32 views

test class for future callout Json.deserialise

My Class global class CreditActionSessionObjMgmt { @future(callout=true) static webservice void deleteSessionRecord(String sessionRecIds) { if(sessionRecIds != null ) { ...
0
votes
0answers
24 views

Advanced Apex Specialist - challenge 8 - Challenge Not yet complete… here's what's wrong

I have this error when I am trying to complete Salesforce Advanced Apex Specialist. Ensure that you have at least 12 products created and that OrderExtension is still working as specified in the ...
0
votes
0answers
13 views

how to add Loop conditions in apex test classes? [duplicate]

Could anyone help me how to write a test class for this logic.I'm little confusing here. public with sharing class XMLparserForIds { public String XMLString1 = '<?xml version="1.0" encoding="...
1
vote
3answers
214 views

Apex InvocableMethod not showing up in Flow

The Apex class is not in a package, has global visibility, is Active, has passing tests with 86% coverage, and the method has the @InvocableMethod tag but it is still not showing up in the picklist ...
0
votes
1answer
16 views

Count on Aggregate result starts as zero

Requirement is to identify the number of records assigned for a given user per day and if it reaches the limit, record has to assign to next user in the queue(All the queueing logic comes from custom ...
1
vote
1answer
1k views

Multiple values for same parameter in GET request?

How can i get multiple values for same parameter for below rest request using Rest request method? https://cs40.salesforce.com/services/apexrest/Membership?include=Membership:member&_include=...
2
votes
1answer
41 views

OrgLimits.getAll() works only with Anonymous apex and gives exception when used in any other context

I have a simple command on Orglimit which runs fine if run in anonymous as below system.debug(OrgLimits.getAll()); 20:25:55:076 USER_DEBUG [2]|DEBUG|(OrgLimit:[delegate=apex.sfdc.orglimits.OrgLimit@...
0
votes
1answer
15 views

Get the account list which has only one inactive AccountContactRelation

This might be pretty basic but I can't get anything on top of my head right now. We need to query all the accounts (or AccountContactRelation which is fine as well), which has only one inactive ...
0
votes
2answers
27 views

Parsing multiple values from a JSON Key

So I have a JSON returned from a REST API call that looks like this: {"AccountId":"0014000001aasdfAA","email":"email1, email2, email3"} What I want to do is parse it out so its normalized liked ...