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.

1
vote
1answer
76 views

Test Class for Trigger before insert before update

I am very new to APEX and I have written the following trigger that updates the due date on a case based upon an SLA value stored in another object once the user fills a value in a lookup field ...
1
vote
1answer
19 views

How to redirect to a custom VFP after a Custom Object record is created (Standard way of insert)?

well, pretty much as the title says. I need the user to be redirected to a Custom VFP when a new record of a Custom Object is created, additional to this I need to be able to send the Id to that ...
0
votes
0answers
33 views

Is it possible to do two DML operations in a single trigger?

I have a custom object called Junction__c with lookups to Custom__c, and Case. In the data model, Custom__c is also a child of Case. There is a validation rule to ensure that any Custom__c record ...
1
vote
2answers
67 views

Cannot move query outside of FOR loop?

REQUIREMENT: Need to move the query outside of the FOR loop in Opportunity trigger. PROBLEM: After moving query outside of the FOR loop, I receive an error when trying to save a new Opportunity ...
-1
votes
0answers
25 views

Validation Trigger Issue [duplicate]

I have a previous validation rule that I made into a trigger that isn't working. The validation rule formula is: AND(ispickval( Status, "Trades Needed*"), ISBLANK( Financial_Account__r....
-1
votes
0answers
43 views

INVALID_FIELD, All accounts must have the same current owner and new owner

