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

Winter Release '20 - Lead Conversion Account Trigger Error

I just wanted to post this somewhere so that others are aware. The Salesforce Winter '20 release for Financial Services Cloud comes with an error attached to the Account-Account Relationship object. ...
0
votes
0answers
9 views

How to write Trigger for Dependent Task [on hold]

I am new to Salesforce, currently still with a trial version. I want a trigger that fires when a predecessor task Status field (Picklist field) is marked "completed" then the successor task Status ...
0
votes
1answer
16 views

Store and Revert Prior Field Values on Object After Approval Process Rejection

I am building a process where partner users make multiple field updates to an object Fatburger_Menu__c (all the fields are currency), which will activate an approval process for one of our team ...
0
votes
1answer
44 views

How to update all records through Trigger?

I have to automate the logic with Trigger. If the Comment__c field is updated in 1 Tool__c record, it should be updated in all another Tool__c records. It's about 700-1000 actual records. When I'm ...
0
votes
3answers
48 views

Possible to Detect if a Record is Being Created by Apex?

Background An Apex Trigger has been set up on a parent object to automatically create a child object record when the parent object record is created. However, another Apex Trigger has been set up on ...
0
votes
0answers
17 views

Event on task completion?

I am wondering if there is any way to fire an event (like popping up a form) on task complete. I know we an do custom buttons and what not to accomplish this, but i specifically would like to put this ...
0
votes
1answer
30 views

Trigger after update: System.FinalException: Record is read-only [duplicate]

