• ani gho 10
  • NEWBIE
  • 5 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 0
    Questions
  • 4
    Replies
【Advanced Apex Specialist --- Step 4: Create the Test Data Factory】

Hi,everyone I working on 
Advanced Apex Specialist --- Step 4: Create the Test Data Factory today,and I continuously got the Error as below:
------------------------------------------------------------------------------------
Challenge Not yet complete... here's what's wrong:
【Ensure insertTestData uses the other methods in the class to insert Products, Pricebooks, Accounts, Contacts, Orders, and OrderItem.】

------------------------------------------------------------------------------------

but I hava no idea where I was wrong!!? I test my TestDataFactory class in Anonymous Window it is seems like work,and did not get and error,
and certainly got data inserted successfully.

I also use the other guys code to test several times,but got the same Error above,Can someo kindly give me some suggestion??
I really appreciate that,I got stuck here whole days......it is just simply generate some test datas...I could not figure out what is wrong with that。
I post my code down below,thanks!!


/**
 * @name TestDataFactory
 * @description Contains methods to construct and/or validate commonly used records
**/

public with sharing class TestDataFactory {

    /**
     * @name ConstructCollaborationGroup
     * @description
    **/
    public static CollaborationGroup ConstructCollaborationGroup(){
        //ToDo: Ensure this method returns a single Chatter CollaborationGroup
        //    whose Name starts with 'TEST' followed by the INVENTORY_ANNOUNCEMENTS constant
        //    and configured so anyone can join, see and post updates.
            CollaborationGroup chatterGroup = new CollaborationGroup(
            Name = 'TEST'+Constants.INVENTORY_ANNOUNCEMENTS,  
            CollaborationType = 'Public'
        );
        return chatterGroup;
    }

    /**
     * @name CreateProducts
     * @description Constructs a list of Product2 records for unit tests
    **/
    public static List<Product2> ConstructProducts(Integer cnt){
        List<Product2> products=new List<Product2>();
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Product2 records
        //  with all the required fields populated
        //  and IsActive = true
        //  an Initial Inventory set to 10
        //  and iterating through the product family picklist values throughout the list.
        for(Integer i=0;i<cnt;i++){
            Product2 eachProduct=new Product2();
            eachProduct.Name='testProduct '+i;
            eachProduct.IsActive=true;
            eachProduct.Initial_Inventory__c=10;
            eachProduct.Family=Constants.PRODUCT_FAMILY.get(math.mod(i,4)).getValue();
            products.add(eachProduct);
        }
        return products;
    }

    /**
     * @name CreatePricebookEntries
     * @description Constructs a list of PricebookEntry records for unit tests
    **/
    public static List<PriceBookEntry> ConstructPricebookEntries(List<Product2> prods){
        List<PriceBookEntry> pbeList = new List<PriceBookEntry>();
        //ToDo: Ensure this method returns a corresponding list of PricebookEntries records
        //  related to the provided Products
        //  with all the required fields populated
        //  and IsActive = true
        //  and belonging to the standard Pricebook
        for(Product2 p:prods){
            PriceBookEntry pbe = new PriceBookEntry();
            pbe.Product2Id = p.Id;
            pbe.IsActive = true;
            pbe.Pricebook2Id=Constants.STANDARD_PRICEBOOK_ID;
            pbe.UnitPrice = 100;
            pbeList.add(pbe);
        }       
        return pbeList;
    }

    /**
     * @name CreateAccounts
     * @description Constructs a list of Account records for unit tests
    **/
    public static List<Account> ConstructAccounts(Integer cnt){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Account records
        //  with all of the required fields populated.
        List<Account> accounts = new List<Account>();
        for(Integer i = 0 ; i<cnt; i++) {
            Account acc = new Account(name='Account' + i);
            accounts.add(acc);
        }
        System.debug('account size' + accounts.size());
        return accounts;
    }

    /**
     * @name CreateContacts
     * @description Constructs a list of Contact records for unit tests
    **/
    public static List<Contact> ConstructContacts(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Contact records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Contact> contacts = new List<Contact>();
        for(Integer i=0;i<cnt;i++){
            Contact con = new Contact();
            con.LastName = 'TestContact'+i;
            Integer index = Math.mod(i, accts.size());
            con.AccountId = accts.get(index).Id;
            contacts.add(con);            
        }
        System.debug('contacts size' + contacts.size());
        System.debug('accts size' + accts.size());
        return contacts;
    }

    /**
     * @name CreateOrders
     * @description Constructs a list of Order records for unit tests
    **/
    public static List<Order> ConstructOrders(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Order records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Order> orders = new List<Order>();
        for(Integer i=0;i<cnt;i++){
            Order ord = new Order();
            ord.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            ord.Status='Draft';
            ord.EffectiveDate = System.today();
            ord.AccountId = accts.get(Math.mod(i, accts.size())).Id;           
            orders.add(ord);
        }                
        return orders;        
    }

    /**
     * @name CreateOrderItems
     * @description Constructs a list of OrderItem records for unit tests
    **/
    public static List<OrderItem> ConstructOrderItems(integer cnt, list<pricebookentry> pbes, list<order> ords){
        //ToDo: Ensure this method returns a list of size cnt of OrderItem records
        //  related to the provided Pricebook Entries
        //  and related to the provided Orders
        //  with all of the required fields populated.
        //  Hint: Use the DEFAULT_ROWS constant for Quantity as it will be used in the next challenge
        List<OrderItem> items = new List<OrderItem>();
        for(Integer i=0;i<cnt;i++){
            OrderItem ord = new OrderItem();
            ord.Quantity = Constants.DEFAULT_ROWS;
            ord.UnitPrice = 250;
            ord.OrderId =ords.get(Math.mod(i, ords.size())).Id;
            ord.PricebookEntryId = pbes.get(math.mod(i, pbes.size())).Id;
            items.add(ord);
        }
        
        return items;
    }

    /**
     * @name SetupTestData
     * @description Inserts accounts, contacts, Products, PricebookEntries, Orders, and OrderItems.
    **/
                        
    public static void InsertTestData(Integer cnt){
        //InsertTestData
        //ToDo: Ensure this method calls each of the construct methods
        //  and inserts the results for use as test data.
                
        CollaborationGroup groups = TestDataFactory.ConstructCollaborationGroup();
        insert groups;
        
        List<Product2>  products= TestDataFactory.ConstructProducts(cnt);
        insert products;
        
        List<PriceBookEntry> entries = TestDataFactory.ConstructPricebookEntries(products);
        insert entries;
        
        List<Account> accts = TestDataFactory.ConstructAccounts(cnt);
        insert accts;
        
        List<Contact> contacts = TestDataFactory.ConstructContacts(cnt,accts);
        insert contacts;
        
        List<Order> orders = TestDataFactory.ConstructOrders( cnt,  accts);
        insert orders;
        
        List<OrderItem> items = TestDataFactory.ConstructOrderItems(cnt, entries, orders);
        insert items;
    }
        
        public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered) {
        System.assertEquals((updatedProduct.Quantity_Ordered__c - originalProduct.Quantity_Ordered__c), qtyOrdered);
    }

}
Help needed with the below error
User-added image

