• Mike Chandler
  • NEWBIE
  • 45 Points
  • Member since 2017


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 7
    Replies
I have the following code snippet in a Helper class that's being called by an After Insert trigger (modified to demonstrate my objective):
 
Set<Id> reuseIds = new Set<Id>();
reuseIds.add('a0g0R000001VnjMQAS');

List<ContentDocumentLink> allLinks = [SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN :reuseIds];

System.debug('allLinks size: ' + allLinks.size());

The debug output is showing me that I'm getting zero results. However, when I run the same query in the debug console, I see the single row returned that I'm expecting.

I have included without sharing on the trigger Helper class even though my understanding is that's not necessary in a trigger, but it doesn't change my results.

Can anyone offer any clues as to what I may be experiencing here?
I want to add a workflow rule on Cases to update a field when an Escalation Rule fires. However, I'm finding that "IsEscalated" is set to TRUE when the Case goes into escalation monitoring which is before the Escalation Rule Action actually fires. With that said, is there a good way to accomplish my goal?
I've got a classic Community Portal (Visualforce and tabs) hosted on a root communities domain name. I want to replace it with a Lightning Community. I can easily create a new Lightning Community on a subdirectory of my root domain (e.g. http://DOMAIN/newcommunity) but my desire is to replace the root hosted Portal with a new modern Lightning Community.

Is that a possibility?
I'm still getting my feet wet with SFDX and have stumbled on to a problem. I'm working on a new project and am deploying my code and metadata changes to a scratch org. The scratch org is vanilla and doesn't contain any of the metadata in my Sandbox org. I'm writing an Apex class that has a dependency on a class that is in my Sandbox but not in my scratch org.  I'd like to introduce this class into my project so that I can use it, but I have no intention of changing the class in any way. It's just a dependency, so I need it for reference and so my source push requests will compile.

How can I introduce existing code without making it a part of my SFDX project? I'm pretty confused about how to move forward.
I know that it's possible to exclude a block of code from being executed with creative use of the following method:
Test.isRunningTest()
However, I was hoping someone knew of a strategy for excluding a block of code from certain unit tests while allowing it to run in others.  I have portions of a Trigger that I want to run for certain unit tests, but I'd prefer not to run the same portion of the trigger for other tests. Is there a common strategy for doing that?  Any help would be greatly appreciated.  Many thanks!
I have a custom object with a Look-up Relationship to its parent object in Salesforce Classic.  When a user adds a new instance of the child object from the Related List on the parent detail page, I'd like to redirect BACK to the parent page when the child object is saved.  Is there a way for me to override that behavior to accomplish this?
Hi there.  I'm working in Salesforce Classic and we have Notes activated on an object and as a Related List on an object.  When adding a Note and clicking Save to save it, the user just sees the Note detail screen.  Instead, I would like to redirect the user back to the object on which the note was saved.

Is there a way to override what appears to be default behavior for Notes in Salesforce Classic?
I have a custom object that includes a picklist field of Category with three possible values: Hot, Warm, Cold.  I want to display a list of custom objects using an apex:dataTable in my custom Visualforce page, but I would like to group my output by Category.  I'm wondering if there's a function in the dataTable that allows me to render groupings of rows separated by a row with a single column that renders just the Category name of the matching items below it.

For example:
  • Hot
  • Item 1 - columns of data
  • Item 2 - columns of data
  • Warm
  • Item 3 - columns of data
  • Item 4 - columns of data
  • Item 5 - columns of data
  • Cold
  • Item 6 - columns of data
I'm writing unit tests that should be relatively simple, but I'm stumbling over some sort of restriction that I'm unfamiliar with due to my inexperience with Apex.  I'm attempting to retrieve usable Contacts from the org to use for testing purposes because I need them to have fully initialized IDs.  I'm unable to use test data because inserting them in tests is problematic due to Contact related triggers.

I'm using the following code snippet in my test method and getting exceptions:
Contact testContact = [SELECT Id, FirstName, LastName from Contact LIMIT 1];
Error: System.QueryException: List has no rows for assignment to SObject

