• Suchismita Mukherjee 7
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
I got stucked in challenge 3 getting below error.
Challenge Not yet complete... here's what's wrong:
Ensure that the save method inserts only Products and Pricebooks for rows that have all fields populated.

 
tried all possible ways but no hope.. :(
...............................Pelase help......
 
my code:
Product2Extension>>>>>>>>>>>>>>>>>>>>>

public class Product2Extension {

    public List<ProductWrapper> productsToInsert {get;set;}

    public Product2Extension(ApexPages.StandardController controller){
        productsToInsert = new List<ProductWrapper>();
        addRows();
    }
    
    public List<SelectOption> GetFamilyOptions() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption(Constants.SELECT_ONE, Constants.SELECT_ONE));
        for(PickListEntry eachPicklistValue : Constants.PRODUCT_FAMILY) {
            options.add(new SelectOption(eachPicklistValue.getValue(), eachPicklistValue.getLabel()));
        }
            return options;
    }
    
    public void AddRows(){
        for (Integer i=0; i<Constants.DEFAULT_ROWS; i++ ){
            productsToInsert.add(new ProductWrapper());
        }
    }

    public List<ChartHelper.ChartData> GetInventory(){
        return ChartHelper.GetInventory();
    }

    public PageReference Save(){
        SavePoint sp = Database.setSavepoint();
        Integer insertedCount = 0;
        try {
           list<product2> newProducts = new list<product2>();
            list<PriceBookEntry> newPBEntries = new list<PriceBookEntry>();
            for(ProductWrapper eachPW : productsToInsert) {
                if(eachPW.productRecord.Name != null && eachPW.productRecord.Family != null && constants.SELECT_ONE != eachPW.productRecord.Family && eachPW.productRecord.Initial_Inventory__c != null && eachPW.pricebookEntryRecord.UnitPrice != null) {
                    newProducts.add(eachPW.productRecord);
                    eachPW.pricebookEntryRecord.IsActive = true;
                    eachPW.pricebookEntryRecord.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
                    newPBEntries.add(eachPW.pricebookEntryRecord);
                }
            }
            insert newProducts;
           
            insert newPBEntries;
            
            //If successful clear the list and display an informational message
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,insertedCount + ' Inserted'));
            productsToInsert.clear();   //Do not remove
            addRows();  //Do not remove
        } 
        catch (Exception e){
            System.debug('Exception occured:'+e.getMessage());
            Database.rollback(sp);
            apexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, Constants.ERROR_MESSAGE));            
        }
        return null;
    }
    
    public class ProductWrapper {
        public Product2 productRecord {get;set;}
        public PriceBookEntry pricebookEntryRecord {get;set;}
        
        public ProductWrapper() {
            productRecord = new Product2();
            pricebookEntryRecord = new PricebookEntry();
        }
    }
}
Product2New vf >>>>>>>>>>>>>>>>>>>>>
<apex:page standardcontroller="Product2" extensions="Product2Extension">
    <apex:sectionHeader title="New Product" subtitle="Add Inventory" />
    <apex:pageMessages id="pageMessages" />
    <apex:form id="form" >
        <apex:actionRegion >
            <apex:pageBlock title="Existing Inventory" id="existingInv">
                <apex:chart data="{!Inventory}" width="600" height="400">
                    <apex:axis type="Category" fields="name" position="left" title="Product Family"/>
                    <apex:axis type="Numeric" fields="val" position="bottom" title="Quantity Remaining"/>
                    <apex:barSeries axis="bottom" orientation="horizontal" xField="val" yField="name"/>
                 </apex:chart>                
            </apex:pageBlock>
            <apex:pageBlock title="New Products" >
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!save}" value="Save" reRender="existingInv, orderItemTable, pageMessages"/>
                </apex:pageBlockButtons>
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton action="{!addRows}" value="Add" reRender="orderItemTable, pageMessages" />
                </apex:pageBlockButtons>

                <apex:pageBlockTable value="{!productsToInsert}" var="p" id="orderItemTable" >
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}" >
                        <apex:inputText value="{!p.productRecord.Name}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}" >
                        <apex:selectList value="{!p.productRecord.Family}" size="1" multiselect="false">
                            <apex:selectOptions value="{!FamilyOptions}"></apex:selectOptions>
                        </apex:selectList>
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.IsActive.Label}" >
                        <apex:inputField value="{!p.productRecord.isActive}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.PricebookEntry.Fields.UnitPrice.Label}" >
                        <apex:inputText value="{!p.pricebookEntryRecord.UnitPrice}" />
                    </apex:column>
                    <apex:column headerValue="{!$ObjectType.Product2.Fields.Initial_Inventory__c.Label}" >
                        <apex:inputField value="{!p.productRecord.Initial_Inventory__c}" />
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:actionRegion>
    </apex:form>
