Hot answers tagged

14

So with some help I figured out that it works, it is just a bit dirty to get the values, this is the path through the object structure: child.fields.parent__r.value.fields.Name.value So the targetFields attribute on recordData just came to my mind, and I replaced targetRecord. Now it works as expected: <force:recordData recordId="{!v.recordId}" ...


13

You can use a HAVING clause: AggregateResult[] results = [SELECT COUNT(Id) sum, Tool__c Id FROM Gear__c WHERE Tool__c = :tools GROUP BY Tool__c HAVING COUNT(Id) > 1]; This will give you a list of AggregateResult objects where the sum and Tool__c Id are given. You can even use the Map trick to get the count per record easily: Map<Id, AggregateResult&...


10

You can use a Left Inner Join to get the data you want with pure SOQL. For example: SELECT Id FROM Parent__c WHERE Id IN (SELECT Parent__c FROM Child__c) The joined rows do not count against your query row limit.


10

Sounds a bug to me, the instance is still of ChildDependency I confirmed it using debug logs. public class ChildClass extends ParentClass { public ChildClass() { super(new ChildDependency()); } public void doSomething() { System.debug( this.someDependency); System.debug( super.someDependency); this....


9

You're pretty close to a solution with your parent-child subquery. The big thing to realize is that, similar to how adding parent__r.someField__c gives you a real SObject instance nested in your query results, a parent-child subquery gives you a List<SObject> nested in your query results. About the only thing I'd add is to limit the subquery rows to ...


6

The child object sObject list, here Child__r, is never null if you perform a parent-child query on that relationship. If no child objects are present, the list will have zero size. You can check if (opportunity.Child__r.size() > 0) { to determine whether to proceed with processing child objects.


6

Lightning page can provide recordId only to the top most custom LWC/AURA component. You need to pass down the record id down the hierarchy. Make a Component Aware of Its Record Context: Define @api recordId in parent component in JS file. Now, pass the record id to child: <c-childcomponent record-id={recordId} selectedsobject="Contact" where-field="...


4

You can't just update related records in this way. You need to actually call update on a record. You can't access parent fields in a trigger context, but in this case you do not even need a query because you just need the ParentId. Map<Id, Case> cases = new Map<Id, Case>(); for (CaseComment record : trigger.new) if (record.ParentId != null) ...


4

On question 1), an alternative to the ultimate parent approach is a query per layer: Id accountId = '...'; Account[] allChildren = new Account[] {}; Set<Id> parentIds = new Set<Id>{accountId}; Account[] children; do { children = [select Id, Name from Account where ParentId in :parentIds]; allChildren.addAll(children); parentIds.clear(...


4

If you want to persist your changes in the database, you have to perform a DML Operation (in this case update): for (MyObject__c record : scope) { // manipulate data } update scope; I would also recommend a few changes: Change all global access modifiers to public. In general if you want to map by a record, use its Id as the key, not the object itself....


3

Your solution will really depend on how many levels you need to be able to support. For instance, if you can rely on only going 10 levels deep then you can just use a formula field as per Adrian's answer to Need a custom field Grand parent Account which has highest level of account hierarchy. Another alternative is to use a text field to maintain the ...


3

If you do not have Business Unit Filters enabled in your account (largely a deprecated feature), you will see subscribers from all business units in All Subscribers. You might want to revoke permissions on All Subscribers from users, if this is an issue. If you are using standard unsubscribe functionality, the subscriber would be unsubscribed just from the ...


3

You cannot compare a field to another field in SOQL. The standard workaround is to use a formula. It's hard to tell what you're trying to achieve based on your syntax, but if you wanted to filter on records where one field equals another, you would do make a formula (say DoesField1EqualField2__c) that looks like: Field1__c = Field2__c And then in your ...


3

Yes, you can use a join to find only records which have child records meeting certain criteria. SELECT ... FROM MyObject__c WHERE Id IN ( SELECT Lookup__c FROM Child__c WHERE ... ) So in your case, if your child object is named VotingRelatedCompany__c, it would look like: WHERE Id IN ( SELECT Company__c FROM VotingRelatedCompany__c WHERE ...


3

The key to any such functionality is an Ultimate_Parent__c function. I think it maxes out at ten levels deep, but here is a smaller example of how it should work: BLANKVALUE(Parent.Parent.ParentId, BLANKVALUE(Parent.ParentId, BLANKVALUE(ParentId, Id ))) Then, given any account, you can find its entire hierarchy using: SELECT Id FROM Account ...


3

It doesn't help you with historical data, but I would set up a flow using Process Builder to update a Most Recent Child Status field (or a lookup to that child record). Make sure to have it fire only on record creation. Once it's populated, just filter on this field. For example, if you use a relationship, include this clause: WHERE Most_Recent_Child__r....


3

As Adrian noted in the comments on your question, this isn't possible to achieve via SOQL alone. While you can't use ORDER BY in a semi-join/Left Inner Join (i.e. a subquery appearing in the WHERE), you can use ORDER BY in a Left Outer Join (a.k.a. a parent-child subquery, one that appears in the SELECT clause). I can't find documentation that corroborates ...


3

Can you try out like this where Subquery has been replaced by INNER JOIN: SELECT Parent__c, Parent__r.Name, COUNT(Id), MAX (CreatedDate) FROM Child__c WHERE Status__c = 'Failure' AND Parent__r.RecordType.Name = 'rt' GROUP BY Parent__c,Parent__r.Name ORDER BY Parent__c, Parent__r.Name LIMIT 100 I have tested this at my org. It will show latest Child ...


3

You can't do it for most fields. As it's a polymorphic relationship field, you can utilize Type to get the object of a polymorphic relationship, but you're limited in what fields are accessible through that key. SELECT Id,WhatId FROM Event WHERE What.Type IN ('Opportunity') This is highlighted in the Name object documentation. Non-queryable object that ...


2

I know you went through the coding path but here is an alternative solution... If you Project__c and Project_Contact__c are linked through a master-detail relationship, you could create 2 rollup summary : Count total of project contact Count Total of survey sent (filter by survey_sent__c) Then create a custom validation rule if Total_Project_Contact__c !=...


2

You have some ways to solve it. If the fields can be editable only in one object, you can use a Formula field. If you want that these fields will be editable in both objects I suggest you to use a workflow rule, a flow or a Process Builder. Also, if you want to code, you can use a trigger for this.


2

There may have multiple contact related to selected Account. You need to iterate contact list to display all the related contacts.There is an error in your query, it should be AccountId insted of id. <apex:page controller="AccountControllertest"> <apex:form id="formid"> <apex:pageBlock> <apex:pageBlockSection title="Select ...


2

You cannot create master-detail relationship when referencing the same object. You could create lookup to the same Territory Custom object. Just think about how Salesforce default Account Hierarchy works. It has default parent Account lookup field to itself. Refer Object Relationships Overview Lookup Links two objects together. Lookup relationships are ...


2

e.g. for(Account acc:[Select Id, (Select Id From Contacts limit 1) From Account Where Id=:idVar]) { if(acc.Contacts != null && acc.Contacts.size() >0) { System.debug('Has child records.'); } else { System.debug('No child records.'); } }


2

Can there be a situation were I delete a ContentDocument that a different Case will be related to as well? Yes. ContentDocument records are connected to the various locations where they have been shared (libraries, record pages, users) by ContentDocumentLink records. ContentDocumentLink is essentially a junction object between some other record and ...


2

Your question implicates several different portions of the Salesforce security architecture. with sharing/without sharing/inherited sharing context, which applies to Apex classes, determines whether or not record-level visibility, such as Organization-Wide Defaults and Sharing Rules, are applied. Because your comment indicates you're running a query via the ...


2

Downwards traversal is when you’re pulling records from a related list. For example, if we’re doing a SOQL query on accounts, downwards traversal could pull data from the account’s contacts. Let’s take a look at a downwards traversal SOQL query: SELECT Id, Name, Industry, AnnualRevenue,( SELECT Name, Email, BirthDate FROM Contacts ) FROM Account We ...


2

This is what I would do in your case. Not knowing if your system of record (SOR) for consent data is within SFMC itself (e.g. in a Consent data extension) or outside, this solution will differ slightly. Firstly, a job needs to be set up in Automation Studio (in parent BU) to query your Complaint and Bounce data views. Once a day you (or more frequent, ...


2

You cannot make a field to field comparison in SOQL i.e. as mentioned in the question, you cannot compare X.Parent.AccountId != X.AccountId. There is other workaround by which you can do this i.e. by creating a new formula field which evaluates to true when X.Parent.AccountId = X.AccountId and false when it is not same. The formula for your new field ...


2

Do I have to import anything into the 'Parent' Component? No. Or Export anything from the 'Child Just the default export: export default class LwcEditForm extends LightningElement { ... Am I perhaps referencing the component incorrectly? Not as far as I can tell. Your main problem is that you're referencing a SLDS grid with a total size of 6/3 (...


Only top voted, non community-wiki answers of a minimum length are eligible