I'm annotating my test method as follows, with no luck:
@isTest(SeeAllData=true)
I'm wondering what I'm missing here.  Any ideas how to get a handle on real Contact records for testing purposes?
I'm working on an Apex custom controller for a Visualforce page.  After I perform an insert transaction for a new instance of a custom object, I want to redirect to a Contact detail page.

I have a field on the Apex class called myContact of type Contact and my constructor always makes sure it is valid and instantiated with a valid Contact based on URL parameters passed to the Visualforce page, so I always have a Contact.  After I do my new custom object insert, I invoke a method called returnToContact() which is shown below.  However, it doesn't redirect, leading me to believe I'm doing something wrong.
public PageReference returnToContact() {
        PageReference contactPage = new PageReference('/' + myContact.Id);
        contactPage.setRedirect(true);
        return contactPage;
}
Any ideas on what I need to do to ensure I can properly redirect?
I have the following code snippet in a Helper class that's being called by an After Insert trigger (modified to demonstrate my objective):
 
Set<Id> reuseIds = new Set<Id>();
reuseIds.add('a0g0R000001VnjMQAS');

List<ContentDocumentLink> allLinks = [SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN :reuseIds];

System.debug('allLinks size: ' + allLinks.size());

The debug output is showing me that I'm getting zero results. However, when I run the same query in the debug console, I see the single row returned that I'm expecting.

I have included without sharing on the trigger Helper class even though my understanding is that's not necessary in a trigger, but it doesn't change my results.

Can anyone offer any clues as to what I may be experiencing here?
I know that it's possible to exclude a block of code from being executed with creative use of the following method:
Test.isRunningTest()
However, I was hoping someone knew of a strategy for excluding a block of code from certain unit tests while allowing it to run in others.  I have portions of a Trigger that I want to run for certain unit tests, but I'd prefer not to run the same portion of the trigger for other tests. Is there a common strategy for doing that?  Any help would be greatly appreciated.  Many thanks!
I'm working on an Apex custom controller for a Visualforce page.  After I perform an insert transaction for a new instance of a custom object, I want to redirect to a Contact detail page.

I have a field on the Apex class called myContact of type Contact and my constructor always makes sure it is valid and instantiated with a valid Contact based on URL parameters passed to the Visualforce page, so I always have a Contact.  After I do my new custom object insert, I invoke a method called returnToContact() which is shown below.  However, it doesn't redirect, leading me to believe I'm doing something wrong.
public PageReference returnToContact() {
        PageReference contactPage = new PageReference('/' + myContact.Id);
        contactPage.setRedirect(true);
        return contactPage;
}
Any ideas on what I need to do to ensure I can properly redirect?
I had so much trouble with this one section that I feel like I have to post this to help out those who are struggling as much as me. Three hours for a simple controller... The problem is the way trailhead tests the challenge is hard for them and they have very strict criteria that is not implicit in the challenge directions.

