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

Trigger creating multiple records where i need only one?

I have created a trigger(after update) on Lead which will fire on status change and create a contact and custom object record. Issue is that trigger is working but creating around 7 records of ...
0
votes
1answer
15 views

How to create round robin lead assignment for certain lead status value and lead source?

I have done the setup listed here (https://help.salesforce.com/articleView?id=000004000&type=1) for round robin lead assignment, but 'd like to do a lead assignment based on two criteria: the lead'...
1
vote
1answer
35 views

In a Trigger, is there a way to find if SObject.addError () had been used?

In a trigger you use SObject.addError() to mark a record as not fit for processing. This information can be evaluated outside of the trigger as an exception, but is there a way within the trigger to ...
1
vote
1answer
16 views

Is there any way to send an in Org Notification to authorized User, when Opportunity Record has Updated

Hello I'm trying to write a trigger when any fields of Opportunity__c (It is Custom in our Org) has updated , check the User's object Permission and Send relevant user for in org Notification Like : (...
1
vote
2answers
841 views

Complicated FOR loop nesting. Having trouble cleaning up legacy code

I am trying to tidy up some really bad legacy code from an old developer and I'm trying to get rid of these nested for loops. The code below shows what I'm currently working with. I've fixed this ...
1
vote
0answers
24 views

How add a ServiceReport to a test class [duplicate]

trigger ServiceReporttoSA on ServiceReport (after insert) { for (ServiceReport SR: Trigger.new) { ServiceAppointment SA = [select Id FROM ServiceAppointment WHERE ID =:SR.parentId];...
3
votes
1answer
125 views

Trigger: Find out the name of the object the trigger is firing for?

Is it possible for the trigger to see the name of the object it's firing for? Say can I make the OpportunityTrigger be aware that the object name it's firing for is Opportunity without hardcoding the ...
0
votes
1answer
25 views

How to add Contact to appropriate Campaign

I have a 'Highest Priority' field(declarative rollup summary field) on contact object. I have some campaigns namely Red, Orange, Blue, Green, White which are mapped to the 'Highest Priority' field. I ...
0
votes
1answer
27 views

Help With Method Increment A Score

I have a class that increments a custom field on the Contact record. If the contact has a campaign member status of Opened then the Pardot_Emails_Opened__c field increases by 1. If the status is ...
0
votes
1answer
15 views

How to make a call out from batch which (batch) get schedule from trigger?

I'm trying to call a method which do an api call. But I'm getting an error because this method get call through the process ran by batch and this is getting schedule from trigger. So even if i ...
0
votes
1answer
29 views

How to have Apex Trigger post Chatter field updates in one post?

I currently have an apex trigger that posts to chatter for when a field is updated on a record. Currently, the trigger works but posts each update as a separate chatter message: I want to have it ...
0
votes
1answer
56 views

Multiple Nested Loops in Apex

Background: I have 3 objects: Contacts, Accounts, Campaign, that are involved in the scenario. Contact is the parent object, Accounts and Campaigns are child objects to contact(Related Lists) There ...
0
votes
1answer
40 views

Help Bulkifying this Opportunity Trigger

I have written the following Opportunity trigger that is working but I know it's definitely not bulkified. It's definitely got some duplication and when any user has any more than 40/50 ...
0
votes
2answers
30 views

Archive Accounts [closed]

What is the best way to archive accounts, after we have identified them as obsolete. ? I want to automate the process of archiving the obsolete accounts. These accounts become obsolete under two ...
0
votes
1answer
24 views

Error Message Question

I'm new to salesforce and am unsure how to approach this error message. I had created this class that rolls down a Contact Role from a Contact created on a Parent to its children and a trigger that ...
1
vote
2answers
30 views

How to get the Connected App used from an Apex trigger [duplicate]

I have an Apex Job that is being triggered from an 'afterInsert' trigger, but I don't want that Job to be executed if the insert is being performed by a specific external application. I just need to ...
2
votes
1answer
22 views

Trigger unexpected behaviour when used in bulk but not in single update

I have a trigger in the contact (before update and insert) that when a boolean field is true (in insert) or when it changes from false to true (in the update) it goes and find all the opportunity ...
0
votes
1answer
24 views

Trigger On Campaign Member Status

I have a method that is called from my Campaign Member Trigger Handler. If a Campaign member's status changes to "Opened" then Email Opened__c field on the contact object should be incremented by ...
0
votes
3answers
28 views

Trying to increase code coverage for a trigger that deletes events

So I'm trying to write a test class to meet code coverage requirements to push up this trigger: trigger DeleteEventsOnCancellation on Case (after update) { for(Case c : system.trigger.new){ ...
0
votes
1answer
38 views

before insert trigger on Account never fires - why?

My account trigger has heretofore been firing inside this code block if( Trigger.isBefore && (Trigger.isUpdate || Trigger.isInsert)){ ....code .... } I've added a block ...
0
votes
1answer
28 views

How to separate multi values from multiple pick list in salesforce [closed]

How to separate multi values received from multi pick list
0
votes
2answers
31 views

Convert List<String> into List<Schema.SObjectField>

I have a below code public PageReference SyncCandidatewithMirror(map<Id, cxsrec__cxsCandidate__c> NewMap,Map<Id, List<String>> fieldChangedMapChanged, List<...
5
votes
1answer
114 views

Apex trigger takes a lot of time to access items in list

I have a simple Contact trigger in a sandbox org that is exhibiting some serious performance issues. After doing some debugging it looks like the issue boils down to accessing the items inside Trigger....
0
votes
0answers
12 views

How to track unique # of task contact at an account level in past 90 days

I'm trying to report on how many unique task contacts were emailed or called in the last 90 days in Salesforce. What is the best way to achieve this?
0
votes
1answer
24 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
2answers
22 views

Testing a trigger that is suppose to cover an failed check

I have a trigger on a custom Student object that is suppose to assign the lookup field Advisor based off of another look up field Gender. Basically my trigger goes: ... if (newStudent.Gender__c == ...
0
votes
2answers
35 views

need help on a trigger on custom object to get values of some fields from case

I have written a trigger on custom object to copy values of some fields from case objects. Trigger is saved successfully but when i try to create related problem from case it is not copying any fields ...
0
votes
2answers
47 views

Validation Rule to check PRIORVALUE

I am writing one validation rule where status is Pending/In Progress and I am changing any value from record then I need to throw an error 'you cannot edit the record'. AND(OR( ISPICKVAL( Status , '...
0
votes
0answers
19 views

I want to update account field as same field is available in opportunity custom object

Requirement is -: I want to update custom account assigned csd field everytime i create new opportunity. it suppose to update field with new csd along with available assigned csd but it is overriding ...
0
votes
1answer
41 views

Salesforce CPQ: Product Setup scenario

I'm trying to setup the below product set up in salesforce CPQ. Product: BAG Now, I need to set up the price of this particular BAG product based on the Colour in the line editor. For Ex: If the ...
0
votes
1answer
11 views

update Activity Score on Contact and Account

I want to calculate Activity Score on Contact and Account should be updated based on following formula. Contact/Account Activity Score = Count of Meetings * 3 + Count of calls * 2 + Count of Emails *...
0
votes
2answers
35 views

Execution order of Trigger, Workflow and Process

I have a question regarding the execution order of Trigger, Workflow and Process. I know there are plenty of resource there but none of them match my case. Right now our project have bunch of trigger ...
0
votes
1answer
32 views

Prevent certain profiles from approving accounts

I have a requirement to prevent certain user profiles from approving accounts. Wrote below trigger which is partially working. However getting below error when a user in Standard User profile tries to ...
-1
votes
1answer
35 views

need to write trigger on activity (Task and event)

I have following requirement, Update Activity “Type” field with following: Type = Call, if Subject starts with "Call" case-insensitive. Type = Email, if Subject starts with "Email" case-insensitive. ...
0
votes
1answer
15 views

getting recursion for Salesforce 2 Salesforce Integration using REST API in Case object

I am doing salesforce to salesforce integration between two orgs using REST API. I created REST API classes in two different org that update/insert/delete records. Insert and Delete works fine. But in ...
-1
votes
2answers
55 views

Call a trigger in anonymous window

I have a requirement like if the candidate is also a lead, then in leads i have to insert a flag field. this i have done for the records which were newly inserted. now for the existing records i have ...
-2
votes
1answer
24 views

While Refering to the Account field why it will give error that variable dosenot exist please help

public class LeadHandler { public static void callme(List<Account>acc){ for (Account a:acc){ if(a.Type=='prospect'){//While refering Type it give an error ...
2
votes
1answer
35 views

Serial/sequence number in Platform Events fired

(Sorry for the long description but I promise it will compel you to put on your thinking caps) We have a scenario wherein we have several platform events to which external systems within my ...
0
votes
1answer
34 views

Convert files Lead to Custom object

I have files (ContentDocument) attached to a Lead on conversion I map the Lead to a custom object trough process builder. Is there a Id or field I can use to map the files attached to the custom ...
0
votes
1answer
27 views

after update logic in trigger keeps on affecting because of before update

I have written a trigger on case object having before update and after update as it's events. In Before update : Where user selects any value of "Assignment Group", based on that Case owner will get ...
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 ...
1
vote
0answers
34 views

Not able to send email with HTML template (S-Docs)

My following code is working for generate the s-doc as expected but it is not sending email with HTML template. Id sDocTemplateId = [Select Id from SDOC__SDTemplate__c where Name = 'PDF template' ...
1
vote
1answer
26 views

Instant trigger email to new subscribes only in a data extension

I have a data extension in SFMC that is being populated with opt-ins from an external source. I would like to trigger an instant welcome email ONLY to anyone who is added to this data extension. How ...
0
votes
1answer
38 views

Disabling Triggers in Production

I have a trigger live in production on Contact Object and I am trying to load a set of 500 records through data loader and I don't want that trigger to fire upon the contact records I am loading into ...
0
votes
1answer
35 views

Trigger on opportunity object

There is one object let say Account. In Account I have field called Amount1 Now when I enter value in Amount1 at the time of creation of account record. Account1 field value get updated as'********' ...
0
votes
2answers
50 views

I'm having hard time bulkifying a code that attach similar deals to an opportunity when is created

the parameters are: amount within 10% of difference closed won last year Same industry I'm having hard time since is I have to validate 3 parameters instead one. Below you have the non-bulkified ...
0
votes
2answers
43 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 ...
3
votes
3answers
31 views

Trigger unit test or integration test

I have written some apex triggers along with some classes. The triggers are quite small because all the real work happens in the classes. trigger MyAccountTrigger on Account (after insert, after ...
0
votes
2answers
81 views

Apex Trigger on Attachment object not being fired

I wrote this apex trigger for Attachment sObject following the answer here. The trigger basically counts the total number of attachments for a record of type Assignment__c and updates the field ...
0
votes
0answers
31 views

Issue In platform event after Insert Calling twice due to Process builder

I have created one platform event and publishing the json in it on account creation. I have one Process builder which populating the field on account creation. the issue is my Platform event is ...