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 [trigger]

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

0
votes
1answer
1k views

Trigger on OpportunityTeamMember has an error

Since there is no out of the box solution to send email notifications to users when they are added/removed from an Opportunity team, I wrote a trigger. So far I have code to handle the addition. This ...
1
vote
1answer
2k views

Opportunity Team email notification - Is Trigger the only way?

I have another situation that I need to write a trigger for and I am wondering if there is an out of the box solution I can use. Basically when a team member is added or deleted from an Opportunity ...
7
votes
1answer
7k views

Trigger behavior with Field Update

Well today while working with triggers I observed a weird issue. In my org I have a object called Demo__c and which has a standard "Name" field and another field called "TimeStamp__c". I have a ...
1
vote
3answers
8k views

How to get the opportunity owner name instead of owner ID

I am posting to chatter using an apex trigger whenever the opportunity stage changes to a certain value. The problem I'm having is that I'm trying to concatenate the opportunity owner name with some ...
5
votes
3answers
10k views

Trigger behaviour with insert and update in same execution context

I am writing an after insert, after update on Task object trigger. Both the insert code and the update code will make changes to records for a custom object which get updated. I would like to know ...
5
votes
1answer
761 views

Activate/Deactivate action on Product list

In the Product list table you have an Activate/Deactivate action links (the left column). When I click these the action does not fire the On Update trigger I have. If I implement a custom button to ...
1
vote
2answers
4k views

How to customize the error message thrown by approval process?

I have requirement where an user should not be able to submit a master record for approval until all the related child records are approved. Submit for approval button on approval history related ...
19
votes
1answer
13k views

Do changes to rollup summary fields cause triggers to fire?

If a parent record has a roll up summary field, let's say to calculate the number of line items on an opportunity, if a new line item is added (and hence the value of the rollup field is changed), ...
1
vote
1answer
2k views

how to Create Parent account using child account using trigger?

Can some one please help me on this? My requirement: Once child account is created, it's respective (parent) account should also be created using trigger. The parent account's name should be "XXX ...
0
votes
1answer
815 views

Test Coverage 93% how to Make this code cover to 100% [closed]

