• Base Line
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
{ "Global Quote": { "01. symbol": "AAPL", "02. open": "191.5450", "03. high": "193.5863", "04. low": "190.3045", "05. price": "192.7400", "06. volume": "18761474", "07. latest trading day": "2019-06-14", "08. previous close": "194.1500", "09. change": "-1.4100", "10. change percent": "-0.7262%" } }

Please help me out? Thanks.
Hi. I am trying to implement an interface that will perform the following filter on input records.

- Do not include any record that has the field “Deleted__c” as true. (I have already created this custom field in the Account object)
- Do not include any record that is newer than 24 hours.
- Do not include any record that has an address outside of Japan.

Unfortunately, when I try the unit tests I created,  there are some System.AssertException errors. Having searched all over the internet for possible solutions, I am at a loss at what I am doing wrong. Please have a look at my code and guide me on what I should change. Any help would be greatly appreciated. Many thanks in advance.

INTERFACE
public interface IFilter {
List<Account> filter(List<Account> records);
}

IMPLEMENTATION
public class AccountFilterJapanOnly implements IFilter{

    public List<Account> filter(List<Account> records)
    {
        DateTime twentyFourHoursAgo = DateTime.now().addHours(-24);
        List<String> jpCountry = new List<String>{'Japan', 'JP'};
        
        List<Account> returnedAccountsList = new List<Account>();
        
        for( Account matchingAccount : [SELECT Name, AccountNumber, BillingAddress, Deleted__c, CreatedDate
                                        FROM Account
                                        WHERE Deleted__c != TRUE AND 
                                             CreatedDate < :twentyFourHoursAgo AND
                                            BillingCountry IN :jpCountry])
        {
            System.debug(matchingAccount);
            returnedAccountsList.add(matchingAccount);
        }
        
        return returnedAccountsList;
    }    
}

UNIT TESTS
@isTest
public class AccountFilterJapanOnlyTest {

    //NOT WORKING AS EXPECTED
    @isTest static void testDeletedField()
    {
        Account testAccDelTrue = new Account(Name='DeletedFieldTrue', Deleted__c=TRUE);
        Account testAccDelFalse = new Account(Name='DeletedFieldFalse', Deleted__c=FALSE);
        Account[] accts = new Account[]{testAccDelTrue, testAccDelFalse};
        //Insert accts;
        
        Test.startTest();
        AccountFilterJapanOnly jpRecords = new AccountFilterJapanOnly();
        List<Account> lst = jpRecords.filter(accts);
        Test.stopTest();
        
        System.assertEquals(1, lst.size());
        System.assertEquals(testAccDelFalse, lst[0]);        
    }
    
    //GIVING CORRECT RESULTS BUT STILL UNSURE IF THIS IS ACCURATE
    @isTest static void testCreatedDate()
    {        
        Account testCreatedDate = new Account(Name='Created Within 24 hours');
        Account[] accts = new Account[]{testCreatedDate};
        Insert accts;
        
        Test.startTest();
        AccountFilterJapanOnly jpRecords = new AccountFilterJapanOnly();
        List<Account> lst = jpRecords.filter(accts);
        Test.stopTest();
        
        System.assertEquals(0, lst.size());        
    }
    
    //NOT WORKING AS EXPECTED
    @isTest static void testLocation()
    {       
        Account testOutsideJapan = new Account(Name='Address Outside Japan', BillingCountry='USA');
        Account testWithinJapan1 = new Account(Name='Address1 Within Japan', BillingCountry='Japan');
        Account testWithinJapan2 = new Account(Name='Address2 Within Japan', BillingCountry='JP');
        Account[] accts = new Account[]{testOutsideJapan,testWithinJapan1,testWithinJapan2};
        Insert accts;
        
        Test.startTest();
        AccountFilterJapanOnly jpRecords = new AccountFilterJapanOnly();
        List<Account> lst = jpRecords.filter(accts);
        Test.stopTest();
        
        System.assertEquals(2, lst.size());
        System.assertEquals(true, lst.contains(testWithinJapan1));
        System.assertEquals(true, lst.contains(testWithinJapan2));
    }
}



 
Hi. I created a component which when dropped onto the opportunity screen, it is supposed to show a summary of the total value of all the added products. I checked the logs and the relevant data is sent back from the server but for some reason it is not showing on my table. If you can please take a look at my code and advise me on what is wrong, I'd highly appreciate it.Here it is:

