New answers tagged trigger
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
In Salesforce, if there are multiple FLOWs active for the same object then does trigger fired only once or will it be fired for each FLOW
If there are multiple flows active for the same object, the trigger will fire only once for each context (before-save or after-save). However, the order in which the flows run depends on the trigger ...
0
votes
Problem with PlatformEventSubscriberConfig user change being ignored
Solution in my Case:
Open Setup > Platform Events
Open Event Class with PlatformEventSubscriberConfig
At Subscriptions click on Manage
Suspend Subscription and activate it again.
Now new config ...
1
vote
Accepted
Querying CampaignMembers based on Lead fields
At first glance, your code is a lot more work than it needs to be. If we use Trigger.newMap instead of Trigger.new, we don't need the partners map. Consequently, we can dramatically reduce your code ...
1
vote
Accepted
Trigger to calculate Average date of closed opportunity if its closed won?
As Felix Van Howe says, CreatedDate is a Datetime field, so, you'll need to extract the date portion from the Datetime.
(and I rewrote this to be crisper)
public static void afterUpdateMethod(List<...
3
votes
Batch Apex Class Invoked From Before Delete Trigger is not deleting Files Attached to accounts
The query won't return any records, because the accounts will have already been deleted by the time your batch class has run. Instead, query for those files in the trigger, and use a batchable, if you'...
2
votes
Batch Apex Class Invoked From Before Delete Trigger is not deleting Files Attached to accounts
If the execute of your batch class is not running, but the finish is, it means that the query in the start is returning zero results.
Your batch class will be running asynchronously, so it will be ...
0
votes
Syncing data with legacy system
There's no such thing as a Code Block in Salesforce. You could create a custom field, and store data there to indicate if it's likely a synchronization.
2
votes
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, execution of AfterInsert
Well, the immediate source of the error is because your code is structured like this
for (Account objAccount : accountsToUpdate) {
for (Contact updatedContact : Trigger.new) {
// Yes, I've ...
2
votes
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, execution of AfterInsert
As a preface, consider using DLRS. It does what you're trying to do without you having to write any code.
That said, you have a couple of problems. First, you're not using the undelete trigger event, ...
0
votes
How to edit Parent Record from Related Record
You'll want to write two triggers, one for Lead and LeadClientInsurance__c. Both will look very similar. You can also build this design in a flow, but I'm not going to build all that for this question....
1
vote
Accepted
Partial commit in before insert trigger - Apex
When you use the insert, update, delete, etc... keywords, that uses the default mode of operation for DML.
That is to say, it's all or none. If one record runs into an error, the entire DML operation ...
1
vote
Apex - 0% Code Coverage!
Solved. The FundingAwardTriggerTest test class was omitted from my outbound change set. Including it solved the issue!
0
votes
How to generate a GUID/UUID?
You can also use Auth.JWT() class for that:
(String)((Map<String, Object>) JSON.deserializeUntyped(new Auth.JWT().toJSONString())).get('jti')
It's not documented in https://developer.salesforce....
0
votes
Trying to Bypass Validation Rule within Flow
If you are referring standard validation rule on object then I would recommend to tweak your validation rule rather than flow. If you have the condition which you were planning to use during flow ...
1
vote
Accepted
I'm trying to bulkify the update of parent field based on child
You are querying the rooms by their name instead of their database identifier.
Instead of WHERE Name IN use WHERE Id IN.
An improved version of your snippet, with an early return and a more selective ...
3
votes
Getting System.NullPointerException: Attempt to de-reference a null object . Trying to update Account Description field as OpportunityLineItem Desc
The issue is Account acc = AccIdmap.get(oppI.Opportunity.AccountId);.
As written, your acc variable is guaranteed to be null.
If you go back to your error and look at your stack trace you should be ...
0
votes
Conflict Between Triggers on blng__Invoice__c: Billing Package vs. Custom Development
There's no direct method to control the order of triggers. To run your trigger after a "before save" trigger, you would need to use an "after save" trigger. To guarantee your ...
1
vote
If a user can access only the salesforce UI, will there be multiple transaction for that user?
So, if an account is restricted to use Developer Console, does that mean each event in sf ui will be in single transaction (assuming that there is no code that updates multiple records when a certain ...
1
vote
If a user can access only the salesforce UI, will there be multiple transaction for that user?
I think you have gotten confused by what you have read.
The standard Salesforce UI allows the user to perform a sequence of actions (typically create, edit, delete against individual records), and ...
0
votes
Field is not writeable: Opportunity.PartnerAccountId
You cannot populate the Partner Account directly on an Opportunity. Instead, you must insert a Partner record linked to the Account and the Opportunity. For example:
Partner p = new Partner();
p....
Top 50 recent answers are included
Related Tags
trigger × 7920apex × 5086
unit-test × 561
before-trigger × 383
soql × 374
after-trigger × 298
class × 229
workflow × 204
visualforce × 193
code-coverage × 191
opportunity × 155
process-builder × 144
email × 142
update × 135
batch × 130
case × 126
account × 122
future × 121
visual-workflow × 118
map × 116
callout × 110
custom-object × 108
bulkification × 107
triggercontext × 106
community × 104