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
16 views

Populate Create By field from Assigned to User field

I don't even know where to begin with this trigger... I need a trigger that can overwrite the Created By field in my Task, with the Assigned to User (picklist) field I created. I've opened the Created ...
2
votes
1answer
346 views

Why does this apex trigger update a record twice?

I've been trying to troubleshoot this problem for awhile and haven't made much progress, so any tips / tricks / answers that you can provide will be appreciated. Description: When a Case object ...
0
votes
1answer
337 views

outbound message within delete trigger

The use case I am trying to satisfy is to create a notification when an opportunity is deleted. From my investigation, I believe I cannot do this out of the box using a workflow. So I created a ...
-1
votes
1answer
26 views

restrict user to edit the notes using the trigger on ContentVersion

Please help me with this. trigger ContentVersion_PreventUpdate on ContentVersion (before update) { Schema.DescribeSObjectResult inv = customobject__c.sObjectType.getDescribe(); String invKeyPrefix =...
0
votes
1answer
32 views

Best approach for handling preventing Parent trigger when updated from multiple child objects

I need some suggestions in improving the 'prevent trigger' logic. I have parent 'Lead' object and couple of child objects. I have Trigger Helpers on each of these objects. When these child object ...
0
votes
1answer
47 views

Possible to send negative values? [on hold]

I have a set of number fields on accounts that roll up totals in a hieararchy. I was given a requirement to create a class/trigger that fires if an account is changed from active to inactive and sends ...
3
votes
4answers
17k views

Trying to create a trigger to prevent creation of duplicate accounts

This is the trigger i have wrote to prevent the creation of duplicate accounts, i am getting an error message saying "Intial term of field expression must be a concrete SObject:LIST ". Can someone ...
2
votes
0answers
38 views

Invoking trigger when an answer is marked as Best Answer in Chatter

I am trying to invoke a trigger when an answer is marked as 'Best Answer' in Chatter Question. I tried a trigger on FeedItem and FeedComment objects, but the triggers were not invoked when I mark an ...
0
votes
1answer
331 views

Trigger to get Prior value of last activity date on opportunity

I have custom formula field return type date Last Activity age on opportunity. I want to capture last to last Activity date. So I create workflow with "created and every time edited" and formula ...
1
vote
1answer
332 views

Need to send email Notification whenever a knowledge article is published in real time

Requirement:Neet to send email Notification whenever a knowledge article is published in real time. I am not able to understand how to do it
1
vote
3answers
332 views

Opportunity Trigger After Update doesn't work

So here is the scenario, I want to have an error message when user click Save after he changes Opportunity Stage from 10% Probability to 20% probability. I am using Related list Object Contact Role so ...
-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<...
1
vote
2answers
315 views

Check parent field is null before inserting child record

As per my requirement,I need to check whether phone field of account object is null before inserting contact.If it is null,I should not allow user to create contact.I created trigger for this scenario,...
1
vote
1answer
101 views

Trigger to update parent's field

I have a requirement: 1) Match field(number) is created on name 2) Opportunity Match(number) is created on vehicle. 3) Develop a trigger :: 1) on Insert - The value in "Opportunity Match" field ...
0
votes
0answers
25 views

Auto approve record when it is submitted for approval

I try to approve next step of approval process automatically, when submit for approval button is pressed. So, when the button is pressed, it updates two fields on record and then trigger is run. I try ...
-3
votes
1answer
27 views

Trigger on custom object to send email after uploading all the mandatory documents [on hold]

