New answers tagged apex
0
votes
When the triggers run in context of a composite standard Rest api, which governor limit it comes under?
Sorry for the long post. But an interesting finding with data points.
I did some testing around this. Here are my findings.
FIRST
services/data/v52.0/composite
{
"allOrNone":true,
"...
0
votes
How to generate and download file(text) in visualforce page
I resolved this problem,I am using the javaScript download function in two ways
Visualforce page:
<apex:page controller="VFPageDownloaderController" action="{!downloadAutomatic}"...
0
votes
Text file download in Visualforce page
I resolved this problem ,I am using the javaScript download function with two ways
Visualforce page:
<apex:page controller="VFPageDownloaderController" action="{!downloadAutomatic}&...
0
votes
When the triggers run in context of a composite standard Rest api, which governor limit it comes under?
All the standard apex governor limits apply here for every individual REST API inbound call or sub requests within composite inbound call. As mentioned here, the entire composite inbound counts ...
0
votes
Chatter feed auto refresh
You cannot auto refresh chatter feed in salesforce, Kindly review and vote for this feature.
Thanks
0
votes
Visualforce email template table row conditional with no controller
You have:
<apex:outputField value="{!IF(rx.Type__c == 'Online', rx.Training_Start_Time__c, '')}"
You can't do this -- apex:outputFields can't be dynamically specified in an IF block
...
0
votes
Apex Class - Day Light Savings - If statement to adjust for daylight savings based on dates
I'd like to take @sfdcfox's response and extend it. When you consider Daylight Savings Time, this has two transitions in the year (unless DST is being made permanent, as The Fox says). You can ...
0
votes
How to give profile label permission for files upload and delete
To prevent file upload capability, you will have to enable or disable the Select Files from Salesforce permission as mentioned here
To prevent deletion of files, refer this
Only the file owner can ...
0
votes
store pair of 2 fields on a map
your syntax looks correct, but I'd run it in Anonymous Apex to double check (screenshot added for reference). You other questions can be answered from the Apex Documentation linked below. Let me know ...
1
vote
Can I check contact field conditions from the Map?
If I understand correctly, the code above is iterating through a list of Campaign Members, then if the Campaign Member is linked to a Contact, calculate a date value called LatestDate, then put the ...
0
votes
Pass variable from LWC to apex controller
Well that was more simple than I thought. . .
two lines:
js
createCustomer({name: 'Skip', email: 'skip@gmail.com'})
controller
public static String createStripeCustomer(String name, String email) {
2
votes
Triggers on contact to update decsiption field of its parent account
You have queries and DML operations in a loop, both of which are bad. Also, you're querying the records only in the trigger, which would cause the overwriting you've observed. Instead, you'll want to ...
0
votes
how to call a parameterized method from the developer console?
You declared your add() method as static, which means that you call it using the name of the class instead of an instance of the class.
Other than that, you just need to pass the correct number and ...
0
votes
how to call a parameterized method from the developer console?
'add' method in above class expects two parameters to be passed when being called.
If you call 'first.add()' without passing any parameter code will try to find a function with name as 'add' which ...
0
votes
Unable to fetch the Parent Account information into the Child Account Record
in the line no. 4 Replace this line
if((ac.Account_Level__c == 'Parent' || ac.Account_Level__c == 'Account') && !ac.Exclude_Account__c && ( ac.ParentId != oldAccountMap.get(ac.Id)....
2
votes
Accepted
How to fetch name field for a record of given record id but known object?
Salesforce says, sometimes it is not accurate, what it says :)
There is a possibility to get "main" name field for every object: custom and standard. Use isNameField method.
String ...
0
votes
How to get translation of field label based on language and locale?
Here are 2 possible coding options to retrieve translated field label based on current user language
In APEX
Using Schema describe methods, the field label is translated based on user language
Map<...
1
vote
How to download all Apex classes from Prod using VS code
We can also use these commands from the terminal:
Retrieve All Apex classes
sfdx force:source:retrieve -m ApexClass
Deploy All Apex classes (Never do, a very bad habit)
sfdx force:source:deploy -m ...
1
vote
Best practice for async apex classes (Queueable, Batchable) in relation to service classes
My practice which is not bullet-proof and subject to better alternatives.
If it is a Schedulable class with no call to a batchable (or calls a configurable batchable)
xxxSchedulable
If it is a ...
1
vote
Best practice for async apex classes (Queueable, Batchable) in relation to service classes
This is more an opinion questions so what I share here is an opinion, which may or may not work for you/others.
We came to realize that in Salesforce due to nature of platform, smaller classes are ...
0
votes
SOQL: Convert set to list
If someone like me enjoys using the array notation for the lists like:
Id[] ids = new Id[]{};
instead of,
List<Id> ids = new List<Id>();
to create a list from a set would be as the ...
1
vote
Accepted
Named Credential - using a merge field
Named Credential acts as a runtime proxy. The proxy receives your HTTP request then searches its body or headers for the merge field as a literal string. If NC doesn't find the field, it won't ...
0
votes
Accepted
Database.query() question
No need to use variables if they are not required to be referred in another place. However, careful use of them can enhance the readability of the code to reduce the noise or complexity.
I assume you ...
2
votes
Accepted
Does Date.addDays() method skip the weekends based on the Org's Business Hours settings?
It does not interact with your Business Hours at all. It just adds days. From the documentation on the Date class:
addDays(additionalDays)
Adds the specified number of additional days to a Date.
0
votes
Need help with test class for code coverage on AccountContactRelation Object
This code works for me with no errors:
@isTest
static void test_CreateAcctContactRelation() {
Account accRecord = new account();
accRecord.Name = 'Test Acc1114';
insert accRecord;
...
2
votes
Accepted
Salesforce - Edit field on before delete
You can update the record via DML in a before delete trigger. Here's a copy-paste example:
trigger markAccountAsDeleted on Account (before delete) {
Account[] accounts = new Account[0];
for(...
1
vote
My LWC comes up as Object object in communities but works in lightning apps page
You should debug what you have in rent.error when it is opened in the community.
It seems like, there is some exception thrown by rentController.getRent method, which is an object in error. [object ...
3
votes
Accepted
Conflict between Run Time and CPU time in Apex
The five second concurrent transaction limit is primarily there to prevent us from consuming too many resources. You can view the 10/60 second limit as a "burst" limit, while the 5 second ...
3
votes
why my JSON deserializeUntyped giving me Exception
The decoded parameter is JSON, so you have to deserialize again:
Map<String, Object> params = (Map<String, Object>)System.JSON.deserializeUntyped(
RestContext.request.requestBody....
3
votes
Accepted
Batch apex not executed from test class
The key thing that you're missing is Test.startTest() and Test.stopTest().
Async apex (@future, queueable, batch, schedulable) runs in a separate transaction from the one that it's called from. In the ...
1
vote
Named Credential - using a merge field
I don't think you can use a merge field like this, because it's replaced when the call is made.
Effectively you're ending up with the encoded value of the literal text {!$Credential.Username}:*...
0
votes
How to find account with inactive opportunity and send email alert?
You could create a scheduled flow that runs daily, and checks all your accounts iteratively and their opportunities. You should have a new date field on your accounts for 'email sent'. For those that ...
3
votes
why my JSON deserializeUntyped giving me Exception
That is because event_value is escaped inside of a string. Meaning it starts with quotes, and all quotes inside are escaped with a backslash:
{
"event_source": "",
"...
0
votes
Apex Class - Day Light Savings - If statement to adjust for daylight savings based on dates
Don't hard-code the timezone offset; parse the time as a GMT, then use the TimeZone class to calculate the correct offset.
// If using this in a loop, compile once for performance
Pattern p = Pattern....
0
votes
How to properly test and assert an @restresource that do multiple API calls?
So try something like this (note, this is me coding in the browser so you might need to adjust it).
public class MockHttpResponse {
public Integer code { get; set; }
public String status { get; ...
0
votes
Salesforce - Best way to pass namespace__ (e.g:Apttus__, svmax__ etc) to get('obj').getDescribe().fields.getMap(); method
The namespace prefix is part of the object API name. You should be storing the complete ("fully-qualified") object API name. So if you have an object called apttus__Template__c, you must ...
0
votes
Accepted
Validate lineitems and throw error if the lineitem values dont match
Maps and Sets are your friend whenever you want to perform pretty much any comparison.
The general approach here is:
Determine what you want your map key to be, and what you want the value to be
Make ...
0
votes
Accepted
Multiplication of two fields in salesforce using trigger
Even if your code ended up working, you'd run into a recursive loop. You should use before insert/before update, and set the value directly. You'll need to query the parent record(s), then perform the ...
1
vote
System.LimitException: Too many callouts: 101 Error
The error message is clear that you cannot make more than 100 calls in Transaction (Tx) context. Each time your future job runs, it starts a new Tx context and that execution can make max 100 calls.
...
0
votes
How to remove time from date?
A more elegant way I found was:
System.debug('Current date: ' + String.valueOf(Date.today().toStartOfMonth()).split(' ')[0]);
1
vote
How to convert JSON String of RESTRequest to Map
Naming your string "json" is shadowing the JSON class, causing you to be unable to use the JSON class in the same scope where this variable is present.
Rename your string variable, or use ...
0
votes
Accepted
What do we mean when we write the below code?
There was some aggregate query on which is returning the Accountid, Amount .. etc. You are iterating the result through the for Loop and adding the Id and Amount to the Map called amountMap. The same ...
0
votes
Lightning Dual Listbox style
I removed selected-label="Selected" and the box was aligned correctly .
1
vote
Platform event Fired from two objects
Platform Events can be absolutely used in this case.
Just to recall, Platform Event is similar to a Custom Object, has its own set of fields and is not tied to any other Object hence it can be used to ...
0
votes
How to In trigger, when an account is Inserted it should create multiple contacts without nested loop?
we can add one more step to this code, if you create 'Total Contacts' field in Account, the trigger will create as many contacts as you indicate in this field;
trigger testAccountTrigger on ...
3
votes
Accepted
Is there anyway to check what the triggering class is?
I think the most correct term to use here is the "calling class", and No, there is not an out-of-the-box way to determine that.
The closest thing you'd get to this is to have the class where ...
0
votes
How to define a constructor and pass parameters to schedulable controller
Here's my way of passing parameters to a schedulable apex class.
This following class has a constructor that takes two parameters and sets the class attributes to hold the values passed into as the ...
0
votes
Passing Parameter Into Schedulable Class
Here's my way of passing parameters to a schedulable apex class.
This following class has a constructor that takes two parameters and sets the class attributes to hold the values passed into as the ...
2
votes
Accepted
setBody on HTTPCallout not working apex to stripe
When you're having trouble with a third party API, your first stop should be to look at that third party's documentation. Here's Stripe's API documentation for the customer object.
Combine that with ...
2
votes
Accepted
How to add ALL ROWS in fflib selector class
Seems like there is no fflib solution for it. Append the ALL ROWS string at the end of a built query string.
public List<AccountTeamMember> selectByDeletedId( Set<Id> ids)
{
...
Top 50 recent answers are included
Related Tags
apex × 34072visualforce × 7147
trigger × 4815
unit-test × 2771
soql × 2594
batch × 1273
javascript × 1051
lightning-aura-components × 960
code-coverage × 799
class × 797
json × 782
community × 733
controller × 733
lightning-web-components × 722
rest-api × 720
callout × 713
lightning × 641
map × 591
visualforce-component × 526
scheduled-apex × 526
email × 523
list × 503
query × 429
governorlimits × 427
api × 407