</apex:page>

ChartHelper class>>>>>>>>>>>>>>>>>>>>>>>>

public without sharing class ChartHelper {

  @AuraEnabled
  public static List<chartData> GetInventory(){
    List<chartData> cht = new List<chartData>();

    for(AggregateResult ar : [SELECT Family, SUM(Quantity_Remaining__c) FROM Product2 WHERE Quantity_Remaining__c > 0 AND IsActive = true GROUP BY Family]) {
      cht.add(new ChartData(String.ValueOf(ar.get('Family')), Integer.ValueOf(ar.get('expr0'))));
    }

    return cht;
  }


  public class ChartData {
    public String name {get; set;}
    public Decimal val {get; set;}

    public ChartData(String name, Decimal val){
      this.name = name;
      this.val = val;
    }
  }

}
Hi,

I have done the process builder but it is showing me error:
"The Fulfillment Creation Process does not appear to be working properly.Please check your task was created with all of the field values set appropriately"

My process builder is:
process builder

User-added image
User-added image


User-added imageUser-added image
Hi All,
I am getting the error "The campingList JavaScript helper doesn't appear to have the correct functionality. Ensure that it is saving the new record to the database and in the callback, pushing the new record to the array of existing items (e.g., v.items) and setting the modified array of items to the 'items' value provider to display the updated list." Please help me to resolve the error.
My code:

campingList.cmp
<aura:component controller="CampingListController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
 <!--<ol>
    <li>Bug Spray</li>
    <li>Bear Repellant</li>
    <li>Goat Food</li>
    </ol>-->
    <!--<aura:attribute name="olditem" type="Camping_Item__c"/>-->
    <ltng:require styles="/resource/SLDS105/assets/styles/salesforce-lightning-design-system-ltng.css"/>
    <aura:attribute name="items" type="Camping_Item__c[]"/>
    <aura:attribute name="newItem" type="Camping_Item__c" default="{'sobjectType':'Camping_Item__c',
                                                                   'Quantity__c': 0,
                                                                   'Price__c': 0.0}"/>
   
   <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <div class="slds-card slds-p-top--medium">
    <lightning:card title="Existing Items">
        <p class="slds-p-horizontal--small">
            <aura:iteration items="{!v.items}" var="itms">
                <c:campingListItem item="{!itms}"/>
            </aura:iteration>
        </p>
    </lightning:card>
    <br/>
    <!-- CREATE NEW Camping FORM Name, Quantity, Price, and Packed-->
    <form class="slds-form--stacked"> 
        <lightning:input aura:id="campingform" label="Name"
                             name="campingname"
                             value="{!v.newItem.Name}"/>
        <lightning:input type="number" aura:id="campingform" label="Quantity"
                             name="Quantity"
                             min="1"
                             value="{!v.newItem.Quantity__c}"
                             messageWhenRangeUnderflow="Enter an atleast 1 digit"/>
        <lightning:input type="number" aura:id="campingform" label="Price"
                             name="Price"
                             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 type="checkbox" aura:id="campingform" label="Packed?" 
                             name="Packed"
                             checked="{!v.newItem.Packed__c}"/>
        <lightning:button label="click to Create Item"
                              class="slds-m-top--medium"
                              variant="brand"
                              onclick="{!c.clickCreateItem}"/>
    </form>
    <br/>
     <lightning:card title="Items">
        <p class="slds-p-horizontal--small">
            <aura:iteration items="{!v.items}" var="itms">
                <c:campingListItem item="{!itms}"/>
            </aura:iteration>
        </p>
    </lightning:card>
    </div>
</aura:component>

