New answers tagged

1

In the documentation you mentioned, the object types are clearly stated for setEntityAttachments() Optional. Array of IDs of Document, ContentVersion, or Attachment items to attach to the email. where ContentVersion is a File.


4

If trigger starts working from another trigger, they are executed in same transaction. It can be easily tested by these samples: 1st Account trigger that calls Opportunity trigger: trigger AccountTrigger on Account (after insert) { //in 1st trigger you see opps update, so they call 2nd trigger system.debug('1st trigger: before SOQL: ' + Limits....


1

updateDA is typed as a List<Dealer__c>. The type that has fields Account_Name__c etc. is Dealer__c, which is the type of the elements of this list. The list itself does not have these properties. You would need to iterate over this list in another for loop to access those properties on each element. But... there are much bigger problems here. This ...


1

The answers above appear to contradict each other, so it's worth adding some clarification. The need for Database.setSavepoint() and rollback depends in part on whether you are using a try/catch block in your code. One way to prompt a SystemDmlException is to set a phone field to a value with more than 40 characters. If you use Execute Anonymous to run ...


4

You're right. Flows are not the correct tool for this type of job. Use Apex triggers and/or batch jobs to update the rollup summaries. You can use DLRS if you don't want to write your own Apex.


0

Can you ensure you have selected "All" in the list view as shown in the picture. This should fetch you all the triggers in your org.


0

Email templates are intended to be used with a related record, so one possibility here is to enable your community users to set a field on a record with the URL you want them to set, save it, then send the email with the field exposed in it. This approach lessens the amount of code you would need to write, but it would consume a field from some object in ...


0

I believe your problem is here if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred and' + ((math.mod(i , 100) > 0)?' ' + convert(math.mod(i , 100)):''); you are appending and always, try with appending it only if there is something behind if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred' + ((math.mod(i , 100) > 0)?' ...


0

I was able to solve this. That DML delete statement was causing a problem if one record failed to delete, so I used Database.delete(list,false)


1

If you want to preempt the Lead Assignment rules (while keeping them active): for certain Leads created by any client where such client instructs SFDC to run lead assignment rules (such as Web-to-Lead) do the following: Add a custom field to the Lead - Has_Preemptively_Assigned_Owner__c (checkbox, default to false) Add as the VERY FIRST lead assignment ...


0

First, you need to get familiar with Apex Sets and Maps, how to use sets in SOQL queries, and how to build Maps and reference their values. Check the documentation, Trailhead modules, Salesforce youtube channel for info on these Apex fundamentals, as well as various free and paid tutorial resources. For your use case, here are the high-level steps you need ...


0

In hindsight, this question is fairly dumb and I've figured out the problem. In a trigger that is set to before insert I was calling insert on the triggering item after having added the contact to the case. That seems like something that shouldn't work, and simply commenting out that line allows the code to function.


1

Remove the LIMIT from your query. Every batch of 200 records will only delete a single record. Also, you don't need to check for empty lists before you iterate over them/DML on them. Here's the optimized version: global void execute(Database.BatchableContext BC,List<Account> accs) { List<AccountEvent__e> aevents=new List<AccountEvent__e&...


2

Since you are setting the HTMLBody, have you tried the following? body = issues.replaceAll('\r?\n', '<br/>');


0

You have to use adderror method to show the custom error message either in record level or at field level. Please refer the below code for reference trigger AccountTrigger on Account (after update) { for (Account acct: Trigger.new) { acct.Name.addError('Error added to Name on trigger'); acct.addError('Error added to account on trigger'); } }


0

See if you have Process builder with this name = "Opportunity Updates" Check this id in that process when updating the record action: a0G1U000003g8cd and check this if this id valid or not your org and update accrdingly . May be record deleted or user deactivated with this id. Thank you.


1

Just to add another option - you can use Approval processes on Knowledge. This would require that everyone "submit for approval" instead of "publish" (you can hide the button). It asks for certain criteria to require the approval, else Approve. In your case, you'd essentially just be auto-approving everything. From here, you can set up actions to take ...


2

Looks like this limitation is clearly documented. One workaround would be to maintain a custom field (may be a picklist or a Boolean ) and trigger off based on that and publish an article based on the custom field value. If you are on classic lightning this would mean a field on Evey article type and hence lightning migration might be something to plan. ...


1

The field values from the original execution context remain constant regardless of the pauses.


0

I was able to solve this by just removing the object which i was creating in the update method. Thanks everyone.


1

it is possible, go to account. create a Rollup summary field let say 'count opportunities' . select Roll type as count and set the calculation filter like stage not equal to closed lost/closed own. (based on business req. which is open opportunities')and expose this field to account layout. so when ever the opportunities matching the filter criteria , it ...


0

Trigger.new doesn't house any id before insert. Since the record has not been created yet. Change it to after insert and when any new Email is created you can see the fields you added while creating. trigger EmailMessageHandler on EmailMessage(after insert){ for(EmailMessage email : trigger.new){ System.debug(email); } }


0

When you have set Opportunity o = new Opportunity(Id=t.WhatID);, you've created a copy of original opportunity that knows only about its own ID and nothing else. You should quey the opportunity instead. Also mind that queries in loop should not be used. So gather WhatId in List, query Opportunities with related Accounts once, than query needed Accounts once ...


0

This is the standard aggregate-query-update pattern, but with a twist: the relationship is polymorphic, so we need to do dynamic queries. Here's what the trigger would look like: trigger MakeEmailsPublic on EmailMessage (after insert) { // Aggregate // Map<sObjectType, Set<id>> recordIdsByType = new Map<sObjectType, Set<Id>>()...


4

No, static variables reset only when the transaction finishes, not after every DML operation. This is why using this "recursion blocking" technique is often a Bad Idea. The only time you should use this technique is to block actual recursion. Some people call the "second trigger" from workflow field updates a "recursion", but it's not. It's a one-time repeat....


1

Just return the list in the start method: public class InsertBatch implements Database.Batchable<sObject> { sObject[] source; public InsertBatch(sObject[] records) { source = records; } public sObject[] start(Database.BatchableContext context) { return source; } public void execute(Database.BatchableContext context, sObject[] scope)...


2

You can determine the context you're in and go from there, but this can be kind of complicated by its own right. Note that this linked answer leverages some rather undocumented features and may break at any time, so use at your own risk. Generally, if your triggers are decently designed, they should be able to run "all the time". which is ideal, as it ...


2

I'd recommend looking through the trailhead on triggers. You have the list of objects in the trigger. No need to then re-query them. Loop through what you're given in the trigger context. The reason it's firing on every record is because you're just checking that Status == Closed. Therefore, all records that meet that criteria when they're updated will ...


2

As you've found out already, we can't make callouts directly from triggers. Instead, we need to make the callout from a new (and asynchronous) transaction. That's typically done with either @future or a class that implements the queueable interface. In any case though, it's simply not possible to get the result of your callout into the initial trigger run (...


1

Below code is unnecessary in your trigger List<Id> sLine = new List<Id>(); for(Service_Line__c i:trigger.new) { sLine.add(i.Id); } Simply pass trigger.new to the handler and change the handler's method signature public static void statuschange(List<Service_Line__c> ServiceLines){ After that, you would not need to have the SOQL with ...


0

In below code Ultimate_Parent_Account__c is a Lookup(Account) field. trigger UPA_Trigger on Account (before insert,before update,after update, before delete) { if(Trigger.isBefore){ if(Trigger.isInsert||Trigger.isUpdate){//before insert, before update List<Id> parents=new List<Id>(); for(Account a: Trigger.New){ ...


0

I know this post is old but answering would help the community. With the recent changes, we can compare attributes in Journey (decision split). Remember to check 'Add an attribute to compare' checkbox, which will allow you to drag and drop the attribute from the library.


0

You cannot create a map with the key you specify in your example because they are duplicated. (line 3 and line 5 Group2-100) KEY VALUE Group1-100, 1 Group2-30, 3 Group2-100, 1 Group2-2, 2 Group2-100, 1


1

I think you're inadvertently making this harder than it needs to be. In the end, it boils down to a few simple steps: Generate the key for the current iteration Check to see if your map contains that key (add it if it doesn't) Update the value Map<String, Integer> groupQtyToCountMap = new Map<String, Integer>(); for(QuoteLine__c lineItem : ...


1

You might find it easier to use a non-String key instead: // Use Group-Quantity as a composite key // Map<QuoteLine__c, Integer> groupQtyMap = new Map<QuoteLine__c, Integer>(); for(QuoteLine__c record: quoteLines) { QuoteLine__c key = new QuoteLine__c(Group__c=record.Group__c, Quantity__c=record.Quantity__c); Integer counter = groupQtyMap....


0

Posting Answer for my question it may save your time if you facing same issue or looking similar solution. External Id does magic when we want to insert Parent Child in same transaction - Here is working code trigger Renewal_Opportunity_trigger on Opportunity (after update) { List<opportunity> newopp = new List<opportunity>(); ...


2

Your queries and your oppByStrings do not do what you want. for (Property__c prop : propList) { oppIds.add(prop.Id); } List<Opportunity> opportunities = [SELECT Id, Name, Escrow_Company__c, Escrow_Address__c, Escrow_City__c, Escrow_State__c, Escrow_Zip_Code__c FROM Opportunity WHERE Id IN : oppIds]; This query ...


0

First of all let me tell you it's not recommendable and doesn't come under best practices to query inside a for loop. You have made the query filtering all the records created this week, if you're ok with the records it's giving back then its ok. If not, then please try to put query filter as: CreatedDate = LAST_7_DAYS instead of : CreatedDate = ...


3

Most of your assumptions are fundamentally correct: you may mutate objects in Trigger.new without performing DML, and your updates will be persisted transparently. There appear to be two issues preventing your unit test class from behaving as expected. Your test setup includes no Opportunities associated with the Account. opps.size() will then always be ...


1

You're allowed 250k future calls per day (combined with other things such as QUeueable, Batchable, and Schedulable calls); you should probably be okay. However, one thing you should do is batch the calls into groups of 100 for performance reasons. List<List<Id>> batches = new List<List<Id>>(); List<Id> temp; batches.add(temp = ...


1

Don't. This class is not suitable for use in a trigger context because it runs a query and a DML operation for each record Id. This code needs to be rewritten in accordance with principles of bulkification to be used in a trigger context. There are a variety of helpful trigger handler frameworks available that provide skeletons for building handler classes ...


1

Assuming you have set the date field on Monthly_Sales_Target__c object as unique, as similar dates may give you erroneous data. Here is the pseudo-code through which you can perform your functionality: Iterate over the list of all opportunities where status is closed(won or lost). Make a map with the key as closed date of opportunity and list of ...


2

You are getting this error because you are trying to pass an instance of Map<Id, sObject> where it expects it to be of type Map<Id,Order> i.e. it expects the concrete type. So, like you are typecasting List<sObject> to List<Order>, you will also have to typecast Map<Id,sObject> to Map<Id,Order>. Although this typecasting ...


1

Tushar, I've gone through your code and try to put it without nested for loop. To avoid nested for loops we must make use of maps in such a way that we get everything we need from one iteration. So for that we can make changes to accconIds value from : accconIds.put(cs.AccountId,cs.ContactId); to : accconIds.put(cs.AccountId,cs.ContactId+'###'+cs.Id);...


1

Problem is that you are passing in first parameter a Map<Id, Order> and it excepts a Map<Id, SObject> Map<Id, Order> cannot be casted in implicit way from Map<Id, SObject> These types are not in same hierarchy, so Map<Id, Order> is not extending Map<Id, SObject> like its for eg. pair SObject -> Account Trigger.oldMap ...


0

You need to define a parent object in for loop and then added to parent list and upate this public class StatusClosedHandler { public static void statuschange (String RecordId){ integer count = 0; List<Service_Request__c> srequest = new List<Service_Request__c>(); for(Service_Line__c sl : [Select id, ...


0

Basically, you need to create a new variable for the Parent and update it. public class StatusClosedHandler { public static void statuschange (String RecordId){ List< Service_Request__c> servRequestList = new List< Service_Request__c>(); //list of Parent integer count = 0; List<Service_Line__c> sLine = new List<...


0

For your line no.4 you can just add newAcc.name = newL.LastName; There are some best practice while writting trigger. Dml and Soql in for loop is not a best practice. You can learn from this link description here.


1

A query returns a list no matter what, but can be cast to a single sObject when it results in a single record. But you can't reference the field directly, as you're doing. With the query in it, line 4 could be: newAcc.name = [select LastName from Lead where id = :newL.id LIMIT 1].LastName; But you don't need to query the Leads, and indeed you definitely ...


2

Your class is explicitly taking no action if the Primary_Email__c field is populated, which would be the case if you changed an existing value in the Exchange_Contact__c field: if (oppt.Exchange_Contact__c != null && oppt.Primary_Email__c == null) { You'll likely want to change this to something like if (oppt.Exchange_Contact__c != null &&...


Top 50 recent answers are included