Here is my component

<aura:component>
     <aura:attribute name="boat" type="BoatType__c" access="public"/>
    <aura:handler name="change" value="{!v.boat}" action="{!c.refresh}"/>
    <!-- set up the aura:method for refresh -->
    <aura:method name="refresh" action="{!c.doInit}" access="public"
                 description="BoatDetailsController.js invokes refresh whenever boat is updated">
    </aura:method>
     
    <ui:scrollerWrapper class="scrollerSize">
        <!--Scrollable content here -->
        <aura:if isTrue="{!v.boatReviews.length==0}">
            <lightning:layoutItem class="slds-align_absolute-center" flexibility="auto" padding="around-small">   
                <ui:outputText value="No Reviews Available" />
            </lightning:layoutItem>
        </aura:if>
        <div class="slds-feed">
            <ul class="slds-feed__list">
                <aura:iteration items="{!v.boatReviews}" var="boatReview">
                    <li class="slds-feed__item">
                        <div class="slds-media__body">
                       <div class="slds-grid slds-has-flexi-truncate">
                            <a href="javascript:void(0)" onclick="{!c.onUserInfoClick}"
          data-userid="{!boatReview.CreatedBy.Id}">
          {!boatReview.CreatedBy.Name}
      </a>
                        &nbsp; &mdash; &nbsp; {!boatReview.CreatedBy.CompanyName}
   </div>
                         <p><lightning:formattedDateTime value="{!boatReview.CreatedDate}" 
                                   year="numeric" month="short" day="numeric"  
                                   hour="2-digit" minute="2-digit" hour12="true"/></p>
                        </div>
                    </li>
                </aura:iteration>
            </ul>
        </div>
    </ui:scrollerWrapper>
    
    