camingList.cmp
<aura:component >
    
	<aura:attribute name="newItem" type="Camping_Item__c"  default="{'sobjectType': 'Camping_Item__c', 'Quantity__c': 0, 'Price__c': 0.00}" required="true"/>
	<aura:attribute name="items" type="Camping_Item__c[]"/>
	<lightning:layout class="slds-page-header slds-page-header--object-home">
        <lightning:layoutItem >
            <lightning:icon iconName="standard:scan_card" alternativeText="My Campign Items"/>
        </lightning:layoutItem>
        <lightning:layoutItem padding="horizontal-small">
            <div class="page-section page-header">
                <h1 class="slds-text-heading--label">Camping Items</h1>
                <h2 class="slds-text-heading--medium">My Camping Items</h2>
            </div>
        </lightning:layoutItem>
    </lightning:layout>
    <!-- / PAGE HEADER -->

    <!-- NEW EXPENSE FORM -->
    <lightning:layout >
        <lightning:layoutItem padding="around-small" size="6">

        <!-- CREATE NEW EXPENSE -->
    <div aria-labelledby="newitemform">

        <!-- BOXED AREA -->
        <fieldset class="slds-box slds-theme--default slds-container--small">

        <legend id="newitemform" class="slds-text-heading--small 
          slds-p-vertical--medium">
          Add Camping Item
        </legend>
  
        <!-- CREATE NEW EXPENSE FORM -->
        <form class="slds-form--stacked">          
            <lightning:input aura:id="itemform" label="Item Name"
                             name="itemname"
                             value="{!v.newitem.Name}"
                             required="true"/> 
            <lightning:input type="itemform" aura:id="itemform" label="Amount"
                             name="itemprice"
                             min="0.1"
                             formatter="currency"
                             step="0.01"
                             value="{!v.newitem.Price__c}"
                             messageWhenRangeUnderflow="Enter an amount that's at least $0.10."/>
            <lightning:input aura:id="itemform" label="Quantity"
                             name="itemquantity"
                             value="{!v.newitem.Quantity__c}"
							 min="1"
							 type="number"
							 required="true"
							 messageWhenRangeUnderflow="Enter minimum 1 Quantity"/>
                             />
            <lightning:input type="checkbox" aura:id="itemform" label="Packed?"  
                             name="packed"
							 class="slds-checkbox"
                             checked="{!v.newitem.Packed__c}"/>
            <lightning:button label="Create Camping Item" 
                              class="slds-m-top--medium"
                              variant="brand"
                              onclick="{!c.clickCreateItem}"/>
        </form>
        <!-- / CREATE NEW EXPENSE FORM -->
  
      </fieldset>
      <!-- / BOXED AREA -->

    </div>
    <!-- / CREATE NEW EXPENSE -->

        </lightning:layoutItem>
    </lightning:layout>
    <!-- / NEW EXPENSE FORM -->
	
	<div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small">Camping</h3>
        </header>
        
        <section class="slds-card__body">
            <div id="list" class="row">
                <aura:iteration items="{!v.items}" var="cmp">
                    <c:campingListItem item="{!cmp}"/>
                </aura:iteration>
            </div>
        </section>
	</div>
</aura:component>

campingList.Controller
({
		handleAddItem: function(component, event, helper) {
    var addItm = event.getParam("item");
    helper.createItem(component, addItm);

},

    createItem: function(component, newItem) {
    var action = component.get("c.clickCreateItem");
    action.setParams({
        "item": newItem
    });
    action.setCallback(this, function(response){
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            var items = component.get("v.items");
            items.push(response.getReturnValue());
            component.set("v.items", items);
        }
    });
    $A.enqueueAction(action);
},
    clickCreateItem: function(component, event, helper) {
		
        var validItem = component.find('itemform').reduce(function (validSoFar, inputCmp) {
            // Displays error messages for invalid fields
            inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        
        
        // ... hint: more error checking here ...

        // If we pass error checking, do some real work
        if(validItem){
            // Create the new expense
            var newItem = component.get("v.newItem");
            console.log("Create Camping Item: " + JSON.stringify(newCamping));
            handleAddItem(component, newItem);
        }
		component.set("v.newItem",{'sobjectType':'Camping_Item__c',
                'Name': '',
                'Quantity__c': 0,
                'Price__c': 0,
                'Packed__c': false});
    }
})
camping.cmp
<aura:component implements="flexipage:availableForRecordHome">
	<br/><br/><br/>
    <c:campingHeader />
    <c:campingList />
</aura:component>

campingHeader.cmp
<aura:component >
	<lightning:layout class="slds-page-header">
		<lightning:layoutItem >
			<lightning:icon iconName="action:goal"/>
		</lightning:layoutItem>

		<div class="slds-page-header">
			<h1 class="slds-text-heading--label"> Camping List </h1>
		</div>
	</lightning:layout>
</aura:component>

campingListItem.cmp
 
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c"/>
    
    <p>Name:
        <ui:outputText value="{!v.item.Name}"/>
    </p>
    <p>Price:
        <ui:outputCurrency value="{!v.item.Price__c}"/>
    </p>
    <p>Quantity:
        <ui:outputNumber value="{!v.item.Quantity__c}"/>
    </p>
    <p>Packed:
        <ui:outputCheckbox value="{!v.item.Packed__c}"/>
    </p>
</aura:component>

Any other controllers or helper classes are not needed. That is the trick here. Using helper classes when not specified fails the challenge. I hope you will read through and understand this code as I have to realize why it is this way and not simply copypasta.

Enjoy!