COMPONENT

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="OppProductsTotalValueController">
    <aura:attribute name="oppProducts" type="OpportunityLineItem[]"/>
    <aura:attribute name="displayText" type="String" default="" description="for displaying a message when the opportunity has no products added"/>
    <aura:attribute name="tableColumns" type="List"/>
    <aura:attribute name="headerTitle" type="Aura.Component[]">
        <b>Total Value of Added Products</b>
    </aura:attribute>
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    
    <lightning:card>
        <aura:set attribute="title">{!v.headerTitle}</aura:set>
        <p class="slds-card__body_inner">
            <aura:text value="{! v.displayText }"/>
        </p>
        <lightning:datatable data="{!v.oppProducts}" columns="{!v.tableColumns}" keyField="id" hideCheckboxColumn="true"/>
    </lightning:card>    
    
</aura:component>

CONTROLLER

({
    doInit: function(component, event, helper) {  
         
        //Get opportunity products
        var action = component.get("c.getOppProducts");
        action.setParams({"oppId": component.get("v.recordId")});
        
        // Pass the data to my attribute and create table
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){                                
                if(response.getReturnValue().length == 0)
                {
                    component.set("v.displayText","This opportunity has no products added to it.");                        
                }
                else
                {   
                    helper.createTable(component); 
                    component.set("v.oppProducts", response.getReturnValue());
                        //For checking the data passed back from the server
                        console.log(JSON.parse(JSON.stringify(component.get("v.oppProducts"))));                                       
                }                
            }
            else{
                console.log('Problem getting Opportunity Products, response state: ' + state);
            }
        });
        $A.enqueueAction(action);
    }
})

HELPER

({
    createTable : function(component) {
        component.set('v.tableColumns', [
    {label:'Product Code', fieldName:'prodCode', type:'text'},
    {label:'Total Value', fieldName:'totalVal', type:'currency'}    
        ]);
    }
})

APEX CLASS

public class OppProductsTotalValueController {
    
    @AuraEnabled
    public static OpportunityLineItem[] getOppProducts(Id oppId)
    {
        // Check to make sure relevant fields are accessible to this user
        String[] fieldsToCheck = new String[] {
            'ProductCode', 'TotalPrice'
        };
        
        Map<String,Schema.SObjectField> fieldDescribeTokens = 
            Schema.SObjectType.OpportunityLineItem.fields.getMap();
        
        for(String field : fieldsToCheck) {
            if( ! fieldDescribeTokens.get(field).getDescribe().isAccessible()) {
                throw new System.NoAccessException();
            }
        }
        
        //Check for any products which have been added    
        OpportunityLineItem[] returnedOppProds;
        
        returnedOppProds = [SELECT ProductCode, TotalPrice FROM OpportunityLineItem WHERE (OpportunityId = :oppId AND TotalPrice > 0)];
                        
        return returnedOppProds;
    }    
}

Thanks in advance!
Hi. I am trying to implement an interface that will perform the following filter on input records.

- Do not include any record that has the field “Deleted__c” as true. (I have already created this custom field in the Account object)
- Do not include any record that is newer than 24 hours.
- Do not include any record that has an address outside of Japan.

Unfortunately, when I try the unit tests I created,  there are some System.AssertException errors. Having searched all over the internet for possible solutions, I am at a loss at what I am doing wrong. Please have a look at my code and guide me on what I should change. Any help would be greatly appreciated. Many thanks in advance.

INTERFACE
public interface IFilter {
List<Account> filter(List<Account> records);
}

IMPLEMENTATION
public class AccountFilterJapanOnly implements IFilter{

    public List<Account> filter(List<Account> records)
    {
        DateTime twentyFourHoursAgo = DateTime.now().addHours(-24);
        List<String> jpCountry = new List<String>{'Japan', 'JP'};
        
        List<Account> returnedAccountsList = new List<Account>();
        
        for( Account matchingAccount : [SELECT Name, AccountNumber, BillingAddress, Deleted__c, CreatedDate
                                        FROM Account
                                        WHERE Deleted__c != TRUE AND 
                                             CreatedDate < :twentyFourHoursAgo AND
                                            BillingCountry IN :jpCountry])
        {
            System.debug(matchingAccount);
            returnedAccountsList.add(matchingAccount);
        }
        
        return returnedAccountsList;
    }    
}

UNIT TESTS
@isTest
public class AccountFilterJapanOnlyTest {

    //NOT WORKING AS EXPECTED
    @isTest static void testDeletedField()
    {
        Account testAccDelTrue = new Account(Name='DeletedFieldTrue', Deleted__c=TRUE);
        Account testAccDelFalse = new Account(Name='DeletedFieldFalse', Deleted__c=FALSE);
        Account[] accts = new Account[]{testAccDelTrue, testAccDelFalse};
        //Insert accts;
        
        Test.startTest();
        AccountFilterJapanOnly jpRecords = new AccountFilterJapanOnly();
        List<Account> lst = jpRecords.filter(accts);
        Test.stopTest();
        
        System.assertEquals(1, lst.size());
        System.assertEquals(testAccDelFalse, lst[0]);        
    }
    
