New answers tagged

2

This Best Practices for Designing Processes mentions the following Each time a record is created or updated, all record-change processes for its object are evaluated. We recommend restricting your org to one record-change process per object The benefits are: Get a consolidated view of your org's automation for an object Avoid hitting limits Determine the ...


1

Well, this is kind of a religion question. I personally would recommend to stick to one method, where ever possible. Either Flow or Trigger. So you are in control of what happens when. Order of execution. If you have a relative small org, it's no problem to use both. But when it grows and you have large complex flows, triggers and maybe process builder it ...


0

As mentioned by Derek in comment section, you need to make corrections to the extra curly braces ({ and  }) and for loop at the start of the trigger.Added to this as it is after insert operation , we have to mention the update statement on the record. By changing the code as below it worked for me . trigger updateCampaignTypeonLead on CampaignMember (after ...


0

You can do this, but it requires slightly more code, may be much slower than your current code, and may actually run in to different limits (the 2000 aggregate result limit). Basically, we have to now group by stage as well, and check each stage to see if it's a won state or not, and then update the fields appropriately. Here's a rough draft of what that ...


0

If you are referencing named credentials that are included into a package with a namespace, then you'll need to add package namespace to the callout name. The callout could work in a Development org because the org had the same namespace as the Named Credentials so the namespace was optional. HttpRequest req = new HttpRequest(); req.setEndpoint('callout:<...


1

You're returning a query from the Case object, then trying to assign the values to a User object. This causes the execute method to be skipped. You need to change your query to use the User object. global Database.Querylocator start(Database.BatchableContext BC) { return Database.getQueryLocator([Select Id FROM User]); } Your code also has a couple ...


2

if (Trigger.isInsert && Trigger.isUpdate) { This is always false. A trigger context can't be both insert and update at the same time. That's the immediate cause of your trigger doing nothing. But you have a lot of other issues here. You need to bulkify the trigger (remove all DML and SOQL from loops). See Bulk Apex Triggers on Trailhead. You need ...


1

The query on Account can be moved out easily using the whole newAccountList as WHERE clause. Then a Set is needed to store every "free" phone number. At first it should be filled with every phone number from the accounts, so it can be used to retrieve all Contacts at once, then the contacts' phone must be removed from the Set. Done that, the Set ...


3

Looks like you might have a class in the system with the name opportunity. Either rename that class to something or instead of Opportunity use System.Opportunity


2

In database terminology, when a record is updated, there's a "lock" that is set so concurrent updates won't clobber each other. Salesforce does allow some wiggle room, about five to ten seconds, before failing to acquire the lock, however. So, either both updates will succeed, or one will fail (whichever one tried to get the lock last). If it fails,...


0

It's likely due to the extra space you have after the comma. Also, you can write this in about two lines of code. I've modified the below example so it won't care if there's extra spaces. Set<String> accountRecordTypes = new Set<String>(Label.AccRecordTypes.split(',\\s*')); Account[] acc1 = [SELECT Name,RecordType.Name FROM Account WHERE ...


0

First Go to the Case Object and then Open Your Parent__c field. Now you got the Relationship Name here. Then follow below Query : SELECT Id, (SELECT Id, parent__c FROM RelationshipName__r) FROM Case WHERE Id IN:SetIds NOTE : If you are Using Custom Lookup Field for relationship Query, You must append the "__c" at the last of RelationshipName. ...


6

i would like to know if it's possible without using another soql in the after insert trigger for exemple ? No. A trigger only includes the field values of the record you're on, not any records it links to. To get values off parent records, you have to perform a SOQL. If you want to avoid a SOQL query, you'll need to use a formula field. You can have a ...


1

The Cases relationship uses the built in ParentId field. Since you're using a custom lookup field, you need to use the custom relationship name, likely Cases__r.


2

You need to parse these ids to List (remove single-quotes on both sides of field1 and split the result on ','): String field1 = '\'a712D000000AZ3yQAG\',\'a712D000000AZ46QAG\''; List<String> ids = new List<String>(); if (String.isNotBlank(field1)) { field1 = field1.substring(1, field1.length() - 1); // this removed single-quotes on both sides ...


2

System.debug(sObject) does not show parent or child relationships, only direct fields. The value is being queried, and is available in memory, but will not be output in a System.debug statement unless you somehow serialize the record: System.debug(JSON.serializePretty(caseList));


0

I can see you've got most of your code in order, although it certainly could have been optimized. You probably got stuck because you have a list of Contact Id values, and what you needed were names. As such, Map<Id, List<Id>> should actually have been Map<Id, List<String>>, and you wanted to collect the names, not Id values, of the ...


1

It is not advisable to switch from addError to throw. If you do so, you will make all bulk operations all-or-none, disabling partially successful saves. Maybe you will decide that is a worthy tradeoff, but it is a brittle architecture and I would fight against it if someone suggested it in any org I've worked on.


1

Assuming your workflow is on Opportunity, the opportunity will never have a DML event when its related objects SubscriptionFee__c or Rate__c objects change values. That is, a workflow on Opportunity doesn't monitor changes on related object fields that influence the value of Opportunity formula fields. A workaround is to add after-save Flows to both the ...


0

Formula fields cannot be tracked as the value of this field is calculated on runtime, and it is not saved to database. So the value is calculated for example when user opens the record detail page or upon query from database. Documentation If you want some work around, you would have to create a trigger and upon update of any fields which is coming into ...


0

Based on the line number you have mentioned. There might be a null getting entered here orderedProducts.add(o.Product2); So after this line you can write orderedProducts.remove(null);, so that it does not contain any null values. So your code will look like this: for(OrderItem o : trigger.new){ newOrderItemIds.add(o.Id); if(o.ServiceStartDate__c == ...


1

Seems your problem is here: for (orderItem o : itemsMissingStartDate) { Integer leadTimeDays = itemsWithLeadTime.get(o.Product2Id).intValue(); // map may not contain key } Your itemsWithLeadTime.get(o.Product2Id) call can certainly return null. You can drop the .intValue() call as it serves no purpose here, but then you just move the NPE down one ...


2

Callouts aren't supported in triggers, however, you can call @Future(Callout=true) method (docs) or enqueue class that implements System.Queueable, Database.AllowsCallouts (docs) with necessary information about updated records and make POST request there. You can also create Process in Process builder on fields change and call Apex method with @...


0

This error you are receiving is not related to the addError() methods you are using. Probably on this line ob2.EURO__c = EURODollar * ob2.Currency_Rate_EURO__c; you have ob2.Currency_Rate_EURO__c which is null. And this null is then evaluated in the * operation which is causing this error. And if you want to display this message to user in readable form you ...


0

In this case you should collect all values for Sold_To_Party__c above the loop and do a single query to retrieve all the team members for all those accounts; Set<Id> soldToPartyIds = new Set<Id>(); for(Sales_Order__c shareObjt: newList){ soldToPartyIds.add(shareObjt.Sold_To_Party__c); } List<AccountTeamMembers> members = [ SELECT Id,...


0

You first need to iterate through the newList, create a map of sales_order__c by a key sold_to_party__c. Then query for accountTeamMember where accountIds are in the keys of the map. Then iterate through this queried list and from the map get the related Sales_order__c. public static void sharetoTeam(List<Sales_Order__c> newList){ list<...


0

Trigger should be written on contact object. The below code is working for all listed operations: Inserting Contact with an Account Updating/Switching Accounts on Contacts ( this will update the count on both the Accounts ) Removing Account from Contact Deleting Contact Undeleting Contact trigger ContactTrigger on Contact (after insert,after update, after ...


5

The only way to persist anything from a transaction that fails is to use a Platform Event. Crucially, you need this Platform Event to publish immediately, not when the transaction finishes. Define a Platform Event with fields to store whatever data you need to send out, then have its subscriber trigger send your email.


0

As @DerekF said in his answer, custom settings are data and so need to be created in the context of unit tests. However, what Derek didn't mention is that if you do this, and actually commit custom settings instances to the database, you will run into database locking problems if you run unit tests in parallel where the same instances are created in the ...


0

Custom setting data is data (as opposed to being metadata). That means that you need to explicitly create data for them in tests, just as you would for an Account, Contact, or Opportunity. If you were to use a Custom Metadata Type (which is suggested as a replacement for list-type custom settings), then you wouldn't need to explicitly add records for it in ...


2

There is this example in the Using the runAs Method documentation that shows how to switch profile in a test: @isTest private class TestRunAs { @isTest static void testTriggerUsingRunAs() { // Create a unique UserName String uniqueUserName = 'user' + DateTime.now().getTime() + '@org.com'; // Pick the Profile you want ...


0

Some working code to invoke through apex with conga 8 since nobody else seemed to share here yet :) I almost believed it wasn't possible after seeing responses above but I was able to make it work! private static final String CONGA_ENDPOINT = 'https://composer.congamerge.com/composer8/index.html?'; String templateId = [SELECT APXTConga4__Key__c FROM ...


0

Test methods by default cannot see pre-existing records in an org. The test method itself should insert the records it needs. So this code: callReport.Loan_Apps_to_Relate__c = 'a071F00000A99Z4QAJ,a071F00000A99YpQAJ'; Loan_Application__c loanAppRelate = new Loan_Application__c(Id = 'a071F00000A99Z4QAJ'); Loan_Application__c loanAppRelate1 = new ...


2

Seeing your trigger logic would help quite a bit, but It's worth noting that hard-coding Ids in your tests is typically a bad idea. Your best bet would be to actually create and insert your Loan_Application__c records before inserting your Call_Report__c record. Then, you'll have to re-query your Call_Report__c record to get any field updates that happened ...


1

Given that Require Validation for Converted Lead is unchecked, DML events on the converted objects (Account, Contact, Opportunity) do not initiate triggers or other automation. However, there will be a DML event on the Lead itself (to set IsConverted = true and also set the Ids of the converted Account, Contact, and Opportunity. So, using either an after ...


1

No, a trigger can only be placed on one object, so you do need the 10 triggers. The point of the trigger handler class is indeed to minimize the amount of logic you need to duplicate, but you can't do so using just a single trigger.


0

Yes, it's possible to show hyperlinks on trigger validation. Please refer to this developer forum post.


2

Maps need to use get and put, rather than accessed directly. Also, you should use a Map<String, Object> instead of Map<Object, Object>: Map<String, Object> data = new Map<String, Object>(); data.put('previousAccountId', trigger.oldMap.get(contact.Id).AccountId); data.put('currentAccountId', trigger.newMap.get(contact.Id).AccountId); ...


0

You need a static variable to store the job Id: public inherited sharing class Accounttriggerhandler { static Id asyncJobId; And then, in your after delete trigger, queue a queueable: public static void Accountdelete(List<Account> Accrec){ asyncJobId = System.enqueueJob(new QueueablePerformActionOnAccountDelete(Accrec)); } And then in your after ...


0

You have an compilation error at line : For (Loan__c loan: [SELECT Id, Loaned_Out__c FROM Book__c WHERE Id IN :bookIds]) Here you are querying Book__c but you are expecting Loan__c to be returned. It should be . For (Book__c book: [SELECT Id, Loaned_Out__c FROM Book__c WHERE Id IN :bookIds]) Also this line loan.Loaned_Out__c = loan.Loaned_Out__c - 1; is ...


0

Create a Visualforce extension class that includes a method that calls your Stuff.doStuff method. The method can then return a pagereference back to the calling page. Create a visualforce page that implements the <apex:page extensions="yourExtensionClass" standardController="Your_Object__c" action="yourExtensionMethodHere">...


0

Account.Class refers to the Type Schema.Account.sObjectType, not a specific account record. You can't get related record information directly in a trigger, you have to query for it first. Also, you shouldn't use Object for this case, you need to use the correct type for the trigger (e.g. Task). So, your code needs to start off with something like: public ...


1

The errors you mentioned all seem to stem from some fundamental misunderstanding of what your code is really trying to do. I think there are two main things that you've gotten wrong here You aren't accessing related data from a given Task properly You don't seem to understand how trigger context variables work There are more issues with your code than that,...


0

You do not use your for-loop currently, just assigning variables, assuming that the list is size 7. Try this approach ( also note, that you should be certain, that you have Approval_Comment_i__c for the res.size(). If you're not sure about it, then you should perform a check): Map<String, SObjectField> fieldsMap = RPR__c.getSObjectType().getDescribe()....


1

This is because your Apex class method needs to have a parameter that accepts a List of Loan__c records. Your apex class should be as below public class LoanTriggerHandler { public static void checkSubject(List<Loan__c> newLoanRecords) { Set<Id> bookIds = new Set<Id>(); Set<Id> readerIds = new Set<Id>(); // ...


1

You're passing in a parameter: LoanTriggerHandler.checkSubject(Trigger.New); But you didn't define the parameter: public static void checkSubject() { Change it to: public static void checkSubject(Loan__c[] loanRecords) { And then change every instance of Trigger.new in your class to use loanRecords instead: for (Loan__c loan : loanRecords) { This is ...


2

It makes sense to only query the inserted loan-related data, but you query all loans. Since this is before insert, you cannot query in the way you have. The inserted loans only get IDs allocated in after insert, which is too late for what you want to do. Change the trigger to: trigger LoanTrigger on Loan__c (before insert) { Set<Id> bookIds = new ...


4

You've written your query in parent-child subquery form, but Loan__c is in fact the child object. You need to traverse the relationship upwards to obtain data from the related Book__c and Reader__c objects: SELECT Active__c, Name, Book__r.Name, Book__r.Subject__c, Reader__r.Name, Reader__r.Specialization_Subject__c FROM Loan__c


0

If Attachment__c is null/blank, your code will throw a NullPointerException. You need to check that there's any value in the field before checking if it contains/does not contain a certain string/value. Not to mention, if it is null (which means it has no img) - you need to also add the error. In other words, you have 2 conditions to check where you want an ...


1

We can also invoke the vf page from the apex, that will get the complete vf page as word document as blob and you can insert content version with that blob This is how it will look like VF Page: <apex:page controller="ControllerName" contentType="application/msword#filename.doc" sidebar="false" standardStylesheets="false&...


Top 50 recent answers are included