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.

0
votes
2answers
42 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
42 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
25 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
15 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
30 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
34 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
41 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
34 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
0answers
15 views

Test class for trigger with list and maps [duplicate]

trigger CloseActivityCopy on Opportunity (after update, before update) { Map<String,String> rejectedMap = new Map<String,String>(); Map<String,String> missedMap = new Map<...
3
votes
1answer
29 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
171 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
39 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
30 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
50 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
38 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
11 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
29 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
23 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
22 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
23 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
39 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
69 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
90 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
29 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
25 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
94 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
29 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
54 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 ...
-1
votes
2answers
64 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
52 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
76 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
49 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
357 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
48 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
49 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
39 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
31 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
30 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 ...
0
votes
1answer
90 views

Update existing AccountContactRelation in before insert trigger

I have a custom field on my AccountContactRelation object, called SurrogateId__c, that has to be unique across all AccountContactRelation. I have the following code that is called upon before insert ...
1
vote
1answer
29 views

How to test or replicate : System.QueryException: Non-selective query against large object type

In our org, there are 220k existing user record, Based on this previous code : public static void assignOwnerId(List<Inventory__c> invList){ List<User> userList = new List<User&...
0
votes
0answers
32 views

Trigger.new does not contain new value

I have a trigger where I want to lookup values in another table and populate a field. Why doesn't trigger.new contain the new value? The debug shows a null value even though I'm setting the ...
2
votes
1answer
39 views

Failure setting lookups in triggers when upserting multiple records of different types very quickly

I have an integration app that polls records of different types from an internal database every few seconds and upserts them into Salesforce. I have two pollers that run independently from one another ...
0
votes
1answer
182 views

Before update trigger is not working

I have two objects, which is used to populate the field value from product object to quote lineitem object. Both the objects have unique field name (CPQQuoteLineItem__c --> Product_Code__c, product --...
0
votes
1answer
31 views

Issue on creating auto number field

I need to create an auto number field on custom object in packaging org. I'm not able to create it now because it's throwing an error while creating it: you cant able to create auto number field ...
-1
votes
2answers
80 views

Is it possible to prepopulate field using a before insert trigger?

trigger MyTrigger on Benifit__c (before insert) { Set<Id> lookupIds = new Set<Id>(); for (Benifit__c b : Trigger.new) { if (b.company__c != null) { lookupIds.add(...
-3
votes
1answer
57 views

Apex trigger, return string, calling methods and code correction needed

Please explain what is wrong as I have problems writing methods, and correct the code if you can. Error: Compile Error: Variable does not exist: a at line 11 column 16 trigger tokenGenerator on ...