New answers tagged apex
0
votes
Hide field on lightning-record-edit-form if the user has read only access to it
We can construct a list of fields in the Apex with using below code
List<Strig> fields = new List<String>();
Set<String> fieldNameSet = new Set<String>{'FirstName', 'LastName', ...
0
votes
Accepted
Not getting any records from ContentVersion in Salesforce SOQ query which we are not owner of
I Managed to find solution to my problem over the weekend and fixed it with a flow.
I fixed my issue by changing away from the Convent Version object.
Instead I got the Content Document Link on the ...
0
votes
Bring validation rule to VS Code project
You can retrieve validation rules under each Object by clicking on the cloud icon as shown on the picture bellow:
They will be shown inside each separate Object under validationRules folder
0
votes
How to get hidden value using template querySelectorAll
The reason why you are not able to retrieve the hidden value from the lightning-record-edit-form using the template querySelectorAll is that the hidden attribute or CSS style prevents the element from ...
0
votes
System.ListException: List index out of bounds
It seems to me that the trigger isn't part of the deployment, and the old trigger logic is still being run. In that code, you query a CMDT, then select the first item out of that list [0]. If this ...
0
votes
Can we do a callout inside for loop in batch class
I would suggest that your batchable execute() pass the list of objects to a Queueable class (via its constructor)
The queueable class would take the first object off the list
Make the callout and do ...
0
votes
Changing the 'From Address' in Messaging.sendEmailMessage: Is It Possible?
The EmailMessage object has both FromAddress and FromName fields. Specify these values to control the email and display name that will be used to send the emails. The address must be from the ...
0
votes
Too many soql rows :101 for SOQL query on user object
These limits are the effect of the execution across an entire transaction. Consider this simple code:
for(Integer i = 0; i < 100; i++) {
Account a = [SELECT Id FROM Account LIMIT 1];
}
Account b =...
1
vote
Cannot deserialize instance of textarea from VALUE_STRING value
You're not properly escaping the field, so certain characters could cause this error. At a basic level, you could probably fix this with just:
+ JSON.serialize(emailService.CommentsCopy__c) +
It is ...
0
votes
Not getting any records from ContentVersion in Salesforce SOQ query which we are not owner of
I haven't test this. But eh... For the service user's profile... Add access to apexClass: ContentVersion. And access to fieldPermissions: FirstPublishLocationId, VersionData, PathOnClient.
1
vote
Accepted
Unable to create the Patch Version for the Second Generation Managed Package
The reason why we couldn't create patch version is we have accidently opened the renderer and css files of an aura component. So a separate CSS and Renderer file has been created for the Aura ...
0
votes
Salesforce System.AsyncException - scheduled class calls Queueable apex do a callout and then calls batch apex
I found the issue.
Remove the Database.AllowsCallouts from the schedule class because salesforce will assume a future method is calling another future method although the schedule class is not doing a ...
0
votes
Data Not returned from apex to Aura component
I think the way you are accessing the Id of the returned record needs adjustments, check below
action3.setCallback(this, function(response) {
var state = response.getState();
if (...
0
votes
Accepted
How to make flag gets TRUE based on user submission Time?
Try writing a trigger on the case object
trigger CaseTrigger on Case (before insert) {
for(Case c : Trigger.new){
if(DateTime.now().hour() < 11){
c.Urgencyflag__c = true;
...
2
votes
I am trying to schedule a basic batch class with a CRON expression which schedules it for every 5 minutes everyday
If you are happy with timing drift, where you simply want to ensure that you have processing done every 5 minutes or so, an alternative to Schedulable is to actually have your Batchable implementation ...
2
votes
I am trying to schedule a basic batch class with a CRON expression which schedules it for every 5 minutes everyday
You can run an apex job every 1 hour using CRON expression by default but you can schedule this job 12 times in one hour at 5 min duration.
You have a Scheduler class MyBatchClassSchedule and want to ...
3
votes
I am trying to schedule a basic batch class with a CRON expression which schedules it for every 5 minutes everyday
In Salesforce, scheduled jobs cannot be scheduled less than one hour apart. If you want to have this process run every five minutes, you will need to schedule 12 jobs five minutes apart.
3
votes
Parsing Google Maps JSON with APEX
I still have to have a look at the documentation. I don't fully understand the result that you present in your example JSON, but below is a first attempt at making the information gleaned from the ...
-1
votes
Diference between @future (callout= true / false)
Its quite simple, where you want to callout third party when resources available, annotate the future method as 'callout= true'. If you want perform some other asynch operations/other future method ...
-1
votes
Data Not returned from apex to Aura component
You can return a string like this
return JSON.Serialize(Cd);
And parse it in aura controller
0
votes
Executing SOQL with User Mode and then DML with user Mode causing Exception
I believe this is a bug with AccessLevels. Until it's fixed, you can use the following workaround:
List<My_Rule_Obj__c> rules = new List<My_Rule_Obj__c>{ rule };
List<My_Rule_Obj__c> ...
0
votes
Accepted
.SFDX folder creates subfolder 246 and many subfolders which are totally useless
These files are not useless. They are files used to autocomplete built-in Apex objects and functions. For example, CalculateTaxRequest is for Connect.CalculateTaxRequest. If you want to be able to ...
1
vote
JSON.deserializeUntyped Error : System.JSONException: For input string
Long has a range of -263 to +263-1. This value is sufficient for any transaction you're every likely to do with an external system. For example, the total estimated global wealth is $454,400,000,000,...
2
votes
LWC referencing error information in Apex callout failure
The lwc-recipes repo, provided by Salesforce, provides a function you can use in any of your projects to parse the exceptions properly. I've included it here for reference. You can check out the repo ...
2
votes
LWC referencing error information in Apex callout failure
I added--
alert(JSON.stringify(error));
and that gave me the info I need; see image below.
Changed my code to --
alert('Error members -- ' + error.status + ' - ' + error.body.message + ' - ' + error....
1
vote
JSON.deserializeUntyped Error : System.JSONException: For input string
The maximum value of a long is:
9223372036854775807
but your number is bigger than that:
2545534543535345435345
1
vote
LWC component when placed [object object ] is visible
In your code, childId is used in JavaScript, but LeadId is used in Apex. That means that query for Lead lerec will not match any rows, and throw a "No rows for assignment" error. [object ...
2
votes
Database.Stateful Batch APEX and static variable in Test Class
Unfortunately, I don't know how to answer your question directly. We don't have the actual, full code to see what's wrong. The code as written doesn't compile, which means I had to pare it down to a ...
0
votes
How to call a method that makes DML and after that another method to get data and cache it
Basically you have to wait till first apex method returns a result, to call second method from your LWC
You can achieve this 3 ways:
Use async await
Using .then method
Use promises
With the minimum ...
1
vote
Accepted
http call out to an external REST webservice
One step which you have missed is adding apex class permissions for permission set you created.
If you know the request and response, but api is still under development, use postman(or any mock api) ...
3
votes
Accepted
How to storage data in Apex Controller for server side caching?
The thing you're looking for is probably the The Org (platform) Cache (as opposed to the Session Cache).
There's also a relevant trailhead module to help get you started.
In a nutshell:
You create a ...
1
vote
Accepted
SOQL : View details of CronTrigger.CronJobDetail.Name
I can't tell you why the XL Connector can't handle the query. Maybe it's running too low of an API version or something. You'd have to get in touch with the appropriate tech support.
As far as the ...
0
votes
Apex Callout Issue - System.HttpResponse [Status=Moved Permanently, StatusCode=301]
You can try to get the URL on which request is getting redirected for that use the below code
HttpResponse response = http.send(request);
if(response.getStatusCode()==301){
String ...
1
vote
Salesforce apex how to save checkbox multiple values in database
First, make sure your picklist is a multiselect picklist. Single option picklists won't hold multiple values correctly. Second, to assign multiple values to a multiselect picklist, you must use a ...
2
votes
Accepted
Dynamic Question and Answer form
This is happening because you're keeping separate arrays for questions and answers. The data came in correct form from apex, it was already linked, so there's no need to divide it.
this.data = result....
0
votes
Update Custom Metadata with Apex in my org
The accepted answer will not work for updating custom metadata. You can't assign id field using the CustomMetadataValue class, it throws an error saying Unsupported type 'Id' for field name 'value'.
...
0
votes
Test Code Coverage - Delete DML catch block
OK, let's start by simplifying your code
@AuraEnabled
public static void deleteObj(List<Id> ids) {
list<Error_Logs__c> lstErrorLogs = new list<Error_Logs__c();
try{
...
1
vote
Accepted
Enterprise Architecture, Domain layer - handling multiple records
The example in fflib-apex-common-samplecode assumes that all opportunities will get a common discount%
Your conundrum is a common one
Option 1
If in fact you want the domain class to apply the ...
0
votes
Unable to fetch accountId of User in Test class
The issue is here:
User u = TestUtility.createCommunityUser(con.Id,profileId,'Fname','Test');
that calls
public static User createCommunityUser(String contactId, String profId, String firstName, ...
0
votes
notifyRecordUpdateAvailable vs RefreshApex vs RefreshView API
Knowledge on RefreshView API is still lacking. But I (think) can at least answer the question of RefreshApex vs notifyRecordUpdateAvailable.
RefreshApex is great for most situations. It will provision ...
7
votes
Accepted
Using Apex, how do I monitor the daily @future limits?
As sfdcfox pointed out, this is a shared limit for all async operations in the org.
You can monitor this directly in Apex via the OrgLimits class.
Map<String,System.OrgLimit> limitsMap = ...
0
votes
How to properly test and assert an @restresource that do multiple API calls?
we can acheive this using map of callouts.
Below article clearly explained the way how to do that
https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-...
1
vote
Accepted
Multiple Items in HTTP Request Body Using wrapper
Your JSON is invalid. You can use the JSON Viewer or JSONLint to validate the JSON.
Suppose your JSON is like this:
{"data":[{"TOne":"First","TTwo":{"one&...
1
vote
Test Code Coverage - Delete DML catch block
You can use the Test.isRunningTest method to check if the code is running in a test context and then throw a custom exception.
For example, you can modify your main class code like this:
@AuraEnabled
...
0
votes
Accepted
Before Insert or Upsert list must not have two identically equal elements WHEN INSERT LIST
You're getting this error because you have the same object in memory in two or more indices.
Here's a simple reproduction of your error:
Account demo = new Account[0];
Account[] accounts = new Account[...
6
votes
Using Apex, how do I monitor the daily @future limits?
Note that future methods don't have their own limit. The limits are shared across schedulable, batchable, queueable, and future methods. There's no way to get this data directly in Apex, but the ...
0
votes
How to send a callout request with Post method using JSON?
While this wouldn't be valid in Apex (because we can't have multi-line strings), if you try to "pretty print" your JSON, the issue should become obvious
{
"name": "Apple ...
2
votes
Need help increasing the code coverage for this trigger
Some background
The golden rule of unit testing is
You only gain coverage for lines of code that are executed by some test method
In tests, we are the ones responsible for setting up the test data. ...
1
vote
Accepted
Trigger to get products records on a long text field in opportunity
This is as simple as querying the records and updating the field.
trigger summarizeProducts on Opportunity(before update) {
// Reset field
for (Opportunity record : Trigger.new) {
record....
0
votes
Salesforce Account Merge Trigger Execution in Bulk Scenarios
How is it possible that these operations happen within the same transaction?
A transaction starts when an API call is made, and ends when the API call returns the final results and writes the debug ...
Top 50 recent answers are included
Related Tags
apex × 36484visualforce × 7285
trigger × 5088
unit-test × 2943
soql × 2794
batch × 1391
javascript × 1133
lightning-web-components × 1096
lightning-aura-components × 989
code-coverage × 863
json × 862
class × 827
rest-api × 796
callout × 794
controller × 750
community × 740
lightning × 678
map × 638
scheduled-apex × 561
visualforce-component × 542
email × 539
list × 534
visual-workflow × 467
query × 462
governorlimits × 462