Stack Exchange Network

Stack Exchange network consists of 175 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

Questions tagged [before-trigger]

Before triggers are used to update or validate record values before they’re saved to the database.

-1
votes
0answers
14 views

Lead Reassaignment. Can we do this with one trigger and class Combination [on hold]

acitve --> No Chnage inactive - > user --> manager is active --> assigned to manager inactive --> user --> manager is empty --> assigned to unassigned inactive --> user --> manager is ...
1
vote
1answer
21 views

Trigger addError('blah') -> Lightning Components JS alert('contense of addError('blah')')

I am sure my Title does not help much, but not sure how to shorten this question concisely. I have a Lightning Component that has the ability to update a case record. I have an APEX Trigger that ...
-4
votes
0answers
42 views

as per my requirement, I have to create only three contacts with the same accountid [on hold]

First contact I am taking Member as Gold and second Contact I am taking Member as Platinum Third contact I am taking Member as Silver In the third requirement, if I take silver as a member I need to ...
0
votes
1answer
25 views

Update a master-detail lookup using a before trigger and the name of the parent record which is a concatenation of fields on the child record?

I have two objects - Customer Visit Quota and Contact Report. The contact report object has a "Number of Visits Field" that should roll up on the Customer Visit Quota. I have a master detail look up ...
0
votes
1answer
17 views

Populate contact field based on email

We're doing a demo of Survey Monkey and can't seem to get the contact populated from the form mapping. My solve for this would be to make a trigger that looks at the required email field and finds a ...
0
votes
1answer
25 views

Insert new contact share if account owner changed

