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
1answer
39 views

Trigger to make autonumber field on account with format 'ACC-001'

I need to create a trigger that will autopopulate the field created in Account object. The field value will be auto populated using the value like 'ACC-001','ACC-002' everytime an account is created. ...
0
votes
1answer
54 views

Auto-populate fields w/o Triggers [closed]

Is there any way to autofill custom fields without using a trigger while still using Apex code? I have fields that are aimed to be filled in based on more complex logic and accessing information of ...
1
vote
1answer
16 views

Can the below code be Optimized and include the logic to check for related opportunityteammember records before updating checkbox to true?

Need help in Optimizing below code. Requirement is to update "opportunity shared" checkbox on "Opportunity" object whenever opportunity is un-shared. (Delete trigger on "Opportunityteammember" ...
-2
votes
1answer
26 views

whenever i change account active field related case status field should be changed to working..please help me out with this

trigger AccRecCase on Account (after update) { map<id,account> oldMap=Trigger.oldMap; //old records ids map<id,account> newMap=trigger.newMap; //new record ids List<Id> ids=...
0
votes
1answer
28 views

Why it is not updating the YourMail__c after Recursion Handling?

Class: public class Hr { public static Boolean f_t = true; } Trigger: trigger HandleTrigger on Input__c (before insert) { if(Trigger.isInsert){ if(Hr.f_t){ Input__c acc = new ...
0
votes
2answers
39 views

Apex after insert trigger - variable does not exist

I am calling another class from my trigger and it works in sandbox, but when I try to validate my deployment (I am using a change set to deploy) in prod, it says "variable does not exist: ...
-2
votes
1answer
50 views

How to write test class for Database.error [duplicate]

for (Database.SaveResult result : results) { if (!result.isSuccess()) { for (Database.Error error : result.getErrors()) { System.debug('Error returned: ' + ...
-4
votes
1answer
54 views

Test class for below class [closed]

public class ExampleClass { public static void publishCaseUpdateNotifications(List<Case> cases) { List<Case_Updated__e> notifications = new List<Case_Updated__e>(); for ...
0
votes
1answer
38 views

How to achieve code coverage for trigger after lead conversion

I have a trigger on lead and wrote a unittest but are not getting any codecoverage. What amI missing. Trigger trigger LeadTrigger on Lead (before insert, before update, before delete, after insert, ...
0
votes
2answers
46 views

Account Apex Trigger Help

I'm trying to prevent the deletion of accounts if one of the contacts within the account has a "Do Not Delete" checkbox as true. Here's a trigger (My very first one!) Please let me know if this is ...
0
votes
1answer
79 views

Apex trigger helper class - deployment error “variable does not exist”

I'm trying to deploy an apex trigger from sandbox to production. But when I test/validate in production I'm getting the error "variable does not exist" for the trigger's helper class: Trigger '...
0
votes
2answers
36 views

How to display validation error in same page using trigger on click of delete button?

How to display validation error in same page without redirecting to new page using trigger on click of delete button?
0
votes
1answer
44 views

SObject row was retrieved via SOQL without querying the requested field: s2cor__Sage_INV_Trade_Document_Type__c. s2cor__Use_Company_Shipping__c

I have a C# application that was meant to upload invoices to salesforce financials. All other functions of the application works fine except the uploading module. During the upload process, I have to ...
0
votes
1answer
25 views

validation rule for sum of percentage field should not be more than 100%

HI I am looking validation rule and am not sure whether can be done with validation rule. I have a task where I will mention an account executive and assign quota and revenue % for that account ...
0
votes
0answers
21 views

Method does not exist or incorrect signature: void setToaddress(List<String>) from the type Messaging.SingleEmailMessage [duplicate]

trigger mailsentcreateaccusindtri on Account (after insert) { //list<string> mail= new list<string>(); if(trigger.isafter && trigger.isinsert) { list<...
0
votes
1answer
25 views

Apex Trigger Based On Related Links Changes

I want to sum the number of Opportunities Related Links using a field trigger (I know I can do a roll up summary, but i cant use it as it is unclickable for the object I am using); I was wondering how ...
0
votes
1answer
28 views

Field information not updating?

I want to update a custom field using Apex triggers. However, after "updating" it doesn't seem like it actually changes the value of the fields. Here is my code (in Apex Execute): for(Contact c:[...
0
votes
0answers
11 views

put value in parent related list can uh explain me how can create trigger? [duplicate]

trigger ProductDetail on Design_Selected_Junction__c (After insert) { if(Trigger.isInsert){ Set<Id> designTemplateSet = new Set<Id>(); Set<Id> oppSet = new Set<...
0
votes
0answers
32 views

How to disable the trigger in production with the custom label

I have one trigger onAccount which is not allowing me to insert update new Accounts to other objects so I would like to know how could I disable the trigger/class in the production without moving in ...
0
votes
0answers
18 views

Is there a way to send email alert when Omni-channel is set to offline automatically or by user in salesforce?

We have a requirement where we have to send email alert to current user when his/her omni-channel is set to offline. I don't see an option to achieve this using Process Builder. But would like to know ...
0
votes
0answers
21 views

Calculating the Min of Date from the related list

I am having one big task and from the last 2 weeks I am working on to solve it but without any result. Please help me out to solve this puzzle. So we are having one object Entity group, which is the ...
0
votes
1answer
23 views

type=meeting for all events

I have a requirement where I want to put type=='meeting' for all the events type has a picklist data type where meeting is a value Here is the trigger I have written but it is not working. trigger ...
1
vote
0answers
27 views

Selecting the Opportunity Price Book

I'm still fairly new to Salesforce Apex and trying to figure out how to select a price book from the opportunity. The reason being I have a trigger which adds in a product when the opportunity is ...
-1
votes
1answer
36 views

Trigger; Initial expression is of incorrect type, expected: String but was: List<String>

//trigger code trigger mailsentcreateaccusindtri on Account (after insert) { //list<string> mail= new list<string>(); if(trigger.isafter && trigger.isinsert) { ...
0
votes
2answers
28 views

How to remove an option from mutli-picklist field in apex trigger

I want to write an apex trigger action to remove a particular value from multi select picklist field based on some condition.How can I do this? This is my trigger action: public static void ...
0
votes
1answer
20 views

Need to call different method from same class on Trigger context

I have written one class and inside that there is method which calling one small method ,what i need is to call inside method based on Insert and update If Operation is INSERT then call one method if ...
0
votes
1answer
18 views

Populate contact field based on email

We're doing a demo of Survey Monkey and can't seem to get the contact populated from the form mapping. My solve for this would be to make a trigger that looks at the required email field and finds a ...
2
votes
1answer
24 views

Standard User profile gives error for delete task trigger testclass

I have trigger to stop users to delete task except if profile is "System Administrator". Trigger : trigger TaskTrigger on Task (before delete) { if(Trigger.isBefore && Trigger.isDelete){...
0
votes
2answers
27 views

When an approver is dynamically chosen on the base of a related field is possible to reassign the approval step through apex?

Suppose to have an approval process where the approver of a step is a related user designated through a custom field. If the value of the custom field is changed, all the records in this approval step ...
0
votes
1answer
48 views

How can I resolve these two errors in trigger handler

public class AttachmentTriggerHandler { public static void onAfterInsert(List<Attachment> attachments) { handleCreditReportAttachments( attachments ); } public static ...
0
votes
1answer
29 views

How SWAP(rows UP and DOWN) in Pageblocktable in Visualforce page using Apex method

Here I'm Trying to do swapping on Pageblocktable means I want my rows to be Up and down Right now it's happening through Javascript Now I want this through APEX method. Please look at the below ...
1
vote
3answers
44 views

Trigger calling future method

I have inherited an after insert lead trigger that calls a future method. Based on the response returned by this method, it inserts records in an object. Lets call this object -LeadCopy__c. Lead --&...
0
votes
1answer
50 views

How to write trigger handler class and test class? [closed]

I wrote trigger which i want it to implement via handler class (As per best practice). Please help. trigger PreventTaskDelete on Task (before delete) { Id profileid = Userinfo.getProfileId(); ...
1
vote
2answers
63 views

Getting the highest Parent Account in Salesforce Hierarchy via SOQL/APEX

I am trying to get the highest level of parent account in an Account Hierarchy in Salesforce via Apex and SOQL. I want to create and MAP<Id, Set<Account>> hierarchy in my Apex class to ...
0
votes
1answer
23 views

Custom error messages on standard salesforce edit view from other object trigger

When I insert a Case I have a trigger that automatically inserts an opportunity among other things to that Case. When something fails due to an expected error I want to be able to customize the error ...
-1
votes
3answers
38 views

Error Error: Compile Error: Unexpected token 'lacc'. at line 5 column 4 [closed]

public with sharing class Myfirstvfclass { public list<Account> lacc { get; set; } public Myfirstvfclass{ lacc=new list<Account> ([select id from Account]); } }
1
vote
1answer
63 views

Getting 'FATAL_ERROR System.TypeException: DML operation INSERT not allowed on Group' on Apex Trigger

I am getting: "FATAL_ERROR|System.TypeException: DML operation INSERT not allowed on Group" error on an apex trigger (line 43) when I am logging in as any other user except System Admin. I am ...
-1
votes
1answer
28 views

Code not executing in child aggregagtor

I can't understand why I am not getting my debugs in here-- my code is for(AGR_Agreement__c agr:newAgr){ for(Account acc:agr.Accounts__r){ system.debug('MVK '+agr.AMS_Agreement__c); ...
0
votes
1answer
24 views

Creating scheduled email for every new leads

I have a business requirement to send email alert every Friday @ 9 AM after creating new leads. The problem is, I don't see any option where I can specify time or hours in Process Builder. I see ...
-1
votes
1answer
25 views

Apex Trigger Avoid nested loop while inserting or updating record child-parent relationship

public class UpdateandInsertAccountRecordHandler { public static void onAfterInsert(List<Account> accList) { Set<Id> aNames = New Set<ID>(); FOR(Account A : ...
2
votes
0answers
46 views

Issue with Insert Trigger after Workflow Field Update

I've an interesting issue here with the combination of Trigger and a Workflow Fied Update on the Opportunity object. I do know/understand the Apex order of execution and also the fact that Salesforce ...
0
votes
1answer
40 views

List.Add() not working

I've got the following code snippet in a trigger handler class x1 = trigger.new; List<Id> listx = new List(Id); For(integer i = 0; i < x1.size(); i++ ) { System.debug('Loop ...
3
votes
1answer
60 views

QueryException - query non selective

I recently deployed a trigger to production. Inside it was the following query: SELECT Id, (SELECT Business_Unit__c, Department__c, Role__c FROM Account_Roles__r WHERE Role__c IN :roles AND ...
1
vote
1answer
63 views

Variable does not Exist: CaseTrigger

I'm trying to pass a value to a variable in an apex trigger from an apex controller in an effort to control whether the the code in the trigger is executed. In myController initialization, I try to ...
0
votes
0answers
25 views

Help with Apex test method for SurveyQuestionResponse [duplicate]

I created an AFTER INSERT Trigger on SurveyQuestionResponse. But it showed error "DML operation Insert not allowed on SurveyQuestionResponse" while tried insert SurveyQuestionResponse in test method. ...
6
votes
1answer
86 views

How would I test a trigger on non-writable SurveyResponse object?

I'm using Salesforce Survey for one of the requirements. I would like to write a trigger on SurveyResponse object. I've written the trigger and apply the logic that I need. Now, I'm trying to write a ...
0
votes
1answer
33 views

Triggering field update based on related list

I have a custom object called "Request for Startup" and an Opportunity. Several "Request for Startups" can be related to one Opportunity. Hence I created a junction object called "Request for Startup ...
0
votes
1answer
30 views

How to appropriately handle before triggers idempotency in beforeInsert triggers?

As Daniel Appleman, has noted in his book "Advanced Apex", it is important to design triggers so to be smart with respect to recursion and re-entrancy. Take the following requirement that mirror our ...
-5
votes
2answers
45 views

Error: Compile Error: Variable does not exist: ac at line 9 column 6 [closed]

trigger DupRecError on Account (before insert,before update) { //List<Account> acList=new List<Account>(); for(Account acc:Trigger.new){ List<Account> ac=[select id,name,rating ...
0
votes
0answers
23 views

Mirror a case's Chatter feed to another object (ConnectAPI vs sObject)

I've got a requirement to mirror a Case's Chatter feed into another object (for safe-keeping, as it were). My first idea was to try a trigger on the FeedItem object, catch it and clone it, and just ...