</aura:component>
Hello, I'm getting the following error:

Challenge Not yet complete... here's what's wrong: 
The 'projectRef__c' field is not configured correctly as an Indirect Lookup field.

I've googled it and tried every solution but I can't fix it.

Here is how I've got configured the External Object:

User-added image

Something weird is that I'm in the last step and I have no data on the Project object. I've done Validate and Sync but nothing.

Thanks!!
The challenge as follows:

For purposes of local regulation new customers must be approved by the legal team.

When an Account has the value of 'Prospect' in the Type field, a user will click the 'Submit for Approval' button to launch an approval process. The process will only happen if Type is 'Prospect' and there are more than 500 employees. Upon entry of the process, Type will become 'Pending' and be locked. If approved, Type will be set to 'Customer' and be unlocked. If not approved, Type will be set back to 'Prospect' and will be unlocked.

The Account object's Type field must have the following picklist values: Prospect, Customer, Pending. Before creating the approval process, verify the values in your Account object setup
The approval process name must be 'Approve New Account'.
When user click 'Submit for Approval', the approval must be processed if the Type field is set to 'Prospect' and the value of Employees is greater than 500.
Upon entering the approval process, set the Type field to 'Pending' and lock the record.
Normally the approver would be someone else. In this instance, assign yourself to be the approver.
If approved, set the Type field to 'Customer' and unlock the record.
If not approved, set the Type field back to 'Prospect', and unlock the record.

I am getting error message: Challenge not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Process failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, missing required field: [nextApproverIds]: [nextApproverIds]

This are the steps I did:

Created approval process called Approve New Account
Criteria Account Type field equals Prospect and Account Employees field greater than 500
Final Approval Actions - Update Type field to Customer
Final Rejection Actions - Update Type field to Prospect

What am I missing that I received the error message?  Please help.

Thanks.
【Advanced Apex Specialist --- Step 4: Create the Test Data Factory】

Hi,everyone I working on 
Advanced Apex Specialist --- Step 4: Create the Test Data Factory today,and I continuously got the Error as below:
------------------------------------------------------------------------------------
Challenge Not yet complete... here's what's wrong:
【Ensure insertTestData uses the other methods in the class to insert Products, Pricebooks, Accounts, Contacts, Orders, and OrderItem.】

------------------------------------------------------------------------------------

but I hava no idea where I was wrong!!? I test my TestDataFactory class in Anonymous Window it is seems like work,and did not get and error,
and certainly got data inserted successfully.

I also use the other guys code to test several times,but got the same Error above,Can someo kindly give me some suggestion??
I really appreciate that,I got stuck here whole days......it is just simply generate some test datas...I could not figure out what is wrong with that。
I post my code down below,thanks!!


/**
 * @name TestDataFactory
 * @description Contains methods to construct and/or validate commonly used records
**/