campingListController.js
({
    doInit: function(component, event, helper) {
        var action=component.get("c.getItems");
        action.setCallback(this,function(data){
           
            component.set("v.items",data.getReturnValue());
            })
        $A.enqueueAction(action);
    },
 clickCreateItem : function(component, event, helper) {
        var newitem= component.get("v.newItem");
        helper.createItem(component, newitem);
           /*var item=JSON.parse(JSON.stringify(newitem));
            console.log("the new item:"+JSON.stringify(newitem));
            //newitem.push(item);
            component.set("v.items",newitem);
            component.set("v.newItem",{'sobjectType':'Camping_Item__c',
                'Name': '',
                'Quantity__c': 0,
                'Price__c': 0,
                'Packed__c': false});*/
         
  $A.enqueueAction(action);
 }
})


campingListHelper.js
({
 createItem : function(component, newitem) {
        var validitems =component.find('campingform').reduce(function(validSoFar,inputCmp){
             inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        if(validitems){
        var actionsave=component.get("saveItem");
            //var strng=JSON.parse(JSON.stringify(newitem);
            actionsave.setParams({"ci": newitem});
            actionsave.setCallback(this,function(data){
                var state = data.getState();
             if (state === "SUCCESS") {
                    var campings=component.get("v.items");
                    campings.push(data.getReturnValue());
                    component.set("v.items",campings);
                    component.set("v.newItem",{'sobjectType':'Camping_Item__c',
                'Name': '',
                'Quantity__c': 0,
                'Price__c': 0,
                'Packed__c': false});
                }
            })
        }
 }
})
campingListController.apxc
public class CampingListController
{
    @AuraEnabled
    public static list<Camping_Item__c> getItems()
    {
        return([Select Name,Price__c,Quantity__c,Packed__c from Camping_Item__c]);
    }
 @AuraEnabled
    public static Camping_Item__c saveItem(Camping_Item__c ci){
        insert ci;
        return ci;
    }
}
Hello,
I am using a standard object (Action Plan) and I would like to give access to records for a specific profile once I have updated a checkbox.
The org does not use 'Role' so using criteria based sharing rule is not an option.
I could probably use a trigger but I am not quite sure how to give visibility to the record once I have ticked the checkbox.
Does anyone have a sample code?
Thanks
 
Hi,

I have done the process builder but it is showing me error:
"The Fulfillment Creation Process does not appear to be working properly.Please check your task was created with all of the field values set appropriately"

My process builder is:
process builder

User-added image
User-added image


User-added imageUser-added image
Error : 
User-added image

I have overridden the add and new standard buttons as well.
User-added image
Product2Extension.cls :
public class Product2Extension {

  public List<ProductWrapper> productsToInsert {get; set;}

  public Product2Extension(ApexPages.StandardController controller){
    productsToInsert = new List<ProductWrapper>();
    AddRows();
  }

  public void AddRows(){
    for (Integer i=0; i<Constants.DEFAULT_ROWS; i++ ) {
      productsToInsert.add( new ProductWrapper() );
    }
  }

  public List<ChartHelper.ChartData> GetInventory(){
    return ChartHelper.GetInventory();
  }

  public List<SelectOption> GetFamilyOptions() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption(Constants.SELECT_ONE, Constants.SELECT_ONE));
    for(PickListEntry eachPicklistValue : Constants.PRODUCT_FAMILY) {
      options.add(new SelectOption(eachPicklistValue.getValue(), eachPicklistValue.getLabel()));
    }
    return options;
  }

  public PageReference Save(){
    Savepoint sp = Database.setSavepoint();
    try {
      List<Product2> products = new List<Product2>();
      List<PricebookEntry> pbes = new List<PricebookEntry>();

      for (ProductWrapper prodwrapper : productsToInsert) {
        if(prodwrapper.productRecord != null && prodwrapper.pricebookEntryRecord != null) {
          if(prodwrapper.productRecord.Name != null && prodwrapper.productRecord.Family != null && constants.SELECT_ONE != prodwrapper.productRecord.Family && prodwrapper.productRecord.Initial_Inventory__c != null && prodwrapper.pricebookEntryRecord.UnitPrice != null) {
            products.add(prodwrapper.productRecord);
            PricebookEntry pbe = prodwrapper.pricebookEntryRecord;
            pbe.IsActive = true;
            pbe.Pricebook2Id = Constants.STANDARD_PRICEBOOK_ID;
            pbes.add(pbe);
          }
        }
      }

      insert products;

      for (integer i = 0; i < pbes.size(); i++) {
        pbes[i].Product2Id = products[i].Id;
      }
      insert pbes;

      //If successful clear the list and display an informational message
      apexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,productsToInsert.size()+' Inserted'));
      productsToInsert.clear();         //Do not remove
      AddRows();        //Do not remove
    } catch (Exception e){
      Database.rollback(sp);
      apexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, Constants.ERROR_MESSAGE));
    }
    return null;
  }

  public class ProductWrapper {
    public Product2 productRecord {get; set;}
    public PriceBookEntry pricebookEntryRecord {get; set;}

    public ProductWrapper() {
      productRecord = new product2(Initial_Inventory__c =0);
      pricebookEntryRecord = new pricebookEntry(Unitprice=0.0);
    }
  }
}
Product2New​.page :
<apex:page standardcontroller="Product2" extensions="Product2Extension">
  <apex:sectionHeader title="New Product" subtitle="Add Inventory"/>
  <apex:pageMessages id="pageMessages"/>
  <apex:form id="form">
    <apex:actionRegion>
      <apex:pageBlock title="Existing Inventory" id="existingInv">
        <apex:chart data="{!Inventory}" width="600" height="400">
          <apex:axis type="Category" fields="name" position="left" title="Product Family"/>
          <apex:axis type="Numeric" fields="val" position="bottom" title="Quantity Remaining"/>
          <apex:barSeries axis="bottom" orientation="horizontal" xField="val" yField="name"/>
        </apex:chart>
      </apex:pageBlock>
      <apex:pageBlock title="New Products">
        <apex:pageBlockButtons location="top">
          <apex:commandButton action="{!save}" value="Save" reRender="existingInv, orderItemTable, pageMessages"/>
        </apex:pageBlockButtons>
        <apex:pageBlockButtons location="bottom">
          <apex:commandButton action="{!addRows}" value="Add" reRender="orderItemTable, pageMessages"/>
        </apex:pageBlockButtons>

        <apex:pageBlockTable value="{!productsToInsert}" var="p" id="orderItemTable">
          <apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}">
            <apex:inputText value="{!p.productRecord.Name}"/>
          </apex:column>
          <apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}">
            <apex:selectList value="{!p.productRecord.Family}" size="1" multiselect="false">
              <apex:selectOptions value="{!FamilyOptions}"></apex:selectOptions>
            </apex:selectList>
          </apex:column>
          <apex:column headerValue="{!$ObjectType.Product2.Fields.IsActive.Label}">
            <apex:inputField value="{!p.productRecord.isActive}"/>
          </apex:column>
          <apex:column headerValue="{!$ObjectType.PricebookEntry.Fields.UnitPrice.Label}">
            <apex:inputText value="{!p.pricebookEntryRecord.UnitPrice}"/>
          </apex:column>
          <apex:column headerValue="{!$ObjectType.Product2.Fields.Initial_Inventory__c.Label}">
            <apex:inputField value="{!p.productRecord.Initial_Inventory__c}"/>
          </apex:column>
        </apex:pageBlockTable>
      </apex:pageBlock>
    </apex:actionRegion>
  </apex:form>
</apex:page>
product2Trigger : 
trigger product2Trigger on Product2 (after update) {
  Product2Helper.AfterUpdate((List<Product2>)Trigger.new);
}
Constants.cls : 
public class Constants {
  public static final Integer DEFAULT_ROWS = 5;
  public static final String SELECT_ONE = Label.Select_One;
  public static final String INVENTORY_LEVEL_LOW = Label.Inventory_Level_Low;
  public static final List<Schema.PicklistEntry> PRODUCT_FAMILY = Product2.Family.getDescribe().getPicklistValues();
  public static final String DRAFT_ORDER_STATUS = 'Draft';
  public static final String ACTIVATED_ORDER_STATUS = 'Activated';
  public static final String INVENTORY_ANNOUNCEMENTS = 'Inventory Announcements';
  public static final String ERROR_MESSAGE = 'An error has occurred, please take a screenshot with the URL and send it to IT.';
  public static final Id STANDARD_PRICEBOOK_ID = '01s6A0000031LaYQAU'; //Test.isRunningTest() ? Test.getStandardPricebookId() : [SELECT Id FROM PriceBook2 WHERE isStandard = true LIMIT 1].Id;
}
Can somebody try and paste the working code here. It would be a great help.
Thanks in advance.