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

Questions tagged [before-trigger]

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

0
votes
1answer
23 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
19 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
21 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
47 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
28 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
36 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
48 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
26 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
38 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
38 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
204 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
38 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
35 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
33 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
26 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
47 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
26 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
28 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
37 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
91 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
28 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
69 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
49 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 ...
0
votes
2answers
32 views

Create list of records in Before and delete the list in After Context

I need to write a trigger on Case object where I need to delete the placeholder records and relate the case to existing records. I need to prepare the list of placeholder in before context and delete ...
0
votes
1answer
46 views

Random String Generator without duplicate values

What needs to be added (an SOQL query perhaps) in the 'else if' statement which checks the value within the c.Name column and tells if the generated random string already exists, and if so add break/...
0
votes
1answer
23 views

Can a Random String Generator create duplicate values, if so how to stop it?

I want to know whether this code can create multiple instances of the same random number by any chance? Can i make this specific field to not have same values within salesforce it self? trigger token ...
0
votes
2answers
56 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
2answers
223 views

update field with a trigger in custom object from pricebookentry

I have a custom object custom__c with couple of custom fields that needs to determine the price of the product. Custom_Child__c is a lookup field that gets the product. Price_Book__c is a lookup ...
0
votes
1answer
33 views

OrderTrigger: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object

I got stuck at one place on one of my requirement on which I am working on. My use case is as follows: SCENARIO 1: Close Opportunity when Upgrade Order is cancelled GIVEN a a person account record ...
0
votes
2answers
38 views

Test trigger before insert

I'm trying to test a test a trigger that adds an error if the field Active__c is set to true on CreditInfo_Eval_Rules__c (son of CreditInfo_Fields__c) and the field Used__c is updated to false. I'm ...
0
votes
1answer
53 views

SObject row does not allow errors: error updating record

i'm getting an error from updating or saving a record on the following trigger: trigger ActiveSave on CreditInfo_Eval_Rules__c (before insert, before update) { for(CreditInfo_Eval_Rules__c ...
0
votes
1answer
123 views

Using Maps instead of nested for loops in APEX

Hi i'm really new to Salesforce development in the following code I'm trying update existing record to inactive but, not the coming record on two different conditions. I'm a bit confused in the last ...
1
vote
1answer
26 views

How to test a change OwnerId by groupQueue.Id?

I have a trigger. If a user who creates a record isn't 'Manager' (UserRole.Name) - record's OwnerId change to GroupQueue.Id. I have a correct test method for scenario, where user-creator is 'Manager', ...
0
votes
1answer
46 views

State and country:There's a problem with this state, even though it may appear correct. Please select a state from the list of valid states

During the state and country activation for my instance, some state fields were set to undefined value. I guess it could not be mapped with any state. Even when I go into that record and try to update ...
-1
votes
1answer
51 views

If condition is met trigger will fire and clone the record to Salesforce Standard Object

TriggerHandler class: public static void onBeforeUpdate(Map<Id, Apttus__APTS_Agreement__c> oldMap, Map<Id, Apttus__APTS_Agreement__c> newMap){ List<Apttus__APTS_Agreement__c> ...
0
votes
1answer
76 views

Event and EventRealtion

I am trying to create an event and upon creation of Event i am creating EventRelation to add attendee. While creating Event i am prepopulation some fields in before insert. If i am prepopulation Type ...
2
votes
1answer
694 views

APEX Lock and Unlock a Record

I wanted to lock and unlock records based on a check box. I know that you can do this stuff via a validation rule but I think that is difficult to maintain if adding fields. I wrote an apex trigger ...
0
votes
1answer
36 views

Fire the Trigger only if record is being entered through classic UI not from the communities

I've a requirement that the Trigger should fire only when the Lead record is being entered through Slaesforce classic UI, Trigger should not be fire if the record is being entered by communities or ...
2
votes
2answers
104 views

Query becoming non-selective with null values

In the query I asked here - Confirm if sub-query is selective? , is there a chance of the top level query becoming non-selective if conAccMap.values() has null values? Below is the query: [SELECT Id,...
3
votes
1answer
73 views

Confirm if sub-query is selective?

I have a query in a before-update trigger that looks like following: [SELECT Id,(SELECT Id,Active_opp__c FROM Opportunities ORDER BY Days_from_Last_Stage__c ASC) FROM ...
1
vote
2answers
96 views

Why is my flag not working on maximum trigger depth exceeded

I have written a trigger for purchases if the purchase contains several of the same purchase detail items they should be summed up and merged as 1 purchase detail. When I use a before insert I get in ...
0
votes
1answer
123 views

How to write a trigger handler with trigger new [closed]

I am having some trouble to translate my trigger to a trigger handler how do I deal with the for(Invoice__c record:Trigger.new) part? Trigger: trigger UpdateAutoNumber on Invoice__c (before insert) ...
0
votes
2answers
73 views

Is it possible to executive Trigger before the lead assignment rules?

I Just want to know is there any way that we can executive trigger before the lead assignment rules. My Case: I have one before insert trigger in the lead, here in this trigger I'm checking company ...
0
votes
1answer
54 views

using the trigger framework for before update

I am using the SFDC trigger framework to force a particular field of the Order Object to be always the same. for example, if the the user enters on the field Status 'Active' I want to automatically ...
0
votes
0answers
24 views

Cloning Old Record Versions for a Parent Lookup

Composer__c object has a lookup relationship to the Song__c object. Song__c has a lookup relationship to the Song_Usage__c object. Song_Usage__c has a lookup relationship to the Event__c object. ...
-4
votes
1answer
89 views

How to capture first response on case via trigger?

I need to create a way to capture when the first response. I then need to measure how long time between when the Case was opened and when it was first responded. I created two fields: ...
0
votes
1answer
36 views

How do I stop my Trigger test from firing the Trigger twice?

I've got a trigger in place to count how many times a field has been updated: trigger IncrementClosedCounter on Opportunity (before update) { Opportunity[] oldOpp = Trigger.New; Opportunity[] ...