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
0
votes
0answers
2 views

I have to update the most recent AccountKnowledge__c record's NULL fields with the next most recent record's fields

I have to check if the most recent AccountKnowledge__c record has any blank fields, if it does, I have to check for the next most recent record, and if that record has those fields filled, I have to ...
0
votes
0answers
12 views

API calls on a trigger is a best practice?

I'm a bit wary on creating API calls on trigger. But with our process this is the only way we can achieve our requirements. We have currently have almost 4 million limit on a 24-hour API calls and we ...
-1
votes
0answers
35 views

Apex triggers work in sandbox but fail on import to production org

New to Salesforce development and trying hard to make use of the documentation to fix my problems but running into the sands... I have 2 x triggers that work in my sandbox org and I wrote separate ...
0
votes
1answer
12 views

Apex trigger before update generate problem with Aura methode

My trigger beforeUpdate cause me a problem , i have a button in the header named Validate and this button call the methode below 'UpdateHeader' , but when the user is not the AdminUser , he can ...
0
votes
1answer
27 views

updating field from parent object to child object and it's not working

I have been working with this code for updating field from parent object to child object and it does not work. Can you help me with this. Thanks. public void tcUpdate(Map<Id, SObject> newMap, ...
0
votes
0answers
24 views

Create quick action generate pdf and attach as object

I need to create quick action for "Generate PDF" and attach it for opportunity object. i create vf page, i create apex controller. i have next qustions: my method SavePDF work only in Open ...
1
vote
2answers
21 views

How to avoid Multiple DMLs on a single transaction while populating Rollup fields in Lookup relationship using triggers

I have a trigger on child object.From the handler I am calling the helper method multiple times to update 4 rollup fields on parent record. I have a working logic but I am concerned about repeatedly ...
1
vote
0answers
19 views

Have a validation on knowledge article publish

We are trying to add a validation on knowledge article before publishing. This can not be done with validation rule since it involves data category. However, when I do that via trigger, I find that ...
0
votes
2answers
35 views

Apex trigger running recursively

I have a scenario where i have a checkbox field on Account object "test_check__c" and this checkbox field is applicable only for child accounts and not for the parent. Scenario is : - Parent ...
0
votes
1answer
22 views

Patterns for Methods to be used by Insert and Update

I am trying to find out efficient designs to use for a method that can be used by both Insert and Update triggers. For example: if I want to perform some complex logic when an Opportunity is inserted ...
2
votes
2answers
56 views

Error: Create a Visualforce page to use as a custom action

thank you for your reply. I need to create Quick Action - generate PDF on opportunity object. i have PDF visualforce page and custom controller. If i want to add my vf page in Quick action i get error:...
4
votes
1answer
75 views

More focused Apex Trigger: Before Delete

I'm new to the world of Apex and have managed to cobble together this code that looks at a particular field and prevents deletion of that record if a particular field (in this case 'Data Source' isn't ...
-3
votes
0answers
31 views

REGEX in Screen Flow [closed]

I have To use validation for Phone Number in flow screen in Salesforce. I used the following formula REGEX(Phone_number,”^((\+1)?\s?\(\d{3}\)\s?\d{3}\-\d{4})?$”) But its giving a validation syntax ...
0
votes
0answers
28 views

Uncovered Trigger Scenario in Duplicate Record Checking

We have a custom object called Request__c which has 4 custom fields: BusinessAccount__c(Lookup to Account), AssigneeAccount__c(Lookup to PersonAccount), RoleName__c(Picklist field), Status__c(...
0
votes
1answer
54 views

After update Trigger to avoid hitting governor limits

We have a custom object(Request__c) with lookup to PersonAccount(AssigneeAccount__c) and Account(BusinessAccount__c) similar to AccountContactRelation(ACR) standard object. There is a requirement ...
0
votes
1answer
31 views

Can a Trigger Handler be used on 2 separate Triggers, so that if 1 runs the other doesn't and vice versa

Can a Trigger Handler be used on 2 separate Triggers, so that if 1 trigger processing the data onto another object, and then the other trigger is prevented by the handler, and vice versa when the data ...
0
votes
0answers
42 views

How to use external api using apex triggers [closed]

I want to trigger an event when a job is created. It should create this job in the livehire too. This is my class where I am getting access token public class _Token { @future(callout=true) ...
9
votes
1answer
295 views

Exeception line numbers are not reliable

I spent quite some time debugging an issue because the stack trace line numbers were not correct and wanted to share my findings. The problem seems to be 10 Years old and fixed, but under specific ...
0
votes
1answer
29 views

Allow only Admin Key-User to delete the form

I want to allow only the user that have Admin Key-User as role to delete the form , now also the Admin Key-User can't delete if the conditions in trigger are corrects . =>this is my trigger trigger ...
0
votes
1answer
31 views

Trigger on ContentDocumentLink object which sends an email each time i upload a file in account object

Things I have done:This is my code.Earlier I had done it without using an email template by using a subject and body in my apex code itself.It worked fine and each time I uploaded a file in account ...
0
votes
1answer
20 views

Inbound changeset validation error on opportunity trigger

I need to preface this with the statement that I am not a developer. I've inherited an instance that contains some apex triggers that I'm trying to tighten. I'm attempting to make a minor update to a ...
-1
votes
0answers
35 views

Users don't have access to Apex Trigger

please I need help, I created two triggers (before delete & before update) both are applicable when I connect by my profile which is system admin but once I use another user with another profile ...
1
vote
0answers
23 views

Prefill text fields with text in users language

We are currently using text fields with default text to create a form for users when they create a new record, e.g. custom_field_1 is not editable by any profiles and has default text that appears on ...
0
votes
2answers
33 views

Getting error System.AsyncException: Future method cannot be called from a future or batch method: when I am calling future method from a trigger

When I am calling future method from a trigger then I am getting error USER_DEBUG caused by: System.AsyncException: Future method cannot be called from a future or batch method: ExampleFuture....
1
vote
2answers
118 views

How to implement dynamic array/list in apex like vector in c++

If we want to concatenate current collection elements to same collection ex: if current collection contains {1,2,3} how to write logic in apex to make its value {1,2,3,1,2,3} without using any extra ...
0
votes
0answers
20 views

How to cover ConsentEvent platform event trigger in test class

I have written a trigger on Standard platform event object 'ConsentEvent' which gets fired whenever user or contact email is updated. But I am not able to write test class for the same. I have tried ...
0
votes
1answer
36 views

Before Delete Trigger : Need to compare User with the Owner [closed]

i want to add in my trigger before delete to compare if the owner of a form is the user , if it true then i can delete but in the object form i don't have an object that refer to the user , how can i ...
0
votes
0answers
27 views

NUllPointerException on TDTM Trigger [duplicate]

I have a TDTM trigger on the Case object which does some simple operations. Problem is, all contact-related fields appear to be null, so I get a nullPointerException error when trying to update one of ...
0
votes
0answers
14 views

Validate event attendees are related to account on Event before insert

I want to validate that, whenever I'm creating a record with WhatId filled (Account) and WhoId (multiple contacts available) all these contacts are related to the Account before the Event is inserted. ...
0
votes
1answer
12 views

Problem in approval process

I am trying to send an email with CC when an approver approved a quote in approval process. For this in approval steps I make Current Approver field update and I have created trigger on these updates. ...
1
vote
1answer
36 views

Is lookup skew bad if it doesn't bring about row lock contention?

On Opportunity there are two lookups fields, the standard Primary Campaign Source, and a custom lookup to object Exhibition__c (which is set to Clear the value of this field if related record is ...
0
votes
1answer
27 views

Is the rule of 'triggers for one object not creating or editing records of a different object' a good idea in a managed package?

Context: Working with Multiple 2GP Packages in a Single Namespace. It's a big package(s). OEM environment so this is the core application used by clients on the salesforce platform and takes ...
0
votes
1answer
41 views

How do I correctly implement the 'isDelete' method?

This is the code I am trying to use. I will also add that in the parameters of the trigger, I have added the 'before delete' and 'after delete' at the top of the trigger. And I am getting the ...
0
votes
1answer
18 views

Preserving @mentions in the FeedItem trigger edit

I have written before insert trigger that concatenates Case Subject to the Chatter post when it is posted from the case record. But when I do that, @ mentions are getting stripped from the chatter ...
-3
votes
1answer
42 views

Trigger Apex Trigger if a custom field (bool) is true

I have this code that sends information to a webhook, I only need to send information when the field WebTrig__c (checkbox) = True. I wrote this code but for both cases it sends the information to the ...
0
votes
2answers
57 views

Need help moving SOQL out of the loop

Hello, I need move this query out of loop: List<Lead> dupeLeads = [SELECT Id, Email FROM Lead WHERE Id != :Ld.Id AND Email =: Ld.Email]; I'm testing various guides on "bulkifying ", ...
0
votes
1answer
28 views

Fire validation on UI with more than one active products with same name [closed]

I have an active checkbox field in the standard product object. I want to throw a validation on UI if the user tries to activate a product if there is already a product with the same name and is ...
1
vote
0answers
24 views

Bulk insert test failing for lead convert

I have an apex trigger helper method that converts lead to contact when certain conditions are met. My bulk insert test method is failing on the line where I assign email to lead. The single insert ...
0
votes
1answer
22 views

Fee field must not be blank

In this trigger apex, I want to give error when Fee_paid__c field must not be blank. We can throw the error as "Please enter amount" I tried above code trigger Not_Negative on Student__c (...
0
votes
0answers
37 views

BillingState Issue

i am trying to get BillingState value from apex trigger before insert, before update. I have troubles when change the value it got the last one and not the actual value I do a debug and get the last ...
-2
votes
0answers
24 views

Can we get the Id of the record in Apex in the next line after Insert statement inside a Trigger Handler? [duplicate]

I need to create a Before Insert Trigger for Object A__c, where in I will check if the record has email Id matching with any of the records of Object B__c. If yes, I need to populate Id of that record ...
0
votes
1answer
42 views

Trigger to compare records in different Objects not working as expected

I have refered the following thread to solve my problem. Not sure where I am going wrong. Compare records with same field value from different Objects in apex? Here is my attempt: PROBLEM: While ...
1
vote
2answers
51 views

Query third-party api on lead update and write response to new field on same object

Folks, I am in need of some apex wisdom please! I've experience in other programming languages but trying to get my first apex trigger and class set up. My overall aim is when a specific field on the ...
0
votes
1answer
40 views

I have to check whether an account has closed won opportunity and if yes find all the accounts nearby

Create a custom field to show whether that account has closed won opportunity Create a custom button to get the number of closed won Accounts in below ranges a) >50 km b) Accounts between 30 km and ...
2
votes
1answer
122 views

Error on Trigger: Method does not exist or incorrect signature: void CheckPreviousYearEntryByPhoneNumber(list) from type FreeWaterSchemeClass

Problem statement: If the customer phone number was enrolled in free water scheme for 2020, status field in 2021 scheme object should ''You cannot avail this scheme in 2021, as you have already ...
0
votes
3answers
45 views

Is there any way we can identify the insertion/updation of record is happened through UI or not

I have requirement where I have one trigger and its calling handler and in handler i have one method, I need to run that method if I am updating the record through UI in,i dont want to run trigger or ...
-3
votes
2answers
37 views

How do I write a trigger that only allows editing for certain fields when an Opportunity is Closed Won? [closed]

I have a list of a few fields that I want to be able to edit once an opportunity is Closed-Won. A validation rule will not work for this, as it would require listing every single field that I do NOT ...
0
votes
0answers
11 views

Managed Package's Platform Event is not triggering

I have logging setup in my managed package using a platform-event published immediately with a trigger on that platform event which creates a Log__c record based on the data in the platform event. ...
0
votes
2answers
53 views

Failing to remove single variable from collection in Salesforce Flow

What I'm trying to do Using Record Triggered Flow, when Opportunity is updated, I want it to retrieve all the Opportunities related under the same account like in screenshot below Then I will use ...
0
votes
2answers
36 views

Is this correct way of tackling Code Coverage scenarios?

If someone asks, there are n Apex classes with varying code coverage, some less than 75 & some greater than. What will happen while deployment? So the answer would be - (For Apex) all lines ...

1
2 3 4 5
149