Questions tagged [trigger]

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

0
votes
1answer
40 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
21 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
20 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
27 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
31 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
16 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
21 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
23 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
34 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
25 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
17 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
22 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
25 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
47 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 ...
-1
votes
0answers
28 views

Need help on assert on test class for pagereference [duplicate]

I am not able to get how i can use assert here as a test class best practice. below is the class public with sharing class MyDomainDiscLoginDefaultHandler implements Auth....
0
votes
1answer
28 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
41 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
47 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
55 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
37 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
57 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
26 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
23 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
41 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
36 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
53 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
60 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
82 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
32 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
44 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
22 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 ...
2
votes
1answer
77 views

Refer a string as a field API name

Is it possible to refer a string as a field API name? I'm trying to achieve something like below: Method(string fieldAPI){ Contact con = new Contact(); con.fieldAPI = 'Abc'; update con; }
4
votes
1answer
116 views

Enqueue Queueable class multiple times

I need to do five different callouts from my trigger. I'm planning to use one Queueable class for all the callout using the parameter passed in the constructor. I'm not sure if it is possible, if it ...
0
votes
1answer
70 views

Conflicting triggers

I'm still new to Salesforce and still can't grasp regarding triggers. Scenario: My company's salesforce workspace has a managed package app installed. The managed package app has a custom trigger for ...
1
vote
2answers
45 views

Before Trigger is not picking up BillingCountry on the Account Object

My class is suppose to pick up The Billing Country and Billing Postal Code and populate the state based on those two fields, however when debugging the before trigger It doesn't pick up the Billing ...
2
votes
3answers
598 views

Is my test coverage up to snuff? [closed]

I've got a theoretical, rather than a practical, question today. I just wrote the trigger and test class below. I'd love to get feedback on such questions as: 1. Do I test sufficient cases? (It gets ...
1
vote
3answers
26 views

Add check of user profile to a trigger

I'm writing a simple trigger to prevent deletion of opportunities that are marked Receivable. (Code below.) Could you help me add a criteria to allow deletion if the user doing so is a sysadmin? I ...
6
votes
2answers
156 views

Does addError() work outside of triggers?

I moved a method that sets addError() from a trigger into a Helper class. As I started writing test code for it it seems like the addError() is not actually preventing DML operations for the records ...
0
votes
1answer
39 views

How to rank Users depends on a custom field in apex? [closed]

Question in detail : I have 20 Users {U1, U2, U3....} and 5 Regions {R1, R2, R3, R4, R5} and Ammount__C custom field on User. Now those users are distributed among those regions. So i want to give ...
0
votes
1answer
24 views

showing all related contacts in an account custom field

hey i am trying to write down a trigger in which all related contact lastname of an account will show in an account custom field. i wrote down this trigger and the problem is it is showing only latest ...
0
votes
1answer
33 views

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert: execution of BeforeInsert

ERROR: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadConvert: execution of BeforeInsert caused by: System.SObjectException: ...
-1
votes
1answer
45 views

Update opportunities when account field is changed

I have the below scenarios: Sobject/Field Information: Status__c field on Account - New, In Progress, CLosed StageName field on Opportunity - New, In Progress, Closed Scenario 1: Whenever Status__c ...