New answers tagged

0

As your object has a bunch of records, you should use a field that there is index. You could ask to Salesforce to create an index or use a External ID field in your query. You may find that the query in question needs to be more selective in the WHERE clause. According to the Salesforce standards & best practices - the where clause needs to ...


1

Yes, this is standard logic. When a DML operation starts, a "check point" is implicitly created. During the partial DML operation mode, if any records get an error, the transaction is rolled back to this check point, including any emails sent, jobs queued, future methods, etc. The records that received errors are set aside, and the remaining records are ...


0

If you are using VS Code you can remove the classes and triggers using Terminal command. Find the class/trigger that you want to delete and change the metadata for status to be Deleted. You will need to specify the name of the class/trigger in the sfdx force deploy command, and also you can delete multiple class/triggers per command (you will separate them ...


0

After reading your question a couple times I think I've spotted what you're running into but feel free to comment if I've interpreted your question incorrectly. The immediate problem is this query which doesn't include the email fields you're trying to use later in the for loop. List <Case> caseList = [SELECT Id, AccountId, Account.Name, Account....


0

Close this if condition. if (obj.Object_1__c == obj1s[i].id) { obj1s[i].field_1__c = field_2__c; }


1

There is a comma after the object name in the SOQL. remove that from Object_1__c, List <Object_1__c> obj1s = new List <Object_1__c> ([select id, field_1__c from Object_1__c where id in: Obj1IDs]); //this is line 10 - where the error is


0

Some inputs: Only the immediate fields of the record - Contact in this case - are automatically available so c.RecordType.DeveloperName is probably always null. You will need to get the record type Id and compare that. Keep all queries out of the trigger loop; put those queries upfront before for (Contact c : trigger.new) { in local variables to avoid ...


1

The default behavior would be the child gets a Before Update trigger, then a After Update trigger. The parent record would not ordinarily fire. This is the vanilla behavior. I'm presuming you've read the logs wrong, because the absolute first trigger to fire would need to be the child's Before Update trigger. From there, all bets are off. A before update ...


1

You may be having an unrelated problem problem here. As I see your code, you are trying to update the Contact using Trigger.new in an after trigger. You won't be able to do so. You should review your code and make the necessary changes. E.g., a working version of this could be using this approach in before trigger. if((trigger.isInsert || Trigger.isUpdate) ...


1

You have to make the chatter group unique, for example myGroup.Name = proj.Name + ' - ' + proj.Id; In such a case you'll be able to create chatter groups for the projects with the same name. For handling update operation you there is 2 option: 1) on update operation just collect all the unique combinations for a chatter group name (project name + Id) ...


0

The code that you showed doesn't have any callouts, so I assume that either your Account or Customer Todo trigger have a web service callout in it. In order to write a test class for a class that has a callout, you will need to implement a Mock class. You can read more about it here.


-1

You need to create a trigger on a case object. Based on Salesforce best practices it is better to create handler class, write logic in this class and use bulkification. I would suggest you use TriggerFramework , below you can find example without a trigger framework. trigger CaseTrigger on Case (after update) { if (Trigger.isAfter) { if (Trigger....


1

Your immediate issue is this bit: updates.add(new Case( Last_Chatter_Feed_Timestamp__c = System.now() )); where you are adding a new Case record, with only a single field populated, to the updates list. When you then get to: update updates; Salesforce says that it can't update records for which it doesn't have an Id. You also have a ...


2

The issue in your trigger is that something inside of the updates list isn't being given an Id. Looking at your code, this section appears to be responsible: for(FeedComment fc: trigger.new){ if (feedMap != null && feedMap.containsKey(fc.feedItemId) && fc.ParentId.getSObjectType() == Case.SObjectType) { updates.add(new Case( ...


3

I believe that something like this should work trigger ActiveOrder on Order (after insert, after update) { public class JSONOrderInfo { private String ordAccountId; private String ordBillingStreet; ... public JSONOrderInfo(Order newOrder) { this.ordAccountId = newOrder.AccountId; this....


0

Even though documentation is not very clear about how the external objects work it seems that in a sync transaction you cannot access external objects. Try to run a method with @future notation to update your case based on the data of the external object.


1

Nobody who would be in a position to know would be able to tell you anything concrete (because of signed NDA agreements and/or Safe Harbor policy). I think you might be referring to this Idea. You should vote for the Idea to make sure you get notified when, or if, this feature is implemented.


1

It does indeed make sense if you can easily split the logic of the applications. But the question is why would you do it? That will require extra maintenance as the new requirements are coming in and you may end up with duplicate code which is a bad practice itself. You will also probably end up doing the same check(which application is running now and which ...


0

As per above code, the object structure is Opportunity (Parent) < = pse__Proj__c (Child) < = pse__Timecard__c(Child of Child) and the requirement is the field(Total_Charge__c) of opportunity is the no of child count(pse__Proj__c). Assumption : If one Opportunity is having one pse__Proj__c record and pse__Proj__c can have multiple ...


0

Your tests are passing with false positives because your setup() method is not annotated correctly with the @testSetup annotation. That annotation is required to make the test setup method run prior to each unit test; otherwise, it's just an ordinary unit test itself, whose data-creation steps are not applied to the context of each other test within the ...


1

After some annoying debugging using a special logging tool we built that writes logs as records, I found the culprit was in List.contains(Object). This method does not know how to deal with an Id parameter when it's template type is also Id . My first step was to replace: if (RECORD_TYPE_IDS.contains(customRecord.RecordTypeId)) with... for (Id i : ...


0

If you are talking about sharing, you can read this part of the developer guide. If they have already the same permission sets/profile, this is the way.


0

You can try to check the emails after your test is done. Add something like this on your asserts. We just want to use a SOQL on the EmailMessage and get them by the email subject. // When Test.startTest(); // Your test Test.stopTest(); // Then List<EmailMessage> newMails = [SELECT Id, Subject FROM EmailMessage]; System.assert(!newMails.isEmpty(), ...


0

In the end, the only solution was to get the products with an APEX controller. this.allLineItems=new List<OpportunityLineItem>([select id,UnitPrice,Product2.Name,Quantity,Product2.Hasavshevet_product_ID__c from OpportunityLineItem where OpportunityId = :Opp.id ORDER BY SortOrder]); this.userinput = this.allLineItems[0].Product2.Name; m_names ...


0

You'll want to query the existing leads by email and company in order to identify potential duplicates. Here's one possible solution: public static Map<Boolean, Lead[]> leadCheck(Lead[] newLeads) { // true => non-duplicate lead, false => duplicate lead Map<Boolean, Lead[]> results = new Map<Boolean, Lead[]> { false => new ...


1

I think you should try to set up a singletone pattern for your helper class. You need to make sure that every instance of the helper class is independent. This will help you to reduce governor limits. You are passing all Rents records that are changing. I think you should use here a logic to pass only those Rents that have changes on the fields that have ...


2

Recursion guards are very tricky. Using a simple static Boolean is a bad practice: there are lots of reasons for your trigger to be fired more than once in a transaction, and using a runOnce-style Boolean will mean your trigger just silently does nothing in those cases. This often produces difficult to debug behavior. Instead, use static Booleans that are ...


0

Since there is a master-detail relationship between the parent and child object, here is an alternative solution without code: -Create a roll-up summary field on the parent object, to count the number of child records (let's call the field Count_Quote_Line__c) -Then on the parent object create a validation rule as follows : Count_Quote_Line__c < ...


0

you can create a helper like this public class ContactTriggerHelper {public static Boolean runOnce = true; public static void onAfterUpdate(List<Contact> newacc){ for(Integer i=0;i<newacc.size();i++) { insert (new Account(Name='Test'+i)); runOnce = true; System.debug('Is ...


1

Anytime you deploy or validate a change set, you can specify what tests you'd like to run. There's a quick read about it here: Since you're not deploying any code changes, the Default or Run local tests options should validate the changeset properly without having to run all the tests in your org.


1

Correct, you cannot catch this error in a trigger. This error occurs before any triggers are executed. This is true for all standard validations, such as DUPLICATE_VALUE, REQUIRED_FIELD_MISSING, etc.


2

I recommend you maintain a map of OpportunityId to count of child records. Start with the aggregates, then increment by your context records. Please note from Triggers: Before triggers are used to update or validate record values before they’re saved to the database. Given that you are validating record values, a move to the after context would be ...


1

In a before trigger, the changes to the database have not been committed yet, so you can't query for the data. Accordingly, you wouldn't see the new rows being created yet. Change the trigger to an after insert trigger to see the correct values. Note that your trigger isn't bulkified. Nor, is it even necessary. Just create a normal Roll-Up Summary Field for ...


2

There are a couple things in your code which need fixing. Never consume any governors (such as queries, database operations, etc) in a loop. Please read up on Triggers and understand what operations should be used when. You can define triggers for top-level standard objects that support triggers, such as a Contact or an Account, some standard child ...


0

The culprit here is your recursion guard, which is using an overly-simplistic model and inhibiting the second run of your trigger. Your trigger runs once at insert cont; and sets contactRecursion to true. It retains that value for the remainder of the transaction - the entirety of the unit test run. Your trigger is invoked a second time at ...


0

The SortOrder field is available, just not updateable. To get the sort order, include it in your script: var product_row = {sortOrder: {!BLANKVALUE(lineItem.SortOrder,0)}, name:"{!lineitem.product2.name}", quantity:{!lineitem.quantity}, ID:{!lineitem.product2.Hasavshevet_product_ID__c},price:{!lineitem.UnitPrice}}; Which you can then sort when you're done:...


1

While I am aware that this issue is solved and the code mentioned above works, there is a simpler way of accomplishing this requirement and hence thought of sharing it here. The above scenario can be easily accomplished declaratively through a Formula Field given the fact that you do not exceed the formula field character limit of 3900 characters. Create a ...


3

Future methods only accept Apex primitive values and collections of primitives as parameters. They do not support sObject parameters or complex parameters including sObjects. The easiest way to correct this is to break your code into a synchronous piece and pass only the serialized JSON to your @future method: public static void AfterUpdate(Map<Id, ...


4

Yes, it definitely is. When you use the Bulk API and do not check the Enable Serial Mode for Bulk API, Salesforce will process batches simultaneously which means that multiple batches will execute in parallel. Because of this, there could easily be two batches trying to get inserted with the same autonumber values because at the time they queried the ...


0

I think the problem is how you are validating the Manager1__c field. If it is a relationship the condition if(t.Manager1__c=='') wont work. try using if(t.Manager1__c==null) and also you can bring the transactions that Manager1__c field is null with the query, try this one. List<Vendor__c> vlst = [select id,name,Manager__c,(select id,Name,...


0

[select Status from Case where Id IN (select ParentId from EmailMessage)and Status='Closed']; The above line brings ALL Case records where their status is 'Closed' and the Id that matches with the ParentId of ALL EmailMessage records. That's why you get "more cases whose status is closed with the parent id". Now, if you want to get the case records where ...


0

You can insert the parents beforehand, then link them. trigger createParents on Child__c (before insert) { Parent__c[] parents = new Parent__c[0]; for(Child__c record: Trigger.new) { parents.add(new Parent__c(Name=record.Name)); } Insert parents; for(Child__c record: Trigger.new) { record.Parent__c = parents.remove(0).Id; } } If you ...


1

The reason for your issue is that an afterInsert of ContentDocument will occur before any ContentDocumentLink records are even inserted! Hence none will exist. That is, the ContentDocument has to exist before a ContentDocumentLink can be saved as it is a junction record between ContentDocument and the object pointed at by LinkedEntityId You'll need to ...


0

a.Parent_c = Parent.id; Parent.id is null at this point because Parent has not been inserted yet. Your trigger will need to perform insert Parents first. Salesforce will populate the Id fields on those objects when they're inserted. Then, you can iterate over the lists again, populate the parent Ids on the child lookups, and do update childslist.


0

You missed inner SOQL to get related attachments i.e (select id from attachments), and you are checking attachments.size() inside for loops without child results(attachments). Below are the changes I did in your code Changes in your code list <case >updateCase = new list < case >(); list < case >getCases = [select id, AccountId, AssetId, ...


-2

I found that instead of attempting to access the variable from the SOQL search, I would just place them in a String that is accessible by the If/Then Statement. I created List<String> ListOfMessages = new List<String>(); and pushed each line in to List. List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, ...


1

My option would be when there is no email template to: send the customer (and BCC the sysad) a default email (without a template) with as much useful contextual data so the community user feels they were "heard" and that a followup is forthcoming Use normal apex outbound emails with a setBody() to contain the text. Another amelioration would be a ...


1

There are a couple issues with the code. I understand that you're new to Apex, so I'll try my best to explain things as simply as I can. The first issue is that you said that you want to update the status on Cases if the Work Orders on those cases are all rejected. This necessitates that the we aren't just checking for inserts, and that the Case must exist ...


1

A third and, in my opinion, the best approach would be to log the failure to a custom object and allow the trigger to succeed. If you can't find the email template, write to an object called something like Unsent_Email__c, with all the required details. Then, an admin can have a scheduled report or dashboard or email alert on that object. The admin can go ...


2

Your attempt to use page parameters will fail, because ApexPages.currentPage().getParameters() doesn't contain the key 'myparameter'. You need to put some value in this map key, and also make some assertions. Include something like below in your test before constructing your extension: String expectedFinishUrl = 'abcde'; String parameter = expectedFinishURL ...


Top 50 recent answers are included