We have a trigger on Account (in before insert and before update context) that updates the owner of the account based on the market. We also code in the trigger which populates a custom field (in ...
0
votes
1answer
20 views

Error While Saving the Class [closed]

Error: Compile Error: Variable does not exist: lstOppotunityToUpdate at line 34 column 17 Code: public class QuoteLineItemTriggerHandler { public static void syncQuotes(List<QuoteLineItem&...
0
votes
1answer
39 views

Remove Components (Process builder) From Managed released package

I have a situation. One of Our client is using Professional edition. But our managed release package has a Process builder with APEX invocableMethod in it. Professional Edition will not allow any Apex ...
0
votes
1answer
33 views

Salesforce send Email by Apex

I'm making by a requirement a code able to send an E-mail to an specific list of E-mails, due the fact that I must to include the attachments of the record I decided to use an apex class instead an e-...
2
votes
3answers
530 views

Why does Salesforce has Trigger.isInsert or Trigger.isUpdate when Trigger.old !=Null would have worked?

Salesforce has context variables like Trigger.IsInsert just to understand if trigger is running for Insert scenarios. However, we could always have got this information by doing the NULL check on ...
1
vote
1answer
36 views

First error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Use-case: Trying to update a text field after an insert. Also trying to get the Record Name field(text field) to a specific format using another auto generated field and a picklist field. Simple ...
0
votes
0answers
44 views

Auto child record on self lookup relationship

I have a self lookup relationship on a Custom object called Output. I want to auto create a child record when new record is create, and update the child record when parent is update, the criteria to ...
0
votes
0answers
35 views

Validation rule before publish article

There is a approval field on my knowledge object and there is a approval process which changes this field to approved upon approval. I don't want article to be published when 'approval' field is not '...
0
votes
2answers
56 views

Execution AfterInsert caused by: System.FinalException: Record is read-only:

I am creating record in energy object and have to update a field with user entered value + static value while creating and updating . trigger testews on Energy__c (after insert,after update) { ...
1
vote
1answer
24 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
1answer
65 views

Trigger not updating checkbox properly

My Opportunity object has an child object P_ODR__C. Opportunity obejct has checkbox field Nd_Check__c. I am updating it by trigger. I have a trigger on P_ODR__C updating checkbox on Opportunity ...
0
votes
0answers
27 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 ...
3
votes
1answer
378 views

Custom Logging and Future Methods

I have been reading up on the custom logging, DML, and exceptions but haven't seen anything that talks about @Future methods and exceptions. I have two scenarios: A Button is clicked on a Lead, ...
1
vote
1answer
47 views

I have written one trigger for update child records count on parent record and it's working fine but I want to know my approach is correct or not?

Trigger Trigger ContactCountTrigger on Contact(After Insert, After Delete , After Undelete, after Update) { ContactTriggerHandler cth = new ContactTriggerHandler(); if(trigger.isAfter) { ...
0
votes
1answer
22 views

Disable duplicate check for apex trigger?

I have an issue where in Duplicate Rule(Alert) on contact is blocking creation of contact , so issue is that a Trigger which is part of managed package is tripping because of Duplicate Rule Alert , ...
0
votes
1answer
21 views

this.isEnabled(MethodName) in APEX Class

I'm going through some old APEX classes implemented by a fellow developer who has already left the company and having some difficulties to understand in a trigger helper class where trigger is not ...
0
votes
2answers
46 views

Calling a Class from a Trigger (calls external service)

I am at my wits end with Future Methods coding and would be very grateful for a working example. I've been reading through the Future Methods documentation here: https://developer.salesforce.com/docs/...
0
votes
2answers
28 views

Aggregate Results In A Trigger

Hi Friends I had a question about using aggregate results in a trigger. So far my code seems to be working with single records in the UI and passing its assertions. But I feel like I am either missing ...
1
vote
2answers
34 views

Error while Saving the Quote

Error: Invalid Data. Review all error messages below to correct your data. Apex trigger QuoteTriggers caused an unexpected exception, contact your administrator: first error: ...
1
vote
4answers
133 views

How to update a record in a trigger with value from a REST API?

When an account is saved I need to update it with value from a REST API. I though my approach would work but I'm getting the following compilation errors. Method does not exist or incorrect signature:...
1
vote
1answer
27 views

Fill lookup on task with ID from 'Related to' Object in Trigger

When a new Task is inserted(before insert) I want to get a lookup field from the object in it's 'whatId'(related to) and assign that to a lookup on the task. This is what I have, I'm pretty sure there ...
-1
votes
1answer
33 views

on trigger upsert: if value not found in select , create a new row in different object

I am having a beastly time trying to in a trigger, check the oldmap vs new map, if a certain value exists, check for existence of a row in another object, if that row exists update, otherwise insert a ...
0
votes
1answer
29 views

Trigger to auto sync a Quote When Check box is checked [closed]

I want to write a Trigger to sync a Quote when checkbox is checked, that check box is created as a custom field in a quote.
0
votes
1answer
16 views

Give delete access to records of particular users without 'Modify All' using apex

I want to give delete access to some set of users in certain condition to some records. I don't want to do this using profiles/permission sets. I want to achieve this using apex. Could anyone please ...
0
votes
1answer
21 views

Is there a certain way you need to call targetObjectId?

So normally I would send an email by normal means and without code but I need to do a query on our Team__c object to find out who I would need to send it to. I am trying to send an email to any "squad"...
0
votes
1answer
30 views

Custom settings in Managed package

We have a managed package and include some triggers.We have to give a option to stop a trigger in subscriber's org. Could someone please suggest us the following option is good or not. Create a ...
0
votes
2answers
30 views

Batch Apex Limits in a trigger

In the trailhead lesson "Use Batch Apex" the final line states: Use extreme care if you are planning to invoke a batch job from a trigger. You must be able to guarantee that the trigger won't add ...
0
votes
1answer
30 views

ContatctoAccount: System.LimitException: Apex CPU time limit exceeded

I have a code which executes when a new contact is inserted or updated. But when i tried to insert bulk contacts through data loader, the system is throwing following error "ContatctoAccount: ...
1
vote
2answers
32 views

Trigger to find largest Opportunity by amount & update custom field on account with its name

I wrote a trigger to find the largest amount value for all Opportunities under a particular Account and then update a custom field on Account with the name of the Opportunity. It works fine with ...
0
votes
1answer
46 views

Too many SOQL queries 101 with 5000 records [closed]

I have a trigger which I believe is correctly bulkified, but when I try and insert 5000 records, in a test, it comes up with 'Too many SOQL queries'. What I think is happening is that the trigger is ...
0
votes
2answers
32 views

Add second element of map (multiple same ID)

I wanted to know how to get the second element of my oppTeamMemberWrapper map knowing that its ID exists in several times in the wrapper map (the ID being the ID of the parent opportunity)
0
votes
1answer
17 views

Trigger - Get all occurence of map in same get

I have a map map like that and I wanted to know if I could get all the occurrences of my key in one and the same list (without making a loop). Would you be able to do that? @future public static ...
2
votes
1answer
51 views

50,000 Row Limit

I have a method that gets a count of contacts associated with a custom object Region__c and then gets a count of the tasks assigned to those contacts. If I run an update in Data Loader on Region__c I ...
0
votes
2answers
23 views

I have requirement where i need to disable validation rule to avoid deployment errors

I have requirement where i need to disable validation rule to avoid deployment errors. I have added a custom setting and my rule is below AND($Setup.cust_setting__c.ValidationsOff__c=FALSE, (ISBLANK(...
1
vote
1answer
36 views

how to prevent duplicate values

I am using below helper class in a trigger and it just updates a value in a field name NSID__c field in the Contact object now it should add a unique value every time a record is inserted but ...
0
votes
2answers
57 views

Apex Trigger Handler - Sharing permissions

We update some objects in our trigger handler, the user does not have access to these objects. We want the trigger handler to run in System mode. Should we have the 'without sharing' keyword on the ...
0
votes
1answer
48 views

Why does the trigger always read my if statement as null? [duplicate]

See the code below from an APEX trigger. For some reason, my trigger always reads nextRenewalDate (field from Account object) as null, regardless of whether or not it is blank. Racking my brain here ...
0
votes
1answer
36 views

SOQL limit Error with task dataload

I am receiving System.LimitException: Too many SOQL queries: 101 error because of my Apex trigger. Issue is clear but I am thinking of best possible way to handle it during bulk data loads. We ...
0
votes
1answer
35 views

Attempt to de-reference a null object validation

I'm converting all our validation rules to a trigger to free up a couple object references since we've reached the max. I seemed to have created the trigger okay, but now I'm having an issue of ...
-2
votes
2answers
53 views

How to insert Lookup field value in a Trigger?

I am trying to build a after insert trigger on Contract object. Whenever user will create a Contract record trigger will generate/insert record of other object called Dim2. Dim2 have a lookup with ...
-2
votes
1answer
24 views

Test Class for my Trigger [closed]

I am completely lost at writing a test class for this trigger to give it code coverage. It's a trigger that does a checkbox on a custom object Involvement__c after a File has been uploaded. That ...
0
votes
1answer
55 views

Restrict update existing record while upserting from Data loader

I am going to load data using WorkBench/Dataloader using UPSERT (ExternalId__c) DML operation. Once this ExternalId__c is matched then we have to check one more thing like Sr_number__c in that ...
0
votes
1answer
72 views

Trigger Handler class variables

we follow the pattern Trigger-Trigger Handle. Inside the trigger handler we have a class vaibile of type RecordType that we define and instantiate immediately. I'll show you the code: Trigger: ...
0
votes
1answer
32 views

Trigger to Roll-up on lookup relationship

I have a lookup relationship between Contract(Parent) and Expenses__c want to summarize the value of the field called Amout in Expenses__c to a custom field in Contract called Tot_instalment__c. ...