Questions tagged [trigger]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
33 views

Compare Ids in a set to mapKeys

I'm trying to see if the Ids in a set made up of Ids from trigger.old are in a map. Below is the for loop I put together to do this. If I add an Id to "uniqueSummary.contains('a1N1U000001kDcI')" I'm ...
0
votes
1answer
14 views

How to prevent non admin users from deleting Activity History for specific objects

I have a situation whereby I do not want non admin users to be able to delete Activity History records. What I currently have is a before delete trigger that queries all activity history records for ...
0
votes
0answers
5 views

Need help in creating a flow calling an apex method with parameters using Metadata API

Business Scenario: We have a Tax Master - Master Data to include all the parameters to calculate the Cost of a Product(s). Here we are capturing products in many Custom Sobject for different Product ...
1
vote
1answer
27 views

After delete trigger failing during bulk delete

I have a trigger that counts the number of child records by type and adds that to the parent. Each type has a field on the parent where the count is added. The update part of the trigger works fine ...
0
votes
2answers
28 views

Update field on account whenever a new task or event is created

I am trying to count all open activities related to an account. I have a controller class and two triggers on task and events. I am getting the right records for a related account but, I can not ...
2
votes
1answer
28 views

How do I find out which Account is associated with a specific ContentDocument?

When the user attaches a file to an account, this triggers the ContentDocument trigger. What logic should I put in the ContentDocument trigger to have it find the associated account?
0
votes
1answer
48 views

Convert Trigger into Apex Class