I made a trigger to insert new contact share (user) if the account owner is changed.. and I want to insert new contact share without removing all previous contact share (old account owner/contact ...
0
votes
0answers
33 views

Problem with saving the record on the before insert trigger! Help! [duplicate]

So, I have field called name on my custom field and I am writing a before trigger insert trigger to copy the name of the other lookup field into the name field which is a standard required field and ...
0
votes
0answers
49 views

Before Insert, Before Update Trigger

I have a trigger that runs on before insert and before update using trigger.new. I am sending data in batches, so the tirgger.new holds multiple records, some inserts, some updates. I also have some ...
0
votes
0answers
36 views

Opportunity Trigger with Upsert

I have an opportunity trigger that runs before insert and before update. It has a recursive check on the before update and a separate one on the before insert so that each only run once. I am pushing ...
0
votes
2answers
58 views

Restrict overlapping dates of Opportunities with Trigger

I have an Account and Opportunities for it. These Opportunities have time intervals: Start Date and Close Date. I want to prohibit the creation of Opportunities whose intervals overlap with the ...
-2
votes
1answer
45 views

how to aviod soql query in the loop , i have to get get child data in my method

I have 2 object object1 and object 2(related object) ,,,i wrote trigger on object1 when object 1 record gets created user record should get created.. i stored profile perssion set information in ...
0
votes
1answer
46 views

Unable to save the Lead record since Company is a standard required field in salesforce before insert trigger

I am trying to copy the value of user selected Status value into the standard salesforce required Company field. Now, when I try to save the record on the object since I am not entering any value in ...
-1
votes
1answer
31 views

Before insert trigger failing to autofill Title field with the selected Status field value in Salesforce

So, I have created a trigger which autofills the selected satus value into the title text field in the lead object but I am getting a DML exception. Can someone tell what is wrong in this ...
2
votes
1answer
32 views

Error not bubbling up from delete trigger

I need to prevent deletion of our dummy account, which is part of the Lead conversion process under certain conditions. And it does prevent deletion. However, the error I am adding to the account ...
0
votes
1answer
36 views

Null reference error in trigger on required field

I have this trigger that changes the Name of a record based on a custom title__c field: trigger assignDegreeName on Degree__c (before insert) { /** Variables **/ integer maxSize = 80; ...
0
votes
0answers
65 views

Inserting record on Junction object with formula fields

I have Junction object called Agreement Scope which has two Master Detail relationships with Account and Agreement. We are assigning Account and Agreement in the lightning components Apex Controller ...
0
votes
1answer
36 views

Variable does not exist: StageName what is preventing from saving my apex class which i am calling from apex trigger

This is my Apex Trigger trigger OpportunityUpdateTrigger on Opportunity (after Update,After Delete,after Undelete,before Update) { if((Trigger.isAfter) && (Trigger.isDelete)) { ...
3
votes
1answer
35 views

Does adding a detail record cause an update event on the master record?

Background I have a master-detail relationship between two objects, let's call them: parent__c child__c Once the parent__c record is in a certain status__c we block any changes using a before ...
1
vote
2answers
269 views

Why do we need to update related records in an after trigger but not before?

Why do we need to write the logic to update a related record in an after trigger but not before? Update triggers(Before/After) will have both the record ID and the related record's ID so why can I not ...
0
votes
1answer
16 views

'ExceptionOfBeforeUpdate caused by System.finalException: Record is Read Only' on a BeforeUpdate

I am getting this error Record is Read Only on my Before Update trigger... I know you get that error on an After Update when you try and change something, but not a Before Update. trigger ...
0
votes
1answer
45 views

Generating a random unique token inside a trigger using a method from a separate class [closed]

I'm using a random string generator code, which I found online. I need to know how I could access this code inside an Apex trigger from an apex class. I have pasted both my trigger and class, but I ...
0
votes
2answers
36 views

Update existing records with before trigger [closed]

I need to update the fields of a few records (around 20) that were existing before I made a trigger. I know that before triggers cannot update existing records (or can they ?) but I think that using ...
0
votes
2answers
51 views

Field of new records not updated by trigger

I'm new to apex and trigger and have an issue. I need to update a field on a record when 2 other fields are updated. This field is supposed to calculate the time between 2 dates based on the business ...
0
votes
2answers
41 views

Need to Understand Apex trigger soql execution on each events

I have a trigger handler as shown below (Please Ignore any Syntax errors) trigger AccountTrigger on Account (after delete, after insert, after undelete, after update, before delete, before insert, ...
0
votes
1answer
12 views

Requirement is to write trigger to restrict duplicates for week

Requirement: Restrict duplicate accounts for current week. Error : Compile Error: Unexpected token 'weekStart'. at line 16 column 121 Trigger Code: trigger DuplicateTrigger on Account (before ...
0
votes
1answer
35 views

Recursion in Trigger and Process builder

I have a before update/insert trigger on Contact trigger ContactTrigger on Contact (before insert, before update) { for(contact con:Trigger.New){ If (con.FirstName ==con.LastName){ ...
-2
votes
2answers
25 views

Whenever an account name is modified send an email notification to the contact of an Account

Trigger is not go into the If Condition and Not compare Value. How to comapare oldAccount Name is notEqual to ModifiedAccount Name? And How to write query for the Id to compare the Name in the code.If ...
0
votes
0answers
25 views

Trigger on Attachment object not getting fired after attaching file in an outbound Email [ Related List ]

Trigger on Attachment object not getting fired after attaching file in an outbound Email. Tried both before insert and after insert. Attachment trigger fires while attaching files in the Notes and ...
0
votes
1answer
28 views

Event WhoId field is not retrieving all contacts on field

I'm working with standard object Event and, when saving two or more contacts on WhoId field it only displays via SOQL query or trigger the first one. Is there a way to get all the contacts saved on ...
0
votes
1answer
41 views

Efficient SOQL for record classification

I need to "classify" an incoming Record A based on several related fields on records B,C,D,.. etc. Therefore I need a trigger that is triggering (:D) on this new record and check more then 5 lookup ...
0
votes
0answers
15 views

User Trigger to Assign Lead Lookup not firing [duplicate]

I'm a bit stumped as to why this isn't firing. It's supposed to work when a User Lookup field called ISR_Owner__c on a User record is updated it will try to find all Leads owner by that User. It will ...
1
vote
0answers
168 views

Making approval comments mandatory - different behavior Classic vs Lightning

I am trying to make Approval Comments mandatory for the Approver while Approving. I was using the following apex trigger, approval process steps and workflow field update as per the following blog ...
0
votes
1answer
171 views

Why is (Trigger.isInsert && Trigger.isAfter) not firing when running test class?

THE PROBLEM: My CustomObjectTrigger has a CustomObjectHandler class. I have code that is fired in the CustomObjectHandler class when the CustomObjectTrigger is fired by a new record that (isInsert &...
0
votes
1answer
36 views

Delete Duplicate Opportunity Record, Keep Original Record

My goal is to write an apex trigger that will delete duplicate Opportunity Records based on the Opportunity Name but retain the first record that is created. I believe a before trigger would be the ...
0
votes
1answer
27 views

Trigger to Update a Parent Record based on a value in a child record

I need to update the Order record when it's status changes to Activated. I want to set the custom field, invoice_Due_date__c based on a related record's value. The related record is child record in ...
0
votes
1answer
159 views

testclass for triggerhandler [closed]

I am new in the apex and I don't know how to started to create a test class for apex trigger handler. So those anyone here how to create a sample test class of my apex trigger handler small idea may ...
0
votes
1answer
30 views

update a field on contact once i associate a account

i wanted to update a field on contact once i associate a account. once accountcontactrelation is created i am checking if that relation role is Manager and if yes then only i wanted to update a ...
0
votes
2answers
73 views

Trigger to prevent duplicate combination of 3 fields on insert and update

We have 3 picklist fields Dom1, Dom2, and Dom3. We want to write a trigger before insert and update to prevent duplicate records with the same combination of these 3 fields. For Example: Dom1 ...
-1
votes
1answer
26 views

How to invoke controller setter method in trigger beforeInsert()?

That is my VF page: <apex:page standardController="Lead" extensions="LeadDuplicateController" tabStyle="Lead"> <apex:pageBlock > <apex:pageBlockSection title="Lead ...
-2
votes
2answers
81 views

trigger to Preventing the users to create Duplicate Accounts im getting Variable does not exist: Name error

trigger AccountDuplicateTrigger on Account (before insert) { for(Account a:Trigger.new) { List<Account> acc=[Select id from Account where Name='a.Name' and Rating='a.Rating']; if(acc.size()&...
0
votes
2answers
76 views

PrePopulate Task with related data even before creating a Task

I am trying to populate the Task with related data even before creating a task. For example in this Task creation, I have RelatedTo(Loan) autofilled, similarly I want LoanNumber and ClientName to be ...
0
votes
1answer
111 views

VF page with dynamically generated HTML code?

I have a custom VF page which is added to a section in the page layout of an object. What I'd like to achieve is to add dynamically generated HTML code to my custom VF page. The HTML is dynamically ...
0
votes
0answers
59 views

Can System Admin bypass required (lookup) fields?

A user was trying to create a child record but they were getting an error because of other associated record has a required (lookup) field blank. But i was able to create it when i tried as system ...
3
votes
4answers
453 views

|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object on my Apex Trigger

I'm kind of new in Apex development and I'm writing a before insert, before update trigger to a custom object that is going to be upserted through an API integration. Is very basic code but I don't ...
1
vote
1answer
15 views

custom settings to set event reminder

I'm trying to put (-60) value in the reminder time. it works but it is hard coded. I want it from custom settings so admins could edit the numbers from the GUI. trigger setReminderEvent on Event (...
2
votes
1answer
51 views

Trigger not updating Lead.State before update/insert (state/country picklist use case)

We are using the Salesforce State/Country picklist and the integration values used for US States are state codes, e.g. CA, WY, AL, etc The salesforce AppExchange sends the leads to Salesforce and it ...
0
votes
1answer
63 views

Ignore validation on before update/insert trigger?

I have a before insert/update validation trigger which I would like to be able to ignore when doing mass updates via data loader. Figured if I just add criteria of "checkbox field = true, ignore ...
0
votes
1answer
47 views

Trigger in working as expected in inline editing , But it is not not working when I click the edit button

Hi Folks I have a requirement to copy the case contact id to the task (WhoId) Field. Logic I implemented. 1: Check the task whatID is not blank and the whatId starts with 500 (Case Prefix Which ...
0
votes
1answer
33 views

Prevent Record Update Synchronously via External HTTP Call

I'm integrating Salesforce with an external system, and updates to records in Salesforce need to be kept in sync with the system. If the request to the external system fails, the update in SF should ...
0
votes
1answer
31 views

Updating records when related record is inserted

I have written at shipment insertion to update the shipment's expedited checkbox to be true, and then in the after trigger, it should update all the packages that have the newly created shipment to ...