public with sharing class TestDataFactory {

    /**
     * @name ConstructCollaborationGroup
     * @description
    **/
    public static CollaborationGroup ConstructCollaborationGroup(){
        //ToDo: Ensure this method returns a single Chatter CollaborationGroup
        //    whose Name starts with 'TEST' followed by the INVENTORY_ANNOUNCEMENTS constant
        //    and configured so anyone can join, see and post updates.
            CollaborationGroup chatterGroup = new CollaborationGroup(
            Name = 'TEST'+Constants.INVENTORY_ANNOUNCEMENTS,  
            CollaborationType = 'Public'
        );
        return chatterGroup;
    }

    /**
     * @name CreateProducts
     * @description Constructs a list of Product2 records for unit tests
    **/
    public static List<Product2> ConstructProducts(Integer cnt){
        List<Product2> products=new List<Product2>();
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Product2 records
        //  with all the required fields populated
        //  and IsActive = true
        //  an Initial Inventory set to 10
        //  and iterating through the product family picklist values throughout the list.
        for(Integer i=0;i<cnt;i++){
            Product2 eachProduct=new Product2();
            eachProduct.Name='testProduct '+i;
            eachProduct.IsActive=true;
            eachProduct.Initial_Inventory__c=10;
            eachProduct.Family=Constants.PRODUCT_FAMILY.get(math.mod(i,4)).getValue();
            products.add(eachProduct);
        }
        return products;
    }

    /**
     * @name CreatePricebookEntries
     * @description Constructs a list of PricebookEntry records for unit tests
    **/
    public static List<PriceBookEntry> ConstructPricebookEntries(List<Product2> prods){
        List<PriceBookEntry> pbeList = new List<PriceBookEntry>();
        //ToDo: Ensure this method returns a corresponding list of PricebookEntries records
        //  related to the provided Products
        //  with all the required fields populated
        //  and IsActive = true
        //  and belonging to the standard Pricebook
        for(Product2 p:prods){
            PriceBookEntry pbe = new PriceBookEntry();
            pbe.Product2Id = p.Id;
            pbe.IsActive = true;
            pbe.Pricebook2Id=Constants.STANDARD_PRICEBOOK_ID;
            pbe.UnitPrice = 100;
            pbeList.add(pbe);
        }       
        return pbeList;
    }

    /**
     * @name CreateAccounts
     * @description Constructs a list of Account records for unit tests
    **/
    public static List<Account> ConstructAccounts(Integer cnt){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Account records
        //  with all of the required fields populated.
        List<Account> accounts = new List<Account>();
        for(Integer i = 0 ; i<cnt; i++) {
            Account acc = new Account(name='Account' + i);
            accounts.add(acc);
        }
        System.debug('account size' + accounts.size());
        return accounts;
    }

    /**
     * @name CreateContacts
     * @description Constructs a list of Contact records for unit tests
    **/
    public static List<Contact> ConstructContacts(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list, of size cnt, of uniquely named Contact records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Contact> contacts = new List<Contact>();
        for(Integer i=0;i<cnt;i++){
            Contact con = new Contact();
            con.LastName = 'TestContact'+i;
            Integer index = Math.mod(i, accts.size());
            con.AccountId = accts.get(index).Id;
            contacts.add(con);            
        }
        System.debug('contacts size' + contacts.size());
        System.debug('accts size' + accts.size());
        return contacts;
    }

    /**
     * @name CreateOrders
     * @description Constructs a list of Order records for unit tests
    **/
    public static List<Order> ConstructOrders(Integer cnt, List<Account> accts){
        //ToDo: Ensure this method returns a list of size cnt of uniquely named Order records
        //  related to the provided Accounts
        //  with all of the required fields populated.
        List<Order> orders = new List<Order>();
        for(Integer i=0;i<cnt;i++){
            Order ord = new Order();
            ord.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            ord.Status='Draft';
            ord.EffectiveDate = System.today();
            ord.AccountId = accts.get(Math.mod(i, accts.size())).Id;           
            orders.add(ord);
        }                
        return orders;        
    }

    /**
     * @name CreateOrderItems
     * @description Constructs a list of OrderItem records for unit tests
    **/
    public static List<OrderItem> ConstructOrderItems(integer cnt, list<pricebookentry> pbes, list<order> ords){
        //ToDo: Ensure this method returns a list of size cnt of OrderItem records
        //  related to the provided Pricebook Entries
        //  and related to the provided Orders
        //  with all of the required fields populated.
        //  Hint: Use the DEFAULT_ROWS constant for Quantity as it will be used in the next challenge
        List<OrderItem> items = new List<OrderItem>();
        for(Integer i=0;i<cnt;i++){
            OrderItem ord = new OrderItem();
            ord.Quantity = Constants.DEFAULT_ROWS;
            ord.UnitPrice = 250;
            ord.OrderId =ords.get(Math.mod(i, ords.size())).Id;
            ord.PricebookEntryId = pbes.get(math.mod(i, pbes.size())).Id;
            items.add(ord);
        }
        
        return items;
    }

    /**
     * @name SetupTestData
     * @description Inserts accounts, contacts, Products, PricebookEntries, Orders, and OrderItems.
    **/
                        
    public static void InsertTestData(Integer cnt){
        //InsertTestData
        //ToDo: Ensure this method calls each of the construct methods
        //  and inserts the results for use as test data.
                
        CollaborationGroup groups = TestDataFactory.ConstructCollaborationGroup();
        insert groups;
        
        List<Product2>  products= TestDataFactory.ConstructProducts(cnt);
        insert products;
        
        List<PriceBookEntry> entries = TestDataFactory.ConstructPricebookEntries(products);
        insert entries;
        
        List<Account> accts = TestDataFactory.ConstructAccounts(cnt);
        insert accts;
        
        List<Contact> contacts = TestDataFactory.ConstructContacts(cnt,accts);
        insert contacts;
        
        List<Order> orders = TestDataFactory.ConstructOrders( cnt,  accts);
        insert orders;
        
        List<OrderItem> items = TestDataFactory.ConstructOrderItems(cnt, entries, orders);
        insert items;
    }
        
        public static void VerifyQuantityOrdered(Product2 originalProduct, Product2 updatedProduct, Integer qtyOrdered) {
        System.assertEquals((updatedProduct.Quantity_Ordered__c - originalProduct.Quantity_Ordered__c), qtyOrdered);
    }

}
Hi everyone!,

