• Santosh-Gaddam
  • NEWBIE
  • 10 Points
  • Member since 2018
  • Salesforce Consultant
  • innovateForce.com

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Im receiving this error when trying to delete a Master-Relatioship that I don't need anymore. I already deleted all records and references to this filed in the object, but SF still trows the same error.  Any ideas?

Thanks.
Hello,
While solving challenge 8 I am getting an error:- 
Challenge Not yet complete... here's what's wrong: 
Ensure that orderTrigger and orderHelper are still working as specified in the earlier challenge.
Please let me know what I am doing wrong else paste the correct code here.
My code goes as follows-:

CLASS- OrderTests

@isTest
public class OrderTests {
    @testSetup 
    public static void SetupTestData() {     
            TestDataFactory.InsertTestData(3);      
    }
    
   @isTest
    public static void OrderUpdate_UnitTest (){
        Test.startTest();
        
        List<Product2> originalProduct=[Select Quantity_Ordered__c from Product2 where Name like 'ProductConstruction%'];
        
        List<Order> ord=new List<Order>();
        List<Order> testOrders=[Select status from Order where status='Draft'];
        System.debug('originalPro '+originalProduct);
        System.debug('Ordertest orders '+testOrders);
        
        for(Order o:testOrders){
            
            o.Status=Constants.ACTIVATED_ORDER_STATUS;
            ord.add(o);
        }
        System.debug('OrderTests 21 '+ord);
        update ord;
        List<Product2> updatedProduct=OrderHelper.pr; 
        //System.debug(updatedProduct.get(0)+' '+originalProduct.get(0));
           TestDataFactory.VerifyQuantityOrdered(originalProduct.get(0), updatedProduct.get(0), (Integer)OrderHelper.temp.get(0)); 
        Test.stopTest();
    }
    @isTest
    public static void OrderExtension_UnitTest (){
        Test.startTest();
        
        Account ac=new Account();
        ac.Name='Test1';
        insert ac;
        
        Contract ct=new Contract();
        ct.AccountId=ac.Id;
        ct.StartDate =date.today();
        ct.Status='Draft';
        ct.ContractTerm=4; 
        insert ct;
        
        Order obj=new Order();
        obj.AccountId=ac.Id;
        obj.EffectiveDate=date.today();
        obj.ContractId=ct.Id;
        obj.Status='Draft';
        obj.Name='OrderName';
       
        insert obj;
        
        ApexPages.StandardController sc = new ApexPages.StandardController(obj);
        
        OrderExtension cc=new OrderExtension(sc);
        cc.SelectFamily();
        cc.OnFieldChange();
        cc.Save();
        cc.First();
        cc.Next();
        cc.Previous();
        cc.Last();
        cc.GetHasPrevious();
        cc.GetHasNext();
        cc.GetTotalPages();
        cc.GetFamilyOptions();
        Test.stopTest();
    }
}

CLASS- prouct2Tests
@isTest (seeAllData=true)
private class Product2Tests {

    /**
     * @name product2Extension_UnitTest
     * @description UnitTest for product2Extension
    **/ 
    static TestMethod void Product2Extension_UnitTest(){
        Test.startTest();
           PageReference pageRef = Page.Product2New;
           Test.setCurrentPage(pageRef);
          
        
        ApexPages.StandardController controller =new Apexpages.StandardController(new Product2());
            Product2Extension ext = new Product2Extension(controller);
            ext.addRows();
            ext.save();
            System.assertEquals(Product2Extension.productsToInsert.size(), Constants.DEFAULT_ROWS);
        
         
         //if(addValue.equals('Add'))
                  //System.assertEquals(Product2Extension.productsToInsert.size(), 2*Constants.DEFAULT_ROWS);
        
        Integer i=0;
        for(Product2Extension.ProductWrapper pr: Product2Extension.productsToInsert){
            if (String.isBlank(pr.productRecord.Name) || pr.productRecord.Name==null){
                pr.productRecord.Name='Product'+i;
            }
               
            if(String.isBlank(pr.productRecord.Family) ||  pr.productRecord.Family==null ){
                pr.productRecord.Family='Side';
            }
                  
            if(pr.productRecord.IsActive==false){
                pr.productRecord.IsActive=true;
            }
            if(pr.productRecord.Initial_Inventory__c==null){
                pr.productRecord.Initial_Inventory__c=15;
            }
            i++;
                   
        }
        PageReference p=ext.save();
        List<Product2> queryResults=[Select Name,IsActive,Initial_Inventory__c from Product2 where Initial_Inventory__c=15 and IsActive= true and Family='Side'];
                Test.stopTest();
        System.assertEquals(queryResults.size(), 5);
        System.debug(Product2Extension.productsToInsert.size());       

    }
    static void Product2Trigger_UnitTest(){
        Test.startTest();
        
        Product2 p=new Product2();
        p.Name='TestProduct';
        p.Family='Side';
        p.IsActive=true;
        p.Quantity_Ordered__c =100;
        p.Initial_Inventory__c =10;
        insert p;
        
        p.Quantity_Ordered__c=200;
        update p;
            
        Test.stopTest();
    }

}

