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

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

-1
votes
0answers
3 views

Auto populate Contact and account on Case record in salesforce

Auto-populate Contact lookup and account lookup fields on Case record in salesforce, when record created through Email-to-Case functionality.
0
votes
1answer
14 views

Trigger.New value to compare with all records

I has objects Contracts__c with fields(Start_Date__c and End__Date__c) and related obj Actor__c. When i insert new contract i trying to check does the actor already has a contract on specified dates. ...
0
votes
1answer
25 views

Possible to calculate number of days between when records are created?

Is it possible to calculate how many days has passed since the last record has been created? For example, shipments are children to Contacts. We want to calculate how many days has passed since the ...
-1
votes
1answer
20 views

Test Class/Method for TriggerHandler - Negative scenario

For this class below, which essentially counts the number of Open cases on an Account, on update/insert/delete of a Case, can anyone help me write/provide a scenario of a test method that can hit the ...
2
votes
1answer
44 views

Salesforce Metadata Update tools

We are looking for a tool to reactivate Apex triggers(100), Flows(20), WF rules(50) and Validations rules (1700). During data seeding in a sandbox from PROD using a famous tool had deactivated all the ...
-1
votes
1answer
34 views

Need help with a Test class coverage

Hello guys i need help to cover this Trigger on a Test Class, this Test Class also covers another class so some Data is not refering to the Trigger. This is the Test Class: @isTest private class ...
0
votes
1answer
18 views

adding up custom field with triggar [duplicate]

