• Kavita Kale
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi,

I am using a lightning:datatable to display data-
 <lightning:datatable columns="{!v.columns}"
                             data="{!v.data}"
                             keyField="id"
                             errors="{!v.errors}"
                             show-row-number-column= "true"  
                             onrowselection="{! c.getSelectedRow}"/>

Using a button to validate the data before it gets updated in salesforce.
Sending a response back to helper in Map<Id, String> -

response- {"a1Fn00000007AEpEAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AEoEAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AF9EAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AF8EAM":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AFTEA2":"This contact is already assigned as an Emergency Contact, choose a different contact and save","a1Fn00000007AFSEA2":"This contact is already assigned as an Emergency Contact, choose a different contact and save"}

As per lightning documentation, lightning:datatable attribute error shoudl be set in following format-
cmp.set('v.errors',
{ rows:
{ b:
{ title: 'We found 2 errors.',
messages: [ 'Enter a valid amount.', 'Verify the email address and try again.' ],
fieldNames: ['amount', 'contact'] }
},
table:
{ title: 'Your entry cannot be saved. Fix the errors and try again.', messages: [ 'Row 2 amount must be number', 'Row 2 email is invalid' ]
}
});

I am not sure how to iterate over a map to set error attribute in this format. Any help will be appreciated.
Hi All,

I am trying to create a simple calculator performing total = quantity * price. But my method written in controller is not getting called. ANy help would be appreciated.

visualforce code-

<apex:page id="ProductCalculator" controller="ProductCalculator">
  <apex:pageBlock id="pbProdCalc">
      <apex:form id="fProdCalc">
          <apex:dataTable id="dtProdCalc" columns="4" value="{!Products}" var="con" styleclass="list">
              <apex:column id="prodList" headerValue="Product">
                  <apex:selectList id="slProdList" value="{!product}" size="1" multiselect="false">
                      <apex:selectOptions id="soProdList" value="{!items}"/>
                  </apex:selectList>
              </apex:column>
              <apex:column id="prodQuantity" headerValue="Quantity">
                     <apex:inputText id="Qty" value="{!quantity}"/>
              </apex:column>
              <apex:column id="prodPrice" headerValue="Price">
                  <apex:inputText id="Price" value="{!prodPrice}">
                      <apex:actionSupport action="{!calculateTotal}" event="onchange" reRender="Total"/>
                  </apex:inputText>
              </apex:column>
              <apex:column id="prodTotal" headerValue="Total">
                  <apex:outputText id="Total" value="{!prodTotal}"/>
              </apex:column>
          </apex:dataTable>
      </apex:form>
  </apex:pageBlock>
</apex:page>

Controller code-

public class ProductCalculator {

    Integer qty; Integer price; Integer total;
   
    public PageReference calculateTotal() {
        system.debug('calculate total called' );
        calcTotal();
        return null;
    }  
   
    public Integer calcTotal()
    {
        total = qty * price;
        system.debug('total is: ' + total);
        return total;
    }
  
    public Integer getQuantity() {
        return qty;
    }
   
    public void setQuantity(Integer q) {
       qty = q;
    }
   
     public Integer getProdPrice() {
        return price;
    }
   
    public void setProdPrice(Integer p)
    {
        price = p;
    }
   
     public Integer getProdTotal() {
        return total;
    }
   
    public void setProdTotal(Integer t)
    {
        total = t;
    }
   
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Product1','Product 1'));
        options.add(new SelectOption('Product2','Product 2'));
        options.add(new SelectOption('Product3','Product 3'));
        return options;
    }

  
    String[] prod = new String[]{};
  
    public String[] getProduct() {
        return prod;
    }
   
    public void setProduct(String[] prod)
    {
        this.prod = prod;
    }

    String ProductType;
    List<Product2> products;
   
    public List<Product2> getProducts() {
        if(products == null)
            products = [select id, name from Product2 Limit 1];
        return products;
    }

}

Hi All,

I am trying to create a simple calculator performing total = quantity * price. But my method written in controller is not getting called. ANy help would be appreciated.

visualforce code-

<apex:page id="ProductCalculator" controller="ProductCalculator">
  <apex:pageBlock id="pbProdCalc">
      <apex:form id="fProdCalc">
          <apex:dataTable id="dtProdCalc" columns="4" value="{!Products}" var="con" styleclass="list">
              <apex:column id="prodList" headerValue="Product">
                  <apex:selectList id="slProdList" value="{!product}" size="1" multiselect="false">
                      <apex:selectOptions id="soProdList" value="{!items}"/>
                  </apex:selectList>
              </apex:column>
              <apex:column id="prodQuantity" headerValue="Quantity">
                     <apex:inputText id="Qty" value="{!quantity}"/>
              </apex:column>
              <apex:column id="prodPrice" headerValue="Price">
                  <apex:inputText id="Price" value="{!prodPrice}">
                      <apex:actionSupport action="{!calculateTotal}" event="onchange" reRender="Total"/>
                  </apex:inputText>
              </apex:column>
              <apex:column id="prodTotal" headerValue="Total">
                  <apex:outputText id="Total" value="{!prodTotal}"/>
              </apex:column>
          </apex:dataTable>
      </apex:form>
  </apex:pageBlock>
</apex:page>

Controller code-

public class ProductCalculator {

    Integer qty; Integer price; Integer total;
   
    public PageReference calculateTotal() {
        system.debug('calculate total called' );
        calcTotal();
        return null;
    }  
   
    public Integer calcTotal()
    {
        total = qty * price;
        system.debug('total is: ' + total);
        return total;
    }
  
    public Integer getQuantity() {
        return qty;
    }
   
    public void setQuantity(Integer q) {
       qty = q;
    }
   
     public Integer getProdPrice() {
        return price;
    }
   
    public void setProdPrice(Integer p)
    {
        price = p;
    }
   
     public Integer getProdTotal() {
        return total;
    }
   
    public void setProdTotal(Integer t)
    {
        total = t;
    }
   
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Product1','Product 1'));
        options.add(new SelectOption('Product2','Product 2'));
        options.add(new SelectOption('Product3','Product 3'));
        return options;
    }

  
    String[] prod = new String[]{};
  
    public String[] getProduct() {
        return prod;
    }
   
    public void setProduct(String[] prod)
    {
        this.prod = prod;
    }

    String ProductType;
    List<Product2> products;
   
    public List<Product2> getProducts() {
        if(products == null)
            products = [select id, name from Product2 Limit 1];
        return products;
    }

}