I am stuck on the suerbadge challenge:
Data Integration Specialist #3 Synchronize Salesforce opportunity data with Square Peg's PMS external system

This is my code:
 
public class ProjectCalloutService {
    public static Id opportunityId;
    
    @InvocableMethod
    public static void postOpportunityToPMS(List<Id> opportunityIds){
        opportunityId=opportunityIds.get(0);
        Opportunity opp=[Select Id,Name, closeDate,amount,Account.Name FROM Opportunity Where Id =: opportunityId];
        ID jobID = System.enqueueJob(new QueueablePMSCall(opp));
    }    
    
    public class QueueablePMSCall implements Queueable,Database.AllowsCallouts
    {
        private String jsonOpp;
        private Opportunity opportunityObject;
        public QueueablePMSCall(Opportunity opp)
        {
            opportunityObject=opp;
            JSONGenerator gen = JSON.createGenerator(true);
            gen.writeStartObject();
            gen.writeStringField('opportunityId', opp.Id);
            gen.writeStringField('opportunityName', opp.Name);
            gen.writeStringField('accountName', opp.account.Name);
            gen.writeDateField('closeDate', opp.closeDate);
            gen.writeNumberField('amount', opp.amount);
            
            gen.writeEndObject();            
            
            jsonOpp= gen.getAsString();
            System.debug('jsonOpp: ' + jsonOpp);
            
        }
        public void execute(QueueableContext context) {
            
            ServiceTokens__c token= ServiceTokens__c.getValues('ProjectServiceToken');
            System.debug(token.Token__c);
            
            // create an HTTPrequest object    
            HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setEndpoint('callout:ProjectService/'+ token.Token__c);
            req.setHeader('Content-Type', 'application/json');
            req.setBody(jsonOpp);    
            
            // create a new HTTP object
            Http http = new Http();
            HTTPResponse res = http.send(req);
            if (res.getStatusCode() != 201) {
                System.debug('Error from ' + req.getEndpoint() + ' : ' +
                             res.getStatusCode() + ' ' + res.getStatus());
                
                Opportunity opportunity1=[Select Id, StageName FROM Opportunity Where Id =: opportunityObject.Id];
                opportunity1.StageName='Resubmit Project';
                update opportunity1;
                
            }
            else {
                Opportunity opportunity2=[Select Id, StageName FROM Opportunity Where Id =: opportunityObject.Id];
                opportunity2.StageName='Submitted Project';
                update opportunity2;
            }      
        }
        
    } 
}

Thanks