    //GIVING CORRECT RESULTS BUT STILL UNSURE IF THIS IS ACCURATE
    @isTest static void testCreatedDate()
    {        
        Account testCreatedDate = new Account(Name='Created Within 24 hours');
        Account[] accts = new Account[]{testCreatedDate};
        Insert accts;
        
        Test.startTest();
        AccountFilterJapanOnly jpRecords = new AccountFilterJapanOnly();
        List<Account> lst = jpRecords.filter(accts);
        Test.stopTest();
        
        System.assertEquals(0, lst.size());        
    }
    
    //NOT WORKING AS EXPECTED
    @isTest static void testLocation()
    {       
        Account testOutsideJapan = new Account(Name='Address Outside Japan', BillingCountry='USA');
        Account testWithinJapan1 = new Account(Name='Address1 Within Japan', BillingCountry='Japan');
        Account testWithinJapan2 = new Account(Name='Address2 Within Japan', BillingCountry='JP');
        Account[] accts = new Account[]{testOutsideJapan,testWithinJapan1,testWithinJapan2};
        Insert accts;
        
        Test.startTest();
        AccountFilterJapanOnly jpRecords = new AccountFilterJapanOnly();
        List<Account> lst = jpRecords.filter(accts);
        Test.stopTest();
        
        System.assertEquals(2, lst.size());
        System.assertEquals(true, lst.contains(testWithinJapan1));
        System.assertEquals(true, lst.contains(testWithinJapan2));
    }
}



 
Hi. I created a component which when dropped onto the opportunity screen, it is supposed to show a summary of the total value of all the added products. I checked the logs and the relevant data is sent back from the server but for some reason it is not showing on my table. If you can please take a look at my code and advise me on what is wrong, I'd highly appreciate it.Here it is:

COMPONENT

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="OppProductsTotalValueController">
    <aura:attribute name="oppProducts" type="OpportunityLineItem[]"/>
    <aura:attribute name="displayText" type="String" default="" description="for displaying a message when the opportunity has no products added"/>
    <aura:attribute name="tableColumns" type="List"/>
    <aura:attribute name="headerTitle" type="Aura.Component[]">
        <b>Total Value of Added Products</b>
    </aura:attribute>
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
    
    <lightning:card>
        <aura:set attribute="title">{!v.headerTitle}</aura:set>
        <p class="slds-card__body_inner">
            <aura:text value="{! v.displayText }"/>
        </p>
        <lightning:datatable data="{!v.oppProducts}" columns="{!v.tableColumns}" keyField="id" hideCheckboxColumn="true"/>
    </lightning:card>    
    
</aura:component>

CONTROLLER

({
    doInit: function(component, event, helper) {  
         
        //Get opportunity products
        var action = component.get("c.getOppProducts");
        action.setParams({"oppId": component.get("v.recordId")});
        
        // Pass the data to my attribute and create table
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){                                
                if(response.getReturnValue().length == 0)
                {
                    component.set("v.displayText","This opportunity has no products added to it.");                        
                }
                else
                {   
                    helper.createTable(component); 
                    component.set("v.oppProducts", response.getReturnValue());
                        //For checking the data passed back from the server
                        console.log(JSON.parse(JSON.stringify(component.get("v.oppProducts"))));                                       
                }                
            }
            else{
                console.log('Problem getting Opportunity Products, response state: ' + state);
            }
        });
        $A.enqueueAction(action);
    }
})

HELPER

({
    createTable : function(component) {
        component.set('v.tableColumns', [
    {label:'Product Code', fieldName:'prodCode', type:'text'},
    {label:'Total Value', fieldName:'totalVal', type:'currency'}    
        ]);
    }
})

APEX CLASS

public class OppProductsTotalValueController {
    
    @AuraEnabled
    public static OpportunityLineItem[] getOppProducts(Id oppId)
    {
        // Check to make sure relevant fields are accessible to this user
        String[] fieldsToCheck = new String[] {
            'ProductCode', 'TotalPrice'
        };
        
        Map<String,Schema.SObjectField> fieldDescribeTokens = 
            Schema.SObjectType.OpportunityLineItem.fields.getMap();
        
        for(String field : fieldsToCheck) {
            if( ! fieldDescribeTokens.get(field).getDescribe().isAccessible()) {
                throw new System.NoAccessException();
            }
        }
        
        //Check for any products which have been added    
        OpportunityLineItem[] returnedOppProds;
        
        returnedOppProds = [SELECT ProductCode, TotalPrice FROM OpportunityLineItem WHERE (OpportunityId = :oppId AND TotalPrice > 0)];
                        
        return returnedOppProds;
    }    
}

Thanks in advance!