public class TriggerClass { public void Mycodecoverage(Branch__c Mycodecoverage) { string BankId = Mycodecoverage.Project_Bank__c; List<Bank__c> bank = [select id,project__c,project__r.name,...
8
votes
3answers
511 views

Control Fields vs Heap “Mock” Fields for Branching Trigger Behavior

I've seen solutions that talk about adding control fields to allow for clever trigger branching in problems like this. I know that works, but it annoys me (feels architecturally wrong) to create such ...
3
votes
3answers
2k views

Differentiate UI/Direct updates from Triggered/Indirect updates

I have a custom object (named Rewards) that 99% of the time is automatically populated by triggers on other objects (conditions that automatically grant said Rewards). But I've also exposed this ...
1
vote
3answers
3k views

Trigger Save Error - Variable Does Not Exist

I'm getting an error when saving the following trigger (it's my first). It says that on line 38, the variable gcamount does not exist. This makes me think that the scope of the variables within the if ...
7
votes
2answers
340 views

Delete of former parent in trigger causes workflow failure on child

I have a Lookup relationship from Contact to a custom object, and an "after update" trigger on Contact that deletes any of those related objects that no longer have children. There is a workflow rule ...
5
votes
3answers
2k views

Data loader - each batch a discrete operation/transaction?

I am currently designing a solution which will likely include upload (insert/upsert) of 1000s of records per upload. I am doing some calculations to evaluate how far the solution might be from ...
2
votes
2answers
2k views

Trigger to create task/email when Opportunity is updated with a certain stage

I am trying to create a trigger (possibly After Update) such that it is fired when an Opportunity is updated with a certain stage. It should create a task and send an email to a user. The email should ...
2
votes
2answers
477 views

Trigger for cloning isn't required for data loading

I have a 'Before Insert' trigger that was developed only because of the 'clone' functionality in SF. In our Managed Package if someone clones our custom object there are a number of fields that we ...
15
votes
2answers
732 views

Opportunity Management

This is my first post here on the StackExchange and hoping someone can help. I have been tasked with finding a way to prevent users from moving to 70% or greater probability in an opportunity when ...
6
votes
1answer
26k views

Checking to see if a value is present in a list - Apex

As a part of my first trigger, which is running on Opportunities, I have a list I created that contains the result of a SOQL query. Here is the code. List<Custom_Object__c> mylist = [SELECT Id,...
11
votes
3answers
48k views

How to define a map with id and list of records of an object

I have a custom object called entity_c, this has a field called product which is a lookup to product. There could be many records in entity_c for a particular product. I need to store it in a map ...
10
votes
4answers
10k views

Is there a function to check if a string value be converted to number?

I have a custom field called value__c in my custom object. This field can store values which could be a string, number, decimal or currency. How can i check if this particular value can be converted ...
2
votes
3answers
1k views

Options for callouts from triggers

I need to make some callouts from code that initiates from a trigger. I realize that you can't do a callout directly from a trigger. Currently what I do is make a future call to code that then ...
31
votes
5answers
18k views

How to generate a GUID/UUID?

What is the best way to generate a GUID/UUID from Apex code (such as a trigger)? Preferably in the following format: nnnnnnnn-nnnn-nnnn-nnnnnnnnnnnnnnnnn Example: 13219ec0-3a81-44c5-a300-...
46
votes
2answers
15k views

Lead Conversion Trigger Order of Execution

I've got a project where I'm looking to tweak the standard lead conversion process. Triggers and lead conversion has always been funky in past projects so I was hoping to start the design off by ...
2
votes
2answers
2k views

Basic Example of a Lookup?

I'm am having a ridiculous time finding basic Trigger examples (background: no official training, have books, have experience elsewhere, figuring this out on my own). I am trying to write an insanely ...
2
votes
1answer
365 views

What is the best workaround for the lack of the FeedItem/FeedComment trigger firing when you like a Chatter post?

Unfortunately SFDC decided to not make the relevant triggers fire when you like a Chatter post. It also doesn't fire if someone comments on a Chatter post (the FeedItem object has both a LikeCount and ...
5
votes
1answer
4k views

How to update Account object when related AccountPartner is updated/inserted/deleted/undeleted?

I am working on an org with Person Accounts enabled, but I think that my problem applies to regular non-person Accounts as well. I am tasked with writing a trigger to cross-populate spouse ...
2
votes
1answer
1k views

Test for delete success within Trigger context

I have a trigger use case that goes as follows: 1. On a junction object that joins two records of the same sObject type. 2. Junction object records reflects one direction of relationship (parent-to-...
0
votes
1answer
504 views

Regex NullObject in Trigger if run from Dataloader else works fine

Fellow developers, I have a call to an email validation function in my before insert in my trigger, which basically puts the email blank if its not valid (according to the regex) public static ...
6
votes
2answers
3k views

System.LimitException: Too many fields describes: 101

For the sake of my programming around this with a makeshift fix: Is this implying that I am trying to write to more than 100 fields at a time across multiple records..? Or even one record? I can't ...
1
vote
2answers
857 views

Avoiding Duplicates in Loop (inside other loops)

I have a complicated trigger (a labor of love for over 2 years now). I've recently discovered one of the problems in it. It ends up with duplicate entries in "updateList" to apply to SF (recently ...
1
vote
1answer
4k views

Time-based Trigger to update all records

If I want to "touch" (save, update) all records once a morning in an object (let's use Account as the example, though it would more likely be in a Custom object), how would someone go about that? To ...
1
vote
1answer
577 views

Display Self-Service fields on Contact Object

I would like to display Self-Service Portal fields on the contact object. I need the fields "IsActive" and "Last Login". Is it possible by trigger?
24
votes
3answers
9k views

Generically Walk sObject Fields

I've become quite comfortable with writing bulkified triggers that compare before and after values of specific fields. I've bumped into two cases where I'd like to do this generically for all fields. ...
4
votes
1answer
600 views

In Memory Init of sObject with Id for Update

Let's say I have a Contact, we'll say from Trigger.new. If I want to update its parent account, I skip a query by initializing it in memory like this. Account acct = new Account(Id = contactInstance....
2
votes
3answers
163 views

Updating a GROUP of accounts in lieu of ONE account (“update”)

I do not wish to paste the HUGE trigger this is related to (several hundred lines). However, a long time ago when it was first written, I believe it was MEANT to update "all accounts affected" with ...
35
votes
1answer
13k views

Infering sObject Type from Id or collection of Id's

If I have an instance of an Id variable that has been populated with a value, is there way to infer the sObject type of that Id using a describe call. So if I did: Set<id> parentIds = new ...
8
votes
3answers
9k views

How to bypass Validation logic in a Trigger

If I have a trigger that works fine (generally), but which is generating false results due to VALIDATION RULES, how can I tell the trigger to ignore Validation rules (if at all)? Scenario: Trigger ...
0
votes
2answers
748 views

Querying Tasks within a trigger

I am trying to query for others' Tasks within a trigger. (That is, retrieve Tasks whose OwnerId is other than the running user). I've reduced my query to the following: Task[] anyTasks = [SELECT Id,...
23
votes
2answers
8k views

How can I determine how many future calls have been executed in 24 hours?

I just ran into a huge gotcha in Salesforce: the 24 hr limit on # of future calls - cf. http://www.sundoginteractive.com/index.php?/sunblog/posts/governor-limit-gotchas-part-1-the-future-call/. I ...
2
votes
1answer
877 views

Trigger causes WEB BASED leads to be rejected?

Is there a resource somewhere that would help me figure out why a trigger I wrote is causing web-based leads to be rejected? I get an email containing each lead when this trigger is running. Or, ...
0
votes
2answers
748 views

UserMap, getting NAME for User, not ID, in Trigger

UPDATED 1pm EST: I am working with THIS line of code, where LEFT of the equals sign is NOT the issue, ONLY the usermap reference. I am trying to replace the OwnerID with the actual NAME from the ...
5
votes
4answers
5k views

What options are available to prevent duplicate entries?

I am working to help minimize the appearance of duplicate accounts within our Salesforce environment. One alternative I found was to create a hidden field as a validation check - if that field is set ...
2
votes
2answers
3k views

Determining user invoking action within Trigger

I recently had to implement some logic in a trigger to stop users from being able to add Attachments to a locked record of a particular type, and now I need to be able to create a "loophole" for a ...
2
votes
1answer
540 views

How Updating a Record's Parent Affects a Before Trigger That Pulls Data From Parent's Fields

I have a Before Insert, Before Update trigger on a custom object, Financial Account, that is a child in a master-detail relationship with Account. When the Financial Account is updated/inserted, the ...
1
vote
2answers
642 views

Question on Bulkification/Governor Limit of Code

Is the code below ready to handle bulk changes? Is there a limit to how many Accounts I can be bulk updating with this trigger active? Trigger: trigger transferRelationshipTeamFromAcctOnAcctUpdate ...
1
vote
2answers
1k views

After Insert Trigger on Email Message causing a problem in Case Assignment Rules

We have a after insert trigger on EmailMessage object to Capture "To Email address" (routing address) in Email To Case(We have 10 routing address). Whenever a Case gets created from Email to Case, in ...
1
vote
1answer
639 views

Help with a test for a trigger

The code coverage is good, and the trigger works when testing it manually, however, my system.assertequals statements are failing. the finAcc1.wealth_advisor_lookup__c (and the others) is null. Any ...
2
votes
4answers
1k views

Need help in my attempt to follow a 'best practice' for writing triggers

I have read that it is a considered a best practice when writing a trigger to have as little code as possible in the trigger itself, and to instead call a class from the trigger. I wrote a trigger ...
13
votes
4answers
17k views

How should I determine whether to use Before or After when writing a trigger?

The title pretty much says it all.