Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Make your voice heard. Take the 2019 Developer Survey now

Questions tagged [trigger]

A trigger is a feature of the Salesforce platform consisting of Apex code that executes before or after DML operations.

-3
votes
1answer
44 views

Could you please help me write a test class for the following code: [closed]

trigger TicketTrigger on Ticket__c (before insert) { List<Id> cusIdList = new List<ID>(); List<Ticket__c> updatedTckt = new List<Ticket__c>(); for(Ticket__c ticket ...
0
votes
1answer
31 views

Change error message displayed when trying to edit a Locked Record

I am trying to change the error message that is thrown when a user tries to update a locked record, because instead of sending them to the Admin it should really say go to the approvals and accept or ...
0
votes
2answers
57 views

Salesforce Triggers [closed]

In the Salesforce , Field Service Lightning application there is a Dispatcher console with multiple status fields in it. I created a custom field in it and called it 'Responded'. What do I wanna do ...
0
votes
1answer
40 views

Get IDs of list after inserting records to map to a second Object

I have built a Trigger which first creates an Asset and then a Case when an Opportunity is Closed/Won. I however need to fill a field on Case, Asset.Id, with the ID of the Asset created in the same ...
0
votes
0answers
20 views

I want to deactivate trigger in production via xml-file. Will it count against the code coverage at the time of deployment? [duplicate]

I want to deactivate trigger in production via xml-file. Will it count against the code coverage at the time of deployment? We are rolling out new trigger and deactivating the old one. We want it to ...
0
votes
0answers
31 views

Event.StartDateTime to be treated as the Timezone I specify in the Trigger

I have a flow screen where I display four fields as inputs as follows: Meeting Start Date Time Meeting End Date Time. Meeting Location. Meeting Owner. Meetings are nothing but Events in our ...
-1
votes
1answer
47 views

Apex Triggers Copy Primary Contact Role into lookup field in the opportunity page

I copy this formula and it works great when the lookup field is null but if I want to change the Primary contact Role the lookup field does not change (it keeps the first contact Role assigned) Can ...
1
vote
1answer
22 views

Nested Parentheses in an If condition

I'm refactoring legacy code and I'm having a challenging time unraveling the order in which these conditions are evaluated. I'm assuming the two most nested conditions take precedence but I haven't ...
0
votes
2answers
14 views

What is the proper way to update the object that the Trigger is being called on?

For example, I am working on a method in the Account Trigger that will fire when an account record is attempted to be inserted. Ideally, I would be able to look at a field on the account record being ...
0
votes
2answers
43 views

Update Parent record when child record is updated

I am writing the trigger for When I update the contact record description value of an Account, and if other contacts description value related to that Account is matched. Then update the Account ...
0
votes
1answer
37 views

Create a record in 'Email to Case Premium' in Salesforce using an API call

I am working on a solution where we have an 'Email to Case Premium' or E2CP app added to our Case object in Salesforce. I would like to programmatically create a record in E2CP with Salesforce API ...
0
votes
0answers
33 views

How to create a custom button in Create page (that will redirect to a certain page)?

Right now I am on a specific Report tab view called 'Inventories 3'. When I create a 'New Order' via the Navigation bar (Screenshot 1). This will bring up the Order create view as per normal way. ...
6
votes
2answers
49 views

Workaround for the one record at a time trigger invocation when starting from Content Note

I hit this platform problem a while ago Why is this ContentNote trigger receiving 1 record at a time even though multiple records are being inserted?. But today I've hit it again and now I need a ...
0
votes
1answer
29 views

Trouble with AddError method

Sales Invoices are a custom child object of Opportunity. I'm trying to write a class that throws an error if the total of all sales invoices for a given opp goes above the opp's amount. Currently it ...
1
vote
0answers
50 views

Bulkify dynamic query Batch Class?

I converted existing batch class that was processing single record into schedule/batch class that can process multiple records. But I got stuck in bulkifying the dynamic SOQL inside the for loop. ...
0
votes
1answer
54 views

Apex Trigger is not being fired sometimes

We have a method in Trigger handler class to update a field on parent record with a value from child record. This method is being called in a Before trigger but this trigger is not firing in some ...
1
vote
1answer
20 views

AddError on an object in a trigger is only displaying one of the errors in object list view

I have a trigger on an object, and in that trigger I am doing the following: List<ApexPages.Message> msgs = RecordValidator.isValidRecord(thisObj, criteria, matchingObjectUnionList.values()); ...
1
vote
1answer
94 views

Batch Apex Too many SOQL queries: 201

I am getting Batch Apex Too many SOQL queries: 201 when the class is scheduled for run in developer console. Batch Apex: global class Batch_EmailBlast implements Schedulable,Database.Batchable<...
0
votes
1answer
55 views

UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records - Error even after using FOR UPDATE

I have a trigger and I am calling a queueable job from trigger. Sometimes I get this error: Update failed. First exception on row 0 with id a0VN00*********; first error: UNABLE_TO_LOCK_ROW, ...
0
votes
2answers
48 views

Apex trigger to work as a validation Rule

on the Account Object i need a validation rule which need to prevent Accounts from being set to 'Dead' if there are Orders associated which have a Status <> Invoiced. Account field to be checked = ...
0
votes
2answers
43 views

Trigger.New value to compare with all records

I has objects Contracts__c with fields(Start_Date__c and End__Date__c) and related obj Actor__c. When i insert new contract i trying to check does the actor already has a contract on specified dates. ...
-1
votes
1answer
49 views

Test Class/Method for TriggerHandler - Negative scenario

For this class below, which essentially counts the number of Open cases on an Account, on update/insert/delete of a Case, can anyone help me write/provide a scenario of a test method that can hit the ...
2
votes
1answer
54 views

Salesforce Metadata Update tools

We are looking for a tool to reactivate Apex triggers(100), Flows(20), WF rules(50) and Validations rules (1700). During data seeding in a sandbox from PROD using a famous tool had deactivated all the ...
-1
votes
1answer
37 views

Need help with a Test class coverage

Hello guys i need help to cover this Trigger on a Test Class, this Test Class also covers another class so some Data is not refering to the Trigger. This is the Test Class: @isTest private class ...
0
votes
1answer
22 views

adding up custom field with triggar [duplicate]

trigger PaymentTrigger on Money_Received__c (after insert, after update, after delete) { Money_Received__c moneyReceived = [SELECT Reservation__c FROM Money_Received__c]; Reservation__c ...
3
votes
3answers
472 views

Help With A Null Pointer Exception

I am hoping that someone can teach me a little about how to work through this null pointer error. The class is called from a trigger handler on After Update because I need access to all ID fields. The ...
-3
votes
1answer
45 views

is there any way to solve the following case with out using maps [closed]

Create Custom field called “Number of Locations” (Its API Name: NumberofLocations__c) on the Account Object (Data Type=Number) The following trigger creates the number of contacts which are equal to ...
0
votes
1answer
30 views

Help With Code Coverage

new developer and I am struggling with getting 100% code coverage on a test class. I have written a class to count tasks with unique subline lines and then update a field on a custom object with the ...
1
vote
0answers
34 views

Soql in apex trigger returns different result depending on user who causes the trigger.

In Communities we have an ideas component where users can post/comment/vote on different ideas. We are trying to create a trigger which will send an email to the idea creator whenever someone ...
1
vote
1answer
34 views

Get EntityMilestone fields values?

I'm coding a trigger on case and I'm using this query to get some data fields information from CaseMilestone entity: Select caseid,MilestoneTypeId,CompletionDate,ElapsedTimeInMins,IsCompleted,...
0
votes
2answers
115 views

Trigger error - Too many DML rows: 10001

I have tried to optimize the code, but still it throws the error: Too many DML rows: 10001 Below is my code: if(setAccID != null && !setAccID.isEmpty()) { list<Custom__c&...
0
votes
2answers
34 views

How to set the RecordTypeID

Im trying to set the RecordTypeId of a contact to a certain value if the contact was created by a specific user. Im getting the error: A value cannot be stored to RecordTypeId in type Contact. ...
0
votes
2answers
37 views

How to set ContentDistribution password?

I kindly ask for help with setting ContentDistribution password on a published document link. In the Controller I have: ContentVersion conVer = new ContentVersion(); conVer....
1
vote
0answers
45 views

How to pass multiple param in invocable method

from visual flow i am calling apex class, while calling I need to pass 5 param(3 List, 2 String).but it is not accepting more than 1 param @Invocalble method how to solve this public class SendMail { ...
0
votes
1answer
18 views

Need solution on Child to parent if Parent values is changed to something else

I have a requirement where My custom Object(Market__c) is lookup of Account . Whenever my Account type value is changed from Inactive to Active I Need to capture current date to(Captureaccount__c) ...
0
votes
1answer
30 views

Update users field on account using workflow or process builder

I have one field on user (Employee Number). Whenever the status of the account (Status__c) change to 'permanant'. I need to capture the employee Number in one of the account field ,who will chnage the ...
3
votes
1answer
201 views

Unable to subscribe to platform event using emp api

I am trying to subscribe to my platform event using the empapi feature. This feature was added in v44. I am following the example of the documentation page: https://developer.salesforce.com/docs/...
1
vote
1answer
20 views

need to avoid firing trigger on perticular api invocation

I have written one trigger which fires on account create and update,but there is one API which creates/update account and if creation/updation is through that API i don't need to fire trigger. Please ...
0
votes
1answer
19 views

Beautify exceptions from triggers in Lightning UI

I have a function that I fire on an after insert or update of my Inventory__c object public class duplicateException extends Exception {} public static void preventDuplication (List<Inventory__c&...
2
votes
1answer
96 views

How to display Trigger addError in Salesforce Lightning using AuraException

Background I have a before insert trigger which returns an error: myObject.addError('Helpful Message'); Which I want to catch and display gracefully in my lightning component. My Apex controller ...
0
votes
1answer
44 views

Field is not writable for opportunity team member Name

Getting an error like An Apex error occurred: System.SObjectException: Field is not writeable: OpportunityTeamMember.UserId public class BD_UPDATEOppTeam { @InvocableMethod public static ...
0
votes
3answers
32 views

Restrict of updating opportunity owner

I want to restrict updating the opportunity owner. I cannot able to use the validation rule because ISCHANGED( Owner.Id ) is not working. Its giving the error like Error: The ISCHANGED function cannot ...
0
votes
1answer
35 views

If condition not working

If condition in a trigger has weird results. My condition is, if there are no values from my Set collection do not proceed. Even my debug statement shows NULL value. why this is happening?? if(...
0
votes
1answer
38 views

Using Process Builder to set Date field on Contact upon sending Mass Email

So far, I have attempted to build several processes to achieve this using the Process Builder. None of the processes are completing, or firing for all I know, because I don't get an error message if/...
4
votes
1answer
317 views

Eliminate query on Custom metadata type?

I'm trying to use Custom metadata type to replace a List type Custom settings. I have to access the Custom metadata type information in multipe apex classes and triggers. When I use custom settings, ...
0
votes
1answer
51 views

How to build a trigger for 2 scenarios in 1 object which will create/update multiple records in another unrelated object?

Scenario 1: a) Trigger on Custom Object 'Prod' only when record type = 'Forecast'. b) It should take data from 1 custom date field and 3 custom number fields in Object 'Prod' c) Then creates 3 ...
0
votes
2answers
46 views

add error method returning a null pointer exception

In a before insert trigger I added an addError message, but the error message is not showing, instead I get a NullPointerException. This is my code: trigger ValidateNIF on Account (before insert, ...
-2
votes
1answer
52 views

setTargetObjectId

Apex code: public class Anu { //static method public static List<Booking__c> sendEmail(List<Booking__c> bookings) { //query on template object EmailTemplate et=[...
0
votes
0answers
31 views

Passing a validation function in JavaScript to apex

I have a function written in javascript to validate a field and i need to transform that function to a before insert trigger. I'm a bit of lost in how to do this. This is part of my function: ...
-1
votes
1answer
80 views

How to deal with caseTeamMember Trigger

I have a requirement to add user to case team and need to validate that user should be skilled resource and should have specific skills otherwise do not allow to add that user to case team. I was ...