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

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

0
votes
1answer
56 views

Too many SOQL queries: 101 and Triggers

SHORT VERSION: I'm getting a "Too many SOQL queries: 101" error on my production environment when updating some Leads through an external application. The theory is that it's due to multiple nested ...
0
votes
0answers
14 views

Insufficient access rights on cross-reference id in a managed package procedure

I have added a changing Opportunity owner logic inside Opportunity before triggers. And this is causing issue in a managed package procedure when I amend a contract in Salesforce cpq package. The ...
-2
votes
0answers
11 views

Insert records related to a common object related to two objects in Lookup relation [duplicate]

I have three Objects Contact, Item and Preferance. Prefarance is the common object which has lookup relation with Item and Contact. Type is field on Contact. I am writing a query on Item based on ...
0
votes
1answer
34 views

SOQL to return COUNT value via Apex

I am trying to return the SOQL listed values into a field using an Apex Trigger:- Object: Name = RPA__c Fields: Business_Area__c (picklist) VALUES = Finland Managed Services, UK Managed Services ...
2
votes
4answers
453 views

Should I update trigger API version?

I am an admin and have looking through some of the old triggers that are currently in our org. There are a few of them that are still active and do some important job but are set to API version 20. ...
0
votes
0answers
12 views

Add error displays message as well as updates record in Salesforce lightning

I have the following piece of code in my case before trigger. approvalStatements.get(pi.TargetObjectId).addError( 'Operation Cancelled: Please provide a reason ' + ...
-1
votes
0answers
38 views

sending Contact record Id to a web service

I want to use REST API to send the Salesforce Contact ID into a web service whenever a new contact inserted in Salesforce Org after validating few conditions. I was trying Global class with @...
0
votes
0answers
18 views

Streaming API PushTopic VS Trigger and API Callout

I haven't used the Streaming API yet. I was just researching on it actually and I like the option for PushTopics. However it's not clear to me what's the advantage/difference using that versus a ...
0
votes
1answer
37 views

About heap limits on triggers, garbage collection and transient variables

My friend and I are studying for platform developer I, and one of the questions we use for studying asks what are the best practices to avoid heap limit errors in triggers. The full question reads: ...
0
votes
1answer
24 views

Create contact and community user when the lead status is updated

I am trying to create a contact , custom object record and community user when a lead status is changed , so issue is i am able to create contact and custom object record(without the code to create ...
0
votes
1answer
42 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 ...
-3
votes
0answers
19 views

logic requirement for an xyz television channel [closed]

Logic Requirements This section of the document details the automation that the candidate is required to implement programmatically. XYZ Broadcast Planners want to know how many times a Commercial is ...
0
votes
1answer
8 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
30 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
11 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 : (...
0
votes
0answers
19 views

Update custom object record

I have Case object and a custom Object -LineItem which is child of case. Case has 3 record type- service creation(sc),service revision(sr) and service termination(st). sc case - parent case (fields- ...
1
vote
2answers
830 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];...
-2
votes
0answers
24 views

want to write helper class that can be call in after insert, after update trigger [closed]

I am having one child object where 2 fields are status and date. the parent object is opp. so want to create a field on opp looking to child object so that this new field will populate whenever the ...
3
votes
1answer
118 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
24 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
14 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
18 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 ...
-2
votes
2answers
25 views

Trigger events query [closed]

Can you please explain the simple logic for the below scenario? trigger test on Account(before insert,after insert){ // What values i will get in trigger.new()? for before and after events }
0
votes
1answer
45 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
39 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
29 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
21 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
27 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
17 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
27 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
35 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
23 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
26 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<...
4
votes
0answers
76 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
10 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
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
2answers
19 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
32 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
40 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
25 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
9 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
33 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
27 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
25 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
12 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
40 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 ...