I have a trigger: if(Trigger.isAfter && Trigger.isUpdate) { for(SomeRecord__c newRecord : Trigger.new){ if(Trigger.oldMap.get(newRecord.Id).Worker__c != newRecord....
0
votes
1answer
21 views

Trigger to populate Last Modified date on Content version?

In the content version, there is a Last Modified Date that populates both the date and time, so I created a custom field called Last_Modified__c with a field type Date that is set to create only date ...
0
votes
1answer
30 views

Execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.Battle

I would like to create a trigger to activate when using the Battle class and its battle percentage method, but it gives me a "activate percentage: execution of BeforeInsert caused by: System....
0
votes
2answers
31 views

What's the difference in value of Trigger context variables new and old? [closed]

I have a confusion please can anyone solve it. I know it is silly but I am new to Salesforce so I need help. In before update and after update what will be the difference between the values of ...
0
votes
1answer
24 views

Setting Contact mandatory in Cases

Our org Cases in SF, contacts are not set as mandatory. I want to set it to mandatory by using a validation rule to associate with Contacts. But the validation rule will not work, as we have designed ...
0
votes
0answers
8 views

How do I flag leads that have been extracted from a Community? [closed]

Problem - How to identify leads that have been extracted from a community?
0
votes
3answers
35 views

Test cases in a list

I am trying to get code coverage for my list/loop but no matter what I try I am missing something and could use a hand if possible as I am trying to learn more about Apex. Trigger: trigger ...
-1
votes
0answers
11 views

iterate through a collection to update [duplicate]

I am working on a trigger between 2 custom object in a master-detail relationship Rep and Role History. The objective is to have active roles set on the Role History object via the Type__c field ...
-2
votes
1answer
32 views

code to calculate lineitem total and sum it field in opportunity during insertion my code runs twice and sum will added twice for the new product [closed]

trigger Opportunitylineitemtrigger on OpportunityLineItem (before Insert,before Update) { if(trigger.isbefore) { if(trigger.isUpdate || trigger.isInsert) { Map<...
0
votes
1answer
63 views

How to handle newMap and oldMap in Trigger Handlers for both insert and update Triggers

I have a general question about comparing newMap values with oldMap values in an Apex Class made for both update and insert contexts. Let's say we have an Account Handler method that must run when an ...
-4
votes
1answer
36 views

Trying to update the existing record in Saleforce [closed]

I am trying to update the website field of exisiting account but it is not working, below is my code trigger AccountTrigger on Account (After Insert) { if (Trigger.isAfter == true && ...
-4
votes
1answer
27 views

can anyone tell me the trigger for sending an email for opportunity

can anyone pls tell me the solution this is the error --sendanemail: execution of BeforeInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: ...
0
votes
0answers
21 views

ISSUE Cannot change both 'UnitPrice' and 'TotalPrice' in update call [duplicate]

So currently i have an issue at trigger opportunitylineitem when before update. My scenario is want to convert unitprice to other currency, and the code like below: if(OliObj.Currency__c=='Local'){ ...
1
vote
1answer
41 views

Everything worked fine in Production - but not enough code coverage in Salesforce

I've been tasked with updating our Salesforce. I'm a pretty experienced Salesforce Admin but I have to admit I know very little about apex code. Here's the situation. I've tested everything in ...
0
votes
0answers
40 views

Bypass System Validation in Trigger To Update Record

I have an object called objC which has a key field that is a Text(255) (Unique Case Insensitive) It's composed of objA.Id + objB.Id. Now ObjC has a field called value wherein it should be updated ...
0
votes
1answer
44 views

Apex class to generate pdf and save it in attachement

I had created an apex class to generate a pdf and store the pdf into the attachment object. I had called this apex class using a trigger. When the status is correction requested than the trigger ...
-2
votes
1answer
22 views

How to display contacts as they relate to accounts on a custom object [closed]

I am a newbie in salesforce I have a custom object say X which has master detail relationship with Account. Now I want to display the list of contacts related to account under the custom object X. ...
0
votes
1answer
46 views

match string from map trigger

i am working on a trigger associated with 2 custom objects. when the type__c field (picklist) on role history is updated to a value, the rep_type__c field should automatically take this same value. ...
-4
votes
4answers
86 views

To fire trigger only when there is change in field of IsActive__c of account [closed]

Hi all I have written a trigger but i want it to fire only when there is update in IsActive field else it should not fire so please could you help me This is my trigger public static void ...
0
votes
1answer
22 views

How to Show Role Name And Assignedd Permission Name in History Object

Trigger: if (Trigger.isUpdate) { String jsonOldMap = JSON.serialize(Trigger.oldMap); String jsonNewMap = JSON.serialize(Trigger.newMap); AssignPermissionSetToUserHelper....
1
vote
2answers
31 views

How to create a Record (histroy __C -custom object) with old Values and New Values(Account) after update trigger [closed]

Example: if Record Is inserted or updated, i need create record with Old Vales and new Values in histroy __C custom object how to do ??
-1
votes
2answers
32 views

How to Write One method for Both After Insert And After Update Trigger

i have User object when after insert and after Update populate some values. my question can i write one method for both events.
0
votes
2answers
27 views

System.NullPointerException: Attempt to de-reference a null object: Trigger.Assignedrollno: line 4, column 1

System.NullPointerException: Attempt to de-reference a null object: Trigger.Assignedrollno: line 4, column 1 trigger Assignedrollno on student__c (before insert) { if(trigger.isbefore &&...
-1
votes
0answers
32 views

Update Trigger Not able to track changes on individual ShippingAddress fields

I am struggling to get away with a simple requirement which is to perform an action whenever a ShippingAddress related parameter changes, i.e, on change of ShippingStreet, ShippingState, ...
5
votes
4answers
132 views

Trigger in Managed Package in error state, can't be cleared

I have a Platform Event trigger in my managed package. For some reason, it generated an error on a customer's sandbox, and now it's in error state and won't run. I updated the trigger and pushed the ...
0
votes
1answer
22 views

salesforce - Getting error incorrect signature: void valueof(pse_timecard_header_c) from the type decimal

I was trying to create a separate record in a custom object having hours - for time submitted on every day in the standard timecard object of financial force. Please see the code below Also - please ...
2
votes
1answer
148 views

Trigger : making API call to validate record creation?

I would like to know if this is technically possible from Salesforce to make an API call from a trigger before insert/update to check the data of a record with an API that would respond TRUE/FALSE ...
0
votes
0answers
20 views

Alternative to Delete Trigger for tracking deleted records in OpportunityShare Object

We want to track the deleted records in OpportunityShare Object for some reason. This object doesn't support to write a trigger. Is there way to track those deleted records?. Any suggestion would ...
1
vote
1answer
30 views

Do you need to structure an IN for the where clause a certain way?

Trying to write a dedupe trigger for the lead. Basically, if the lead is created then it will see if it has an exact match to another lead. If it does then it will update the new lead to show the ...
0
votes
1answer
42 views

How to run this Contact Trigger only if Task is Inserted or Update

I have this trigger on contact that I would run only if Task is inserted and updated. I was thinking to create a checkbox on contact and set it true using may be using process builder that would ...
-1
votes
3answers
49 views

Trigger on account for contact with type new and renew

I have to write a trigger for account which has two related contacts one with type new and other with renew if there are 2 contacts with this type then the checkbox isActive on account should be ...
0
votes
1answer
24 views

How to delete child lookups from the parent after reparenting

Im a beginner and still learning to write apex.. Im creating a new object from the old object. I want to reparent the Lookup to the new object and delete it from the old object. //map of ids of new ...
1
vote
1answer
36 views

Trigger Handler

I have a few questions regarding best practices for the methods called from a trigger handler. I am using a trigger handler that calls a method for some processing. I want to call the same method ...
0
votes
0answers
29 views

Attempting to get better code coverage on fairly simple trigger [duplicate]

I am new to working with Map objects in Apex and it has introduced a wrinkle to my test class process. I am only able to achieve 74% coverage and I absolutely cannot figure out why. This trigger is ...
-1
votes
1answer
43 views

Apex Trigger to Insert Opportunity Owner on Custom Task Field

I'm not the best at writing Apex code. I really just need an Apex trigger to insert the Opportunity Owner NAME into a custom Task field named OPP OWNER. Any help is greatly appreciated. Thank you! ...
0
votes
2answers
30 views

Need to Store record on Delete Action [closed]

I need a sample code for a custom object which can store records from another object where records are getting deleted (on click of delete button) for example: i have 'xyz' object and their is a ...
-3
votes
0answers
14 views

I am not getting the code coverage for the trigger.where am i missing.Can somebody help me out [duplicate]

trigger BusinessUnitFieldAutoUpdate on Opportunity (before update,before insert) { Set<Id> accid=new Set<Id>(); Set<Id> accownerid=new Set<Id>(); for(Opportunity tl:Trigger....
0
votes
1answer
57 views

Why this trigger won't insert task for all the contacts?

This trigger inserts and updates contact fields fine for the first contact but when there are multiple contacts in Task, the task does not update contact fields for the rest of the contacts. What am I ...
3
votes
0answers
39 views

In a Task trigger, is there any way to know if a Task is an Email before it has been inserted?

In the "before insert" section of my Task Trigger, I want to check if a Task is an email. But from what I can tell, the only way to know is by checking the Task.TaskSubtype field, but that field is ...
-3
votes
0answers
27 views

Code Coverage Salesforce

Hi i get the following Error on deploying a new changeset in Salesforce. But have no idea why. Code Coverage Failure Your organization's code coverage is 73%. You need at least 75% coverage to ...
-2
votes
0answers
19 views

Open google page after saving new field

after I insert a new field and click on save, I want it to automatically open a Google page with search the name of the field just entered!! please help me?!!
0
votes
1answer
29 views

How to query for TaskRelation contacts from Task?

I need to query for all the taskRelation (for contacts only for now) Ids from the specific Task id and then add them in List(called ContactIds). When I tried taskcontacts.TaskRelations it kept ...
-3
votes
1answer
45 views

when field on child object is updated to have a value, change field on parent to be null trigger

working on this trigger for 2 custom objects in a master-detail relationship, rep is the parent, role history is the child. the insert part works perfectly, just am struggling with the update portion. ...
1
vote
1answer
32 views

Help with “Duplicate id in List”

I've recently started at a new company with a completely different instance. Recently I've noticed a growing amount of errors looking like CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: CaptureCard_Trigger:...