I am done what I want the thing is I dont know how to convert Trigger into class and trigger... trigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) { ...
0
votes
1answer
43 views

I have a Parent Agreement and it has two child Agreement in related list. On Agreement object it has a lookup called parent Agreement

I have a Parent Agreement and it has two child Agreements in related list. If i choose this parent Agreement in another Agreement ParentAgreement-lookup field then all the related child Agreement ...
-4
votes
1answer
16 views

if camapaign status is completed , then add campaign actual cost to account custom field(Total Campaign Cost) [on hold]

Each time a campaign status marked as completed add the campaign actual cost amount to account custom field Total Campaign cost...create a lookup on campaign of account
0
votes
0answers
17 views

Task Trigger is not behaving the way it should [duplicate]

I have a trigger on Task which takes the first record of task and updates on Contact object. But when I tried uploading them to bulk update 1000+ records.. Some records on contact are not being ...
0
votes
4answers
45 views

Apex CPU time limit exceeded error in trigger

I have a trigger on lead after insert that query all accounts and all contacts created the past 30 days to compare 4 fields (external id and legal number on accounts / mobile and email on contacts) ...
0
votes
1answer
19 views

How to remove value from Mapped Parent Object fields if related child records have been removed

I have 12 custom number fields on the OpportunityLineItem, each representing a month of the year (Jan to Dec). In OpportunityLineItemSchedule I have a custom formula field that displays a Month based ...
0
votes
1answer
25 views

Query only OpportunityLineItems whose opportunity is open

I am very new to writing SOQL or APEX triggers I am currently writing an APEX trigger, that would update OpportunityLineItems whenever a Product2 is updated. Basically, it currently looks like this. ...
0
votes
0answers
13 views

How to write help class for the below trigger [duplicate]

trigger ActiveCountContactOnAccount on Contact (after INSERT, after UPDATE, after DELETE , after UNDELETE) { Set <Id> accountIds = new Set <Id>(); List <Account> lstAccountsToUpdate =...
0
votes
0answers
20 views

Can I restrict the number of images to a specific number when I post in the Chatter

I need to restrict the image count(For an Example 5) whenever I post through the chatter on Opportunity Object. How can I achieve this?
0
votes
0answers
36 views

After Insert and After Update Trigger Handler delay in UI

I am new to APEX and I created two Trigger Handlers. They are identical but for different objects. This is for SF Billing Credit and Debits. Everything works, but one is delayed and the other shows ...
-3
votes
0answers
14 views

create lead assignment rules using triggers [closed]

I need to create a trigger that will run a query on the object to identify the user for the lead's zip code and then assigns the lead to that user. could anyone help me with this please?
0
votes
1answer
42 views

How to avoid for loop inside for loop for the below logic

How to avoid "For loop inside loop" for the below code For Each Account Conataines multiple Specifications, for the Specifications contains "Region" need to insert the name in Region field on ...
1
vote
3answers
66 views

Trigger is not updating the first task record on Contact

I have this trigger on Task which should take the first record of tasks and update on their contact id. But, when I tried updating the big file through data loader, It doesn't take the first record. ...
0
votes
1answer
30 views

How do I add a toast message to a standard Salesforce page? Something like addError, but not an error

How do I display information in a toast message using Apex? I want to show the message via a trigger on the Opportunity object. I can't use addError, because addError prevents the user from saving the ...
-4
votes
0answers
43 views

Trigger code is working for one record not working for multiple records [closed]

Logic: For Each Account Conatines multiple Specifications, for the Specifications contains "Region" need to insert the name in Region field on Account same way Each Account Conatines multiple ...
0
votes
1answer
38 views

Null Pointer exception with Private method

I have code below which is throwing System.NullPointerException: Attempt to de-reference a null object when COMPLETED_CASE_STATUS string variable is assigned. Is it because its private method ...
0
votes
0answers
27 views

Creating a Catch for the error: External entry point

There is validation that I made but not using a Validation Rule. Entries with the same Product Name within its Parent Object will be prevented. So for example, a user cannot input 2 ProductA within ...
0
votes
0answers
24 views

Update lookup field on child when apex trigger creates parent record

I have a trigger (before insert, after insert) on the child of a lookup relationship. When a child is created the trigger looks to see if there is a parent record that has the same campaign name. If a ...
0
votes
2answers
39 views

Using Metadata in triggers to remove hard coded keywords

I have custom metadata type with api name program_mdt in which I have created two fields called Email_Keyword__c and Body__c. In the below trigger I am trying to get rid of hard coded values in the ...
1
vote
2answers
35 views

Hari Krishnan based Trigger Framework executes twice on After Update

I have a trigger framework based on the work by Hari Krishnan: An architecture framework to handle triggers on the Force.com platform, however I have functionality on After Update in wich a trigger ...
3
votes
1answer
35 views

Change Data Capture vs Queueable Apex

With the introduction of Change Data Capture, now there is one more way to execute Asynchronous Apex. What are the advantages of Change Data Capture over Queueable Apex? How Salesforce will enqueue ...
0
votes
1answer
21 views

execution of AfterInsert caused by: System.FinalException: Record is read-only: (CMRules)

Hoping someone can help me fix this. I understand that this error is because I'm trying to access a record that kicked off the trigger. I'm just not sure how to resolve it. Any help would be ...
1
vote
1answer
30 views

Prevent Method from Firing again

I added a static variable named, "firstcall" to my method that gets called from a trigger. Static Boolean firstcall = false;. That variable is originally set to false but when the method runs it ...
0
votes
0answers
34 views

Trigger to relate a record to another when a matching field is found

I'm trying to write my first trigger and not having much success. I have two objects email history (wbsendit__Campaign_Activity__c) and email summary (CMRules__Email_Tracking_Summary__c). email ...
0
votes
1answer
31 views

What's Wrong with my Trigger? Record Type Help!

Can someone please take a look at the below trigger and tell me what I can do to make it work! It's triggering an APEX Class to run, however I only want it to run on a specific Record Type. ...
0
votes
1answer
20 views

write an primitive testclass [duplicate]

I am new to apex, and I dont know how to correctly write a Testclass for my trigger. Trigger has to update field Time_Zone__c of object Task according to Time_Zone__c of object Contact, which is ...
-1
votes
1answer
43 views

Restrict creation of duplicate contacts for an Account

I have a requirement that for an account there should be unique email id for every related contact. But in my code it is not working as per the requirement, it is checking all the contacts ...
-3
votes
1answer
43 views

Write a trigger to update the records of Contact object(child) from Account object(parent) whenever we select a value in picklist [closed]

Object: Contact (child) Account (Parent) In Account object, there is pickup list field. Values: A,B,C,D. If we select A, then in contact object all the fields should be automatically update to A. If ...
0
votes
1answer
14 views

records deduplication and sharing after insert [closed]

Here is my question: Org's personal account is enabled. The account sharing setting is set to private, sales team members Sales A and Sales B can not access each others' account records. Sales A and ...
0
votes
0answers
15 views

update partner account status field when partner user profile is updated

I have a partner user who has active partner account. If there is any issue with the payment, the users profile will be updated to "restricted profile". I have a requirement where, if a partner user'...
1
vote
0answers
11 views

Event Trigger not firing when EventRelation record is inserted using data loader

I have a trigger on Event that gets called before update and after update. The trigger essentially computes the next meeting date and the last meeting date for each account related to that event (...
-3
votes
0answers
22 views

Prevent Duplicate records creation

There is 3 account lookup fields on opportunity, i have written a process builder every-time there is value on this 3 fields , it will create a record on opportunity Account(another object) now issue ...
0
votes
0answers
26 views

SELF_REFERENCE_FROM_TRIGGER: Object is currently in trigger CaseTrigger, therefore it cannot recursively update itself

I have a process builder on Email Message object, from this process builder i am updating case 'last_activity_date__c' with system .now() when a email is sent from case related list "send Email". I ...
0
votes
1answer
32 views

Stuck writing a test class for ContentDocumentLink object apex trigger

I am trying to write a test class so that I can send the following trigger live in our production system: trigger updateDocTitleFileExt on ContentDocumentLink (after insert) { for (...
-2
votes
2answers
32 views

How to get the last modified person name in query? [closed]

I am using after update trigger. There I wanna fetch the user name which has modified the record. Please let me know if anyone has idea ow to achieve this.
0
votes
0answers
10 views

Process Builder that creates reminders based on next available preferred day?

Here's an interesting one I am thinking through: I have 7 boolean checkboxes on my contact fields for every day of the week (Mon, Tues, Wed, etc). Preferred scheduling is very important in my ...
1
vote
1answer
27 views

System.TypeException: Invalid integer: (Lead-0002)

I have created a round robin assignment of leads to users. I am getting the following error Lead_Trigger: execution of AfterUpdate caused by: System.TypeException: Invalid integer: (Lead-0002) ...
1
vote
2answers
56 views

Passing same values in trigger.newMap and trigger.oldMap

I am trying to prevent trigger from creating duplicate requests. For example, if the case status is changed from something else to close, then create a new request. If the case status is not changed ...
1
vote
1answer
42 views

Trigger for loop and SOQL limits

I have a trigger. It inserts imported Gears with correct fields' values. One of valu I took from Detail__c - related to MoreInfo__c object. And Tool__c is related to MoreInfo__c too. Each MoreInfo__c ...
4
votes
1answer
90 views

Best way to avoid trigger recursion as using static boolean variable processes only first 200 records

What is the best way to avoid recursion of trigger ? Below are the approaches used and problems faced Using static boolean variable from handler class Apex Class public Class checkRecursive{ ...
2
votes
1answer
21 views

test class for opportunity trigger not fully testing the entire code

my trigger trigger EmailTest on Opportunity (before insert) { id ac; List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); for (Opportunity opp : trigger....
0
votes
1answer
17 views

In which mode(System/Automated Case User) Emailmessage trigger runs when we receive emailmessage to create case

In which mode(System/Automated Case User) EmailMessage trigger runs when we receive EmailMessage to create case,I checked in Logs and User is ('Automated Case User') that we setup on Support Settings.
4
votes
1answer
56 views

Need help in optimizing the below helper class

Logic : For any new record inserts for 'Properties' object, check if its Account_Ref_Ext_ID__c equals to 'Account' object's Chris_Account_Number__c. If it matches, assign Account id to properties ...
0
votes
0answers
13 views

Email To Case with duplicate contacts (intentionally)

We have intentionally created duplicate contacts in Salesforce. Importantly these records have the same email address but the rest of the fields maybe slightly unique. For the sake of argument they ...