CLASS - OrderHelper
public without sharing class OrderHelper {

    /**
     * @name AfterUpdate
     * @description 
     * @param List<Order> newList
     * @param List<Order> oldList
     * @return void
    **/
    public static List<Product2> pr=new List<Product2>();
    public static List<Decimal> temp;
    public static void AfterUpdate(List<Order> newList, List<Order> oldList){
        Set<Id> orderIds = new Set<Id>();
        for ( Integer i=0; i<newList.size(); i++ ){
            if ( newList[i].Status == Constants.ACTIVATED_ORDER_STATUS && oldList[i].Status == Constants.DRAFT_ORDER_STATUS ){
                orderIds.add(newList[i].Id);
            }
        }
        System.debug('New Order '+newList);
        System.debug('Old Order '+oldList);
        System.debug('OrderIDS '+orderIds);
        OrderHelper.RollUpOrderItems(orderIds);
    }

    /**
     * @name RollUpOrderItems
     * @description Given a set of Activated Order ids, query the child Order Items and related Products to calculate Inventory levels
     * @param Set<Id> activatedOrderIds
     * @return void
    **/
    public static void RollUpOrderItems(Set<Id> activatedOrderIds){
        List<OrderItem> oi=[Select Id, Product2Id ,AvailableQuantity from OrderItem where OrderId IN:activatedOrderIds];
        Map<Id,Product2> productMap=new Map<Id,Product2>();
        //ToDo: Declare a Map named "productMap" of Ids to Product2 records

        //ToDo: Loop through a query of OrderItems related to the activatedOrderIds
        for(OrderItem ord:oi){
            Product2 p=[Select Id,Name, Quantity_Ordered__c , Quantity_Remaining__c from Product2 where Id=: ord.Product2Id ];
            productMap.put(ord.Product2Id, p);
         }
         
        
          AggregateResult[] groupedResults =[Select Product2Id,SUM(Quantity) from OrderItem where Product2Id IN : productMap.keySet() group by Product2Id];
        
        for(AggregateResult ag:groupedResults){
             Product2 p= productmap.get((Id)ag.get('Product2Id'));
               p.Quantity_Ordered__c =(Double)ag.get('expr0');
                temp.add(p.Quantity_Ordered__c);
               pr.add(p);
        }
        System.debug('orderHelper'+pr+' '+activatedOrderIds+' '+groupedResults);
        update pr;
            //ToDo: Populate the map with the Id of the related Product2 as the key and Product2 record as the value
            
        //ToDo: Loop through a query that aggregates the OrderItems related to the Products in the ProductMap keyset

        //ToDo: Perform an update on the records in the productMap
    }

}

Thanks in advance
Shubham Nandwana
Create a Queueable Apex class that inserts the same Contact for each Account for a specific state. Write unit tests that achieve 100% code coverage for the class.
Create an Apex class called 'AddPrimaryContact' that implements the Queueable interface.
Create a constructor for the class that accepts as its first argument a Contact sObject and a second argument as a string for the State abbreviation.
The execute method must query for a maximum of 200 Accounts with the BillingState specified by the State abbreviation passed into the constructor and insert the Contact sObject record associated to each Account. Look at the sObject clone() method.
Create an Apex test class called 'AddPrimaryContactTest'.
In the test class, insert 50 Account records for BillingState "NY" and 50 Account records for BillingState "CA". Create an instance of the AddPrimaryContact class, enqueue the job and assert that a Contact record was inserted for each of the 50 Accounts with the BillingState of "CA".
The unit tests must cover all lines of code included in the AddPrimaryContact class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.
Hi,
the challenge is as follows :

Create a camping component that contains a campingHeader and a campingList component.
1.The campingList component contains an ordered list of camping supplies that include Bug Spray, Bear Repellant, and Goat Food.
2.The campingHeader component contains an H1 heading style with a font size of 18 points and displays 'Camping List'.

so i made a lightening application named "camping.app" having code :

<aura:application >
    <br/><br/><br/>
    <c:campingHeader/>
    <c:campingList/>  
</aura:application>


where lightening component "campingHeader.cmp" having code :

<aura:component >
    <h1> Camping List </h1>
</aura:component>

for I have "campingHeader.css" having code :
.THIS {
}

h1.THIS {
    font-size: 18px;
}

and lightening component "campingList.cmp" having code :

<aura:component >
    <ol>
       <li>Bug Spray</li>
       <li>Bear Repellant</li>
       <li>Goat Food</li>      
    </ol>
</aura:component>

when i preview the application it is working nice; but when checking the challenge it says :
"Challenge Not yet complete... here's what's wrong: 
The 'camping' Lightning Component does not include either the campingHeader or campingList component."

please help me know where I m doing wrong. Thanx waiting for your reply