trigger MandatoryDocumentsUploadedEmail on Verification_Documents__c (after insert) { if(Trigger.isAfter){ if(!Trigger.new.isEmpty()){ Set<Id> oppIds = new Set<Id>()...
0
votes
0answers
10 views

Trigger when record has updated after chatter post through feeditem class to GROUP ID OR MENTIONS

A MAIN GOAL : TO ALARM ON EACH USERS IN A GROUP FOR RECORD UPDATE (NO PLATFORM EVENTS) API 44 or higher Hello i want to post a article to chatter group members, but i tried to put group id to the ...
0
votes
1answer
27 views

Create Notes(content documents) preventing the edit and Delete on notes

i need an option to create a note preventing the edit and delete on notes for a particular custom object. i wrote a below trigger .. but it is restricting to create a note also. trigger NoteTrigger ...
3
votes
1answer
25 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 ...
0
votes
1answer
29 views

SalesForce Marketing Cloud journey exit as trigger to enter new journey?

To simplify a rather large/complicated journey, we'd like to split it up into 4 mini journeys, with contacts who exit one journey a certain way automatically moving to the next journey. Is the way to ...
1
vote
2answers
138 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
54 views

Question About Decrementing Numbers

My class that utilizes this LREngine utility class aggregates numbers up a hierarchy. The problem I'm facing is that when an account is deleted the number fields are not subtracting values from the ...
0
votes
0answers
25 views

Picklist Toggle [on hold]

This class and trigger aggregate the total of values in number fields on accounts in a hierarchy. It does not take into account contacts that have been submitted as inactive but the user will have the ...
0
votes
1answer
345 views

AutoFollow using EntitySubscription

I'm trying to write a bulkified logic for a problem on entity subscription. I've a custom object Student which has custom lookup field to User named as Mentor. The use case is when the mentor field is ...
-3
votes
0answers
18 views

Trigger on Task to Update Custom Fields on Account [on hold]

A task gets created from Contact and the under the activity history of both contact and Account the record gets saved. Though the related to field is blank, the account also has the activity. On ...
-2
votes
0answers
22 views

Deleting a child in master detail will fire a trigger on parent [duplicate]

So, in case of MD relationship, if we delete a child record, does that fire a trigger written on parent record. Please elaborate in both yes or no. Edit : Roll up summary from child updates the ...
0
votes
2answers
29 views

Display child trigger error in friendly way on parent record page

Example When updating an Account record, it fires an Account before update trigger which changes a child Contact record, which fires a Contact before update trigger, which validates the change and ...
0
votes
0answers
30 views

Create a Visualforce page in Apex Test Class [on hold]

I need to test a trigger that is not relevant here. To test the trigger I need to create an object in a test class that got the iD of a Visualforce Page as a required field. How can I create a non-...
1
vote
3answers
347 views

Updating Lookup field using Trigger

I have posted a question before, but I think my code is completely wrong and I have started in the wrong direction. This problem should be so simple... So, I have the following setup: Account: - ...
-1
votes
1answer
22 views

Update Earliest created Contact On Account

I have a scenario where Account is related to contacts through lookup relationship. I have a field on Account called Account_Start__c(Date) and a field on Contact called Contact_Start__c(Date). Now i ...
0
votes
1answer
14 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
3answers
49 views

Trigger for avoid insertion from data loader? [closed]

i have scenario like write a trigger avoid insertion of records from data loader,only manual insertion trigger will fire?on any object while Entering records from data loader trigger should not ...
0
votes
2answers
36 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, ...
1
vote
2answers
639 views

Associating new contacts/cases with an account?

So I'm trying to associate new contacts and cases with an account automatically. I've been creating contacts and cases without an account using an automated script. I understand that at this point, I ...
0
votes
2answers
480 views

addError for multiple validation messages on the same record before insert trigger

In before insert trigger I need to verify couple of validations for which I have written 2 methods - Method1(casesList) and Method2(casesList). Both methods operate on the same list of cases in before ...
1
vote
1answer
340 views

how i can create an inventory (custom obj) as per the quantity of opportunity line item?

How i can create inventory custom child object by trigger under opportunity, because child object cannot be created for opportunity line item. inventory will be created for each line item example-...
0
votes
2answers
344 views

Serialize and deserialize the List<sObject> in APEX

How to serialize and deserialize the list of sObjects in APEX. I tried to serialize the list of sobjects like this . JSON.serialize(Trigger.New) This is returning a json array of objects like the ...
0
votes
3answers
342 views

update contact customfield when opportunity is created or updated

I am quite new to Sales force I need to update a custom field on contact using total_amount_c when ever any opportunity is created or updated with stage 'Closed-Won' , opportunity amount value is ...
-1
votes
0answers
28 views

Create New Support Trigger is not creating new Record, when condition is meeting [closed]

I created a custom setting to store all the record type for which I have to create new support case when case status is change to certain status .new support case will take the value form the custom ...
0
votes
0answers
9 views

Partner Email sending to the wrong email address

When a partner replies to a provisioning case email, it sends the reply to the EI case owner whom it was assigned to rather than the provisioning team, looking through the code I can't see any ...
0
votes
0answers
26 views

is there any possibility to assign id to lookup field at run time based on the type of lookup field?

Can any one suggest me the possibilities to assign parent id to the lookup field of child at run time. I have a requirement to assign related list to parent record whenever the child record is created....
-2
votes
1answer
50 views

Salesforce Trigger.isAfter problem? [closed]

if a same contact already exist against to account then the contact should not be added. if a same contact does not exist then the trigger should check if the account's shippingaddress equals to ...
-2
votes
1answer
20 views

before trigger on ContentDocumentLink throwing error-Error: Null pointer exception-Attempt to reference null object- [closed]

trigger tesDocUpload on ContentDocumentLink (before insert) { List<string> strIds = trigger.newmap.keyset() ; List<ContentDocumentLink> lstContDoc= [Select Id,ContentDocumentId ...
0
votes
0answers
19 views

fast access object storage

Lead routing is a common task, the problem in my case that routing rules must be described as sObject, so APEX script should read it and convert into some mapping rules. The problem that 'static' ...
0
votes
2answers
384 views

variable does not exist for every trigger in my account

Hi in my account every trigger throwing same error Error: Compile Error: Variable does not exist: website at line 4 column 1 Example: trigger websiteass on Account (before insert) { for(...
0
votes
2answers
28 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
0answers
13 views

Apex - Chatter Link to Record

I have been trying to create a chatter post that will fire on task creation using the ConnectApi & the following git repository:https://github.com/forcedotcom/ConnectApiHelper What I have so far:...
1
vote
1answer
354 views

Trigger After update after insert error message

I am getting an error message when trying to use an after update, after insert trigger, the code exists within another class Trigger: trigger Identity_Set_Contact_Name_Text on Identity__c (after ...
1
vote
1answer
34 views

Help fixing trigger/class for Campaign lookup fields

I have a couple of custom Campaign lookup fields on the Contact object called First Campaign and Most Recent Campaign. These lookup fields need to get populated with the ID of the appropriate ...
0
votes
0answers
16 views

ID of an approval request?

Is it possible to do something like: Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setComments(quoteObj.Sales_Rep_Comments_for_Approval__c); req.setObjectId(quoteObj.id)...