trigger PaymentTrigger on Money_Received__c (after insert, after update, after delete) { Money_Received__c moneyReceived = [SELECT Reservation__c FROM Money_Received__c]; Reservation__c ...
3
votes
3answers
434 views

Help With A Null Pointer Exception

I am hoping that someone can teach me a little about how to work through this null pointer error. The class is called from a trigger handler on After Update because I need access to all ID fields. The ...
-3
votes
1answer
35 views

is there any way to solve the following case with out using maps

Create Custom field called “Number of Locations” (Its API Name: NumberofLocations__c) on the Account Object (Data Type=Number) The following trigger creates the number of contacts which are equal to ...
-2
votes
0answers
26 views

Insufficient Privileges on Update trigger

I am calling a managed package method from a user trigger. When I create a new record it is working as expected but when I update a record it is throwing Insufficient Privileges error. Please suggest ...
0
votes
1answer
26 views

Help With Code Coverage

new developer and I am struggling with getting 100% code coverage on a test class. I have written a class to count tasks with unique subline lines and then update a field on a custom object with the ...
1
vote
0answers
30 views

Soql in apex trigger returns different result depending on user who causes the trigger.

In Communities we have an ideas component where users can post/comment/vote on different ideas. We are trying to create a trigger which will send an email to the idea creator whenever someone ...
1
vote
1answer
25 views

Get EntityMilestone fields values?

I'm coding a trigger on case and I'm using this query to get some data fields information from CaseMilestone entity: Select caseid,MilestoneTypeId,CompletionDate,ElapsedTimeInMins,IsCompleted,...
0
votes
2answers
41 views

Trigger error - Too many DML rows: 10001

I have tried to optimize the code, but still it throws the error: Too many DML rows: 10001 Below is my code: if(setAccID != null && !setAccID.isEmpty()) { list<Custom__c&...
0
votes
2answers
26 views

How to set the RecordTypeID

Im trying to set the RecordTypeId of a contact to a certain value if the contact was created by a specific user. Im getting the error: A value cannot be stored to RecordTypeId in type Contact. ...
0
votes
2answers
24 views

How to set ContentDistribution password?

I kindly ask for help with setting ContentDistribution password on a published document link. In the Controller I have: ContentVersion conVer = new ContentVersion(); conVer....
0
votes
0answers
25 views

Need a trigger to count specific type of Case [on hold]

I discovered there's no option for a roll-up summary field on the account to count the number of related cases. Is there a trigger I can build that would do this? It would be count cases where the ...
1
vote
0answers
14 views

How to pass multiple param in invocable method

from visual flow i am calling apex class, while calling I need to pass 5 param(3 List, 2 String).but it is not accepting more than 1 param @Invocalble method how to solve this public class SendMail { ...
0
votes
1answer
15 views

Need solution on Child to parent if Parent values is changed to something else

I have a requirement where My custom Object(Market__c) is lookup of Account . Whenever my Account type value is changed from Inactive to Active I Need to capture current date to(Captureaccount__c) ...
0
votes
0answers
12 views

how to limit child records to 5 per day based on master field selection

There are 2 Custom objects Passport_Slot_Availability__c and Passport_Booking_Appointment__c.They both have master detail relationship. where Passport_Slot_Availability__c is master and ...
0
votes
1answer
20 views

Update users field on account using workflow or process builder

I have one field on user (Employee Number). Whenever the status of the account (Status__c) change to 'permanant'. I need to capture the employee Number in one of the account field ,who will chnage the ...
-5
votes
0answers
25 views

How to cover test code coverage for the below trigger code [closed]

Please help me to sort out this issue. How to cover(test class) the trigger code snippet. if (mapAccountKDNRTemp != null && !mapAccountKDNRTemp.isEmpty()) { Database....
3
votes
1answer
33 views

Unable to subscribe to platform event using emp api

I am trying to subscribe to my platform event using the empapi feature. This feature was added in v44. I am following the example of the documentation page: https://developer.salesforce.com/docs/...
1
vote
1answer
18 views

need to avoid firing trigger on perticular api invocation

I have written one trigger which fires on account create and update,but there is one API which creates/update account and if creation/updation is through that API i don't need to fire trigger. Please ...
0
votes
1answer
7 views

Beautify exceptions from triggers in Lightning UI

I have a function that I fire on an after insert or update of my Inventory__c object public class duplicateException extends Exception {} public static void preventDuplication (List<Inventory__c&...
0
votes
1answer
29 views

Update records only if the Values are changed- Before trigger [closed]

Here is the scenario. Am calling a REST API which returns a list of data that am trying to create as a record. But I don't want to update the old Records whose values are the Same. (Say I have 100 ...
2
votes
1answer
30 views

How to display Trigger addError in Salesforce Lightning using AuraException

Background I have a before insert trigger which returns an error: myObject.addError('Helpful Message'); Which I want to catch and display gracefully in my lightning component. My Apex controller ...
0
votes
1answer
20 views

Field is not writable for opportunity team member Name

Getting an error like An Apex error occurred: System.SObjectException: Field is not writeable: OpportunityTeamMember.UserId public class BD_UPDATEOppTeam { @InvocableMethod public static ...
0
votes
3answers
29 views

Restrict of updating opportunity owner

I want to restrict updating the opportunity owner. I cannot able to use the validation rule because ISCHANGED( Owner.Id ) is not working. Its giving the error like Error: The ISCHANGED function cannot ...
0
votes
1answer
29 views

If condition not working

If condition in a trigger has weird results. My condition is, if there are no values from my Set collection do not proceed. Even my debug statement shows NULL value. why this is happening?? if(...
0
votes
1answer
30 views

Using Process Builder to set Date field on Contact upon sending Mass Email

So far, I have attempted to build several processes to achieve this using the Process Builder. None of the processes are completing, or firing for all I know, because I don't get an error message if/...
3
votes
1answer
89 views

Eliminate query on Custom metadata type?

I'm trying to use Custom metadata type to replace a List type Custom settings. I have to access the Custom metadata type information in multipe apex classes and triggers. When I use custom settings, ...
0
votes
1answer
46 views

How to build a trigger for 2 scenarios in 1 object which will create/update multiple records in another unrelated object?

Scenario 1: a) Trigger on Custom Object 'Prod' only when record type = 'Forecast'. b) It should take data from 1 custom date field and 3 custom number fields in Object 'Prod' c) Then creates 3 ...
0
votes
2answers
32 views

add error method returning a null pointer exception

In a before insert trigger I added an addError message, but the error message is not showing, instead I get a NullPointerException. This is my code: trigger ValidateNIF on Account (before insert, ...
-2
votes
1answer
31 views

setTargetObjectId

Apex code: public class Anu { //static method public static List<Booking__c> sendEmail(List<Booking__c> bookings) { //query on template object EmailTemplate et=[...
0
votes
0answers
24 views

Passing a validation function in JavaScript to apex

I have a function written in javascript to validate a field and i need to transform that function to a before insert trigger. I'm a bit of lost in how to do this. This is part of my function: ...
-1
votes
1answer
37 views

How to deal with caseTeamMember Trigger

I have a requirement to add user to case team and need to validate that user should be skilled resource and should have specific skills otherwise do not allow to add that user to case team. I was ...
0
votes
1answer
72 views

Social Sign On for Salesforce Reg Handler Class and Test Class-System.NullPointerException: Attempt to de-reference a null object

My org is setting up social sign on with Google and I am running into an error I have never seen before: System.NullPointerException: Attempt to de-reference a null object Does anyone know a ...
-1
votes
2answers
112 views

update field with a trigger in custom object from pricebookentry

I have a custom object custom__c with couple of custom fields that needs to determine the price of the product. Custom_Child__c is a lookup field that gets the product. Price_Book__c is a lookup ...
-3
votes
1answer
34 views

EXCEPTION_THROWN [0]|System.QueryException: List has more than 1 row for assignment to SObject

I am getting System.Query Exception for my code below. Can anyone help me to rectify the same. public void updateOpportunityStage(){ Set<Id> setIds = new Set<Id>(); ...
-1
votes
1answer
48 views

How to update parent record when I update or insert child record, via trigger

I am new in salesforce developer. Trying to create trigger. I have 3 objects. Student Books Book Assignments On Book Assignments object I created Master Detail relationship with Book and created ...
-1
votes
2answers
70 views

Getting started with triggers

I am new to Apex programming and am trying to play around with different uses for triggers. Currently, I am trying to create a trigger that when a custom text field on our Opportunity object is ...
0
votes
1answer
30 views

OrderTrigger: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object

I got stuck at one place on one of my requirement on which I am working on. My use case is as follows: SCENARIO 1: Close Opportunity when Upgrade Order is cancelled GIVEN a a person account record ...
0
votes
0answers
25 views

Issue with Quote Line items

I want to create new Quote, as we all know when New Quote is created all opportunity products will be added as quote line items by default. Now In the Product Line Item there is a custom picklist ...
0
votes
0answers
16 views

Problem with UpdatePrice on product with trigger

I kinda feel I need to explain my logic better, because the more I test it the more problems i am facing :( My Product has the following product Family values: Bundle Software Hardware ...
0
votes
0answers
20 views

How to create trigger when user login?

How to create trigger when user login? On what Object? I try to write a trigger on User object but can't see System.debug() message because the log file is empty after login. Thank you.
0
votes
0answers
19 views

How to track stage of the opportunity record is not Closed-Lost (unless the stage was automatically set to Closed-Lost within the past 90 days

I am working on one requirement and I got stuck at one place. I hope someone will help me to resolve my problem and guide me in proper directions. My use case is as follows: SCENARIO 1: Close ...
1
vote
1answer
62 views

Exception in Database.save result in trigger context

1) In my opportunityLineitemtrigger, I have a method which updates the opportunity. system.debug('######'); database.saveresult [] rst = database.update(oppList,true); system.debug('######'+rst); ...
1
vote
1answer
37 views

How to have an approval process such that if any of the 2 out of 5 approvers 'Approve' the record in account will be Approved?

I have this Approval Scenario where I want to have this feature where : If one user presses the "submits for approval" button on the Account record, the approval process will go to 5 users to ask for ...
0
votes
0answers
15 views

Approval Process - can't see approver in target object trigger

when i send a record to approve by a user, i have to do some changes on this record, so i query the ProcessInstance and its StepsAndWorkitems. In the StepsAndWorkitems, i should be able to see ...