• Aditi Mohanty 5
  • NEWBIE
  • 30 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 18
    Replies
User-added imageWhen I click on "add to cart" the action history column should show "product added to cart" and same for "buy" button
Controller--
({
	doinit : function(component) {
       component.set( 'v.cols' , [
            {
                label: 'Name',
                fieldName: 'Name',
                type: 'text'
            },
           {
                'label': 'Price',
                'fieldName': 'Unitprice',
                'type': 'Currency'
            },
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Add to Cart',
                    'name': 'add to cart'
                }
            },
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Buy',
                    'name':'buy'
                    
                }
            },
           { 'label': 'action history',
                'fieldName': 'action history',
                'type': 'text',
            	'value':'Edit'
           }
            ]);
        
  var action = component.get("c.getproduct"); 
       
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
        if (state === "SUCCESS") {
            var records = actionResult.getReturnValue();
            for (var i = 0; i < records.length; i++) {
				 records[i].Name = records[i].Product2.Name;
                records[i].Unitprice= records[i].UnitPrice;
            }
             component.set("v.productname", records);
            
          
        }
            });
          $A.enqueueAction(action);
    },
    onRowAction:function(component, event, helper) {
        var act = component.get("c.sendmail");
        var getEmail = component.get("v.address");
       var records = actionResult.getReturnValue();
       act.setParams({
            'mMail': getEmail,});
var actionName = event.getParam('action').name;
        if(actionName=='add to cart'){
    alert("product added to cart");
        }
        if(actionName=='buy'){
        alert("product will be delivered"); 
            act.setCallback(this, function(response) {
                var state = response.getState();
                    if (state === "SUCCESS") {
                      response.getReturnValue();                   
                    }  });
      }
$A.enqueueAction(act);             
}
})

Component--
<aura:component controller="products" > 
<aura:attribute name="productname" type="List"/>
<aura:attribute name="cols" type="List"/> 
    <aura:attribute name="address" type="string"/>
   <aura:attribute name="subject" type="string"/>
   
   <aura:attribute name="mailStatus" type="boolean" default="false"/>
   
<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
<lightning:datatable
            data="{!v.productname}"
        	columns="{!v.cols}"
            keyField="Id"
            onrowaction="{!c.onRowAction}"/>
   
       
</aura:component> 

apex code--
global with sharing class products {
    @AuraEnabled
    public static List<PricebookEntry> getproduct() {
List<PricebookEntry> prod= [SELECT Product2.Name, Unitprice FROM PricebookEntry];
return prod;

    }
     @AuraEnabled
      public static void sendmail(String address, String subject, String body) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'mohantyniki23@gmail.com'};
        mail.setToAddresses(toAddresses);
          String message = 'Thank you choosing our service.Your package will be delivered in 5 days.';
        mail.setSubject('Order confirmation');
        mail.setPlainTextBody(message);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 
global with sharing class products {
    @AuraEnabled
    public static List<PricebookEntry> getproduct() {

   List<PricebookEntry> prod= [SELECT Product2.Name, Unitprice FROM PricebookEntry];
  return prod;

    }
}

component--
<aura:component controller="products" > 
<aura:attribute name="productname" type="PricebookEntry[]"/>
<aura:attribute name="cols" type="List"/>  
     
    <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
   
    <lightning:datatable
            data="{!v.productname}"
            columns="{!v.cols}"
            keyField="Id"
            onrowaction="{!c.onRowAction}"/>
   
       
</aura:component>

controller---
({
	doinit : function(component) {
       component.set( 'v.cols' , [
            {
                'label': 'Name',
                'fieldName': 'Name',
                'type': 'text'
            },
{label': 'Price',
                'fieldName': 'Price',
                'type': 'Currency'
},
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Add to Cart',
                    'name': 'view_details'
                }
            },
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Buy',
                    'name': 'view_details'
                }
            }
            ]);
        
  var action = component.get("c.getproduct"); 
        // var self = this;
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
        if (state === "SUCCESS") {
          component.set("v.productname", actionResult.getReturnValue());
            component.set("v.productprice",actionResult.getReturnValue());
        }
            });
          $A.enqueueAction(action);
    },
		
	
})

Name and price of the products is not showing in datatable, but soql is executing successfully. What to do?
public class postalcode {
    @AuraEnabled
    public static List<Object> call(String p)
    {
        List<object> post=new List<object>();
        
        String s='';
        List<Object> office=new List<Object>();
        List<String> name=new List<String>();
        object o;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.postalpincode.in/pincode/'+p);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        if (response.getStatusCode() == 200) {
           
			List<Object> lst_JsonParse = (List<Object>)Json.deserializeUntyped(response.getBody());
            
            for(Object obj : lst_JsonParse)
             {
                 Map<String,Object> mp_StrObj = (Map<string,Object>)obj;
                office=(List<object>)mp_StrObj.get('PostOffice');
        
            }
            for(object o2:office){
                map<String,object> fin=(Map<String,Object>)o2;
               	String a=(String)fin.get('Name');
                name.add(a);
                System.debug(a);
            }

        }
        return office;
    }
}

 

global class Batch_AddConToAcc implements Database.Batchable <sObject>,Database.Stateful,Database.AllowsCallouts {
     
     public List<String> nam=new List<String>();
     public Integer processedrecord=0;
    public String exp;
   String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True';
    global Database.QueryLocator start(Database.BatchableContext bc) {
         
        return Database.getQueryLocator(query);
    }

    global  void execute(Database.BatchableContext bc,List<Account> batch) {
       List<Account> acnt=new List<Account>();
        List<contact> lstCon = new List<Contact>();
        for (Account a : batch) {
           
            Contact c =  new Contact();
            c.LastName = a.Name;
        c.AccountId = a.Id;
            lstCon.add(c);
            a.checkacc__c = False;  
            acnt.add(a);
            processedrecord=processedrecord+1;
            nam.add(a.Name);
        }
        try{
         
       INSERT lstCon;
      
    }
        catch(Exception e){
            exp= e.getMessage();
        }
 update acnt;
        
        }
    
    global void finish(Database.BatchableContext bc) {
     

AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :bc.getJobId()];
 EmailUtility.sendSimpleEmail(ajob.Status,processedrecord,nam,exp);      
        
        
      
        }     
       
    }
global class Batch_AddConToAcc implements Database.Batchable <sObject>,Database.Stateful,Database.AllowsCallouts {
     
     public List<String> nam=new List<String>();
     public Integer processedrecord=0;
    public String exp;
   String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True';
    global Database.QueryLocator start(Database.BatchableContext bc) {
         
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext bc,List<Account> batch) {
       List<Account> acnt=new List<Account>();
        List<contact> lstCon = new List<Contact>();
        for (Account a : batch) {
           
            Contact c =  new Contact();
            c.LastName = a.Name;
        c.AccountId = a.Id;
            lstCon.add(c);
            a.checkacc__c = False;  
            acnt.add(a);
            processedrecord=processedrecord+1;
            nam.add(a.Name);
        }
        try{
        INSERT lstCon;
    }
        catch(Exception e){
            exp= e.getMessage();
        }
 update acnt;
        
        }
    
    global void finish(Database.BatchableContext bc) {
     

AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :bc.getJobId()];
 EmailUtility.sendSimpleEmail(ajob.Status,processedrecord,nam,exp);      
        
        
      
        }     
       
    }

 
global class Batch_AddConToAcc implements Database.Batchable <sObject>,Database.Stateful {
     
    
   String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True';
    global Database.QueryLocator start(Database.BatchableContext bc) {
         
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext bc,List<Account> batch) {
       List<Account> acnt=new List<Account>();
        List<contact> lstCon = new List<Contact>();
        for (Account a : batch) {
           
            Contact c =  new Contact();
            c.LastName = a.Name;
        
            lstCon.add(c);
            a.checkacc__c = False;  
            acnt.add(a);
          
        }
        
        INSERT lstCon;
       update acnt;
        
        }
    
    global void finish(Database.BatchableContext bc) {
     

AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :bc.getJobId()];
 EmailUtility.sendSimpleEmail(ajob.Status);      
        
        
     
        }     
       
    }

 
global class Batch_AddConToAcc implements Database.Batchable <sObject> {
     
    List<contact> lstCon = new List<Contact>();
   String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True';
    global Database.QueryLocator start(Database.BatchableContext bc) {
         
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext bc,List<Account> batch) {
       List<Account> acnt=new List<Account>();
        for (Account a : batch) {
            if(a.checkacc__c = True){
            Contact c =  new Contact();
            c.LastName = a.Name;
            c.AccountId = a.Id;
            lstCon.add(c);
        }
        INSERT lstCon;
        }
        for (Account a : batch){
          a.checkacc__c = False;  
            acnt.add(a);
        } 
        update acnt;
        
    }
    
    global void finish(Database.BatchableContext bc) {
     

AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :bc.getJobId()];
        if(ajob.Status=='Completed'){
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {ajob.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + ajob.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + ajob.TotalJobItems +
   ' batches status '+ajob.Status );
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
            
            else{
                
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {ajob.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + ajob.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + ajob.TotalJobItems +
   ' batches with '+ ajob.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                
            }
        }     
       
    }

 
public class leadConvert {
    @AuraEnabled
    public static id saveData(Account acc)
    {
        insert acc;
        return acc.id;
    }
     @AuraEnabled
     public static Map<id,string> getUserAccessPicklist()
     {
        Map<Id,Account> use=new Map<id,Account>([select id, name from Account]);
        Map<id,string> userId=new Map<id,string>();
        for(Account u:use.values())
        {
            userId.put(u.id,u.name);
        }
        return userId;
     }
    @AuraEnabled
     public static Map<id,string> getContactAccessPicklist()
     {
        Map<Id,Contact> use=new Map<id,Contact>([select id, Name from Contact]);
        Map<id,string> userId=new Map<id,string>();
        for(Contact u:use.values())
        {
            userId.put(u.id,u.name);
        }
        return userId;
     }
    @AuraEnabled
     public static Map<id,string> getOpportunityAccessPicklist()
     {
        Map<Id,Opportunity> use=new Map<id,Opportunity>([select id, name from Opportunity]);
        Map<id,string> userId=new Map<id,string>();
        for(Opportunity u:use.values())
        {
            userId.put(u.id,u.name);
        }
        return userId;
     }
    @AuraEnabled
    public static void savecontactData(Contact con)
    {
        insert con;
    }
    @AuraEnabled
    public static void saveopportunityData(Opportunity opp)
    {
        insert opp;
    }
    @AuraEnabled
    public static Lead getdata(Id recordId)
    {
        Lead acc=[SELECT Id, LastName, FirstName, Name, Title, Company, Phone, LeadSource, Status, ConvertedAccountId, ConvertedContactId, ConvertedOpportunityId FROM Lead where Id=:recordId];    
        return acc;
    }
    @AuraEnabled
    public static id updateLead(Lead lea)
    {
        update lea;
        return lea.id;
    }
    @AuraEnabled
    public static void convertLead(id lId,string arr1,string arr2,string arr3)
    {
        
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(lId);
        if(arr1<>'-1')
        {
            Id newId1 = Id.valueOf(arr1);
            lc.setAccountId(newId1);
        }
        if(arr2<>'-1')
        {
            Id newId2 = Id.valueOf(arr2);
            lc.setContactId(newId2);
        }
        if(arr3<>'-1')
        {
            Id newId3 = Id.valueOf(arr3);
            lc.setOpportunityId(newId3);
        }
        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
         
        Database.LeadConvertResult lcr = Database.convertLead(lc);
    }
}
User-added imageUser-added imageUser-added imageLead is successfully converted is showing but not converting.
User-added imageUser-added imageUser-added imageLead is successfully converted is showing but not converting.
User-added imageWhen I click on "add to cart" the action history column should show "product added to cart" and same for "buy" button
Controller--
({
	doinit : function(component) {
       component.set( 'v.cols' , [
            {
                label: 'Name',
                fieldName: 'Name',
                type: 'text'
            },
           {
                'label': 'Price',
                'fieldName': 'Unitprice',
                'type': 'Currency'
            },
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Add to Cart',
                    'name': 'add to cart'
                }
            },
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Buy',
                    'name':'buy'
                    
                }
            },
           { 'label': 'action history',
                'fieldName': 'action history',
                'type': 'text',
            	'value':'Edit'
           }
            ]);
        
  var action = component.get("c.getproduct"); 
       
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
        if (state === "SUCCESS") {
            var records = actionResult.getReturnValue();
            for (var i = 0; i < records.length; i++) {
				 records[i].Name = records[i].Product2.Name;
                records[i].Unitprice= records[i].UnitPrice;
            }
             component.set("v.productname", records);
            
          
        }
            });
          $A.enqueueAction(action);
    },
    onRowAction:function(component, event, helper) {
        var act = component.get("c.sendmail");
        var getEmail = component.get("v.address");
       var records = actionResult.getReturnValue();
       act.setParams({
            'mMail': getEmail,});
var actionName = event.getParam('action').name;
        if(actionName=='add to cart'){
    alert("product added to cart");
        }
        if(actionName=='buy'){
        alert("product will be delivered"); 
            act.setCallback(this, function(response) {
                var state = response.getState();
                    if (state === "SUCCESS") {
                      response.getReturnValue();                   
                    }  });
      }
$A.enqueueAction(act);             
}
})

Component--
<aura:component controller="products" > 
<aura:attribute name="productname" type="List"/>
<aura:attribute name="cols" type="List"/> 
    <aura:attribute name="address" type="string"/>
   <aura:attribute name="subject" type="string"/>
   
   <aura:attribute name="mailStatus" type="boolean" default="false"/>
   
<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
<lightning:datatable
            data="{!v.productname}"
        	columns="{!v.cols}"
            keyField="Id"
            onrowaction="{!c.onRowAction}"/>
   
       
</aura:component> 

apex code--
global with sharing class products {
    @AuraEnabled
    public static List<PricebookEntry> getproduct() {
List<PricebookEntry> prod= [SELECT Product2.Name, Unitprice FROM PricebookEntry];
return prod;

    }
     @AuraEnabled
      public static void sendmail(String address, String subject, String body) {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {'mohantyniki23@gmail.com'};
        mail.setToAddresses(toAddresses);
          String message = 'Thank you choosing our service.Your package will be delivered in 5 days.';
        mail.setSubject('Order confirmation');
        mail.setPlainTextBody(message);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 
global with sharing class products {
    @AuraEnabled
    public static List<PricebookEntry> getproduct() {

   List<PricebookEntry> prod= [SELECT Product2.Name, Unitprice FROM PricebookEntry];
  return prod;

    }
}

component--
<aura:component controller="products" > 
<aura:attribute name="productname" type="PricebookEntry[]"/>
<aura:attribute name="cols" type="List"/>  
     
    <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>
   
    <lightning:datatable
            data="{!v.productname}"
            columns="{!v.cols}"
            keyField="Id"
            onrowaction="{!c.onRowAction}"/>
   
       
</aura:component>

controller---
({
	doinit : function(component) {
       component.set( 'v.cols' , [
            {
                'label': 'Name',
                'fieldName': 'Name',
                'type': 'text'
            },
{label': 'Price',
                'fieldName': 'Price',
                'type': 'Currency'
},
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Add to Cart',
                    'name': 'view_details'
                }
            },
            {
                'label': 'Action',
                'type': 'button',
                'typeAttributes': {
                    'label': 'Buy',
                    'name': 'view_details'
                }
            }
            ]);
        
  var action = component.get("c.getproduct"); 
        // var self = this;
        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
        if (state === "SUCCESS") {
          component.set("v.productname", actionResult.getReturnValue());
            component.set("v.productprice",actionResult.getReturnValue());
        }
            });
          $A.enqueueAction(action);
    },
		
	
})

Name and price of the products is not showing in datatable, but soql is executing successfully. What to do?
public class postalcode {
    @AuraEnabled
    public static List<Object> call(String p)
    {
        List<object> post=new List<object>();
        
        String s='';
        List<Object> office=new List<Object>();
        List<String> name=new List<String>();
        object o;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.postalpincode.in/pincode/'+p);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        if (response.getStatusCode() == 200) {
           
			List<Object> lst_JsonParse = (List<Object>)Json.deserializeUntyped(response.getBody());
            
            for(Object obj : lst_JsonParse)
             {
                 Map<String,Object> mp_StrObj = (Map<string,Object>)obj;
                office=(List<object>)mp_StrObj.get('PostOffice');
        
            }
            for(object o2:office){
                map<String,object> fin=(Map<String,Object>)o2;
               	String a=(String)fin.get('Name');
                name.add(a);
                System.debug(a);
            }

        }
        return office;
    }
}

 
global class Batch_AddConToAcc implements Database.Batchable <sObject>,Database.Stateful,Database.AllowsCallouts {
     
     public List<String> nam=new List<String>();
     public Integer processedrecord=0;
    public String exp;
   String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True';
    global Database.QueryLocator start(Database.BatchableContext bc) {
         
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext bc,List<Account> batch) {
       List<Account> acnt=new List<Account>();
        List<contact> lstCon = new List<Contact>();
        for (Account a : batch) {
           
            Contact c =  new Contact();
            c.LastName = a.Name;
        c.AccountId = a.Id;
            lstCon.add(c);
            a.checkacc__c = False;  
            acnt.add(a);
            processedrecord=processedrecord+1;
            nam.add(a.Name);
        }
        try{
        INSERT lstCon;
    }
        catch(Exception e){
            exp= e.getMessage();
        }
 update acnt;
        
        }
    
    global void finish(Database.BatchableContext bc) {
     

AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :bc.getJobId()];
 EmailUtility.sendSimpleEmail(ajob.Status,processedrecord,nam,exp);      
        
        
      
        }     
       
    }

 
global class Batch_AddConToAcc implements Database.Batchable <sObject> {
     
    List<contact> lstCon = new List<Contact>();
   String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True';
    global Database.QueryLocator start(Database.BatchableContext bc) {
         
        return Database.getQueryLocator(query);
    }
 
    global void execute(Database.BatchableContext bc,List<Account> batch) {
       List<Account> acnt=new List<Account>();
        for (Account a : batch) {
            if(a.checkacc__c = True){
            Contact c =  new Contact();
            c.LastName = a.Name;
            c.AccountId = a.Id;
            lstCon.add(c);
        }
        INSERT lstCon;
        }
        for (Account a : batch){
          a.checkacc__c = False;  
            acnt.add(a);
        } 
        update acnt;
        
    }
    
    global void finish(Database.BatchableContext bc) {
     

AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :bc.getJobId()];
        if(ajob.Status=='Completed'){
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {ajob.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + ajob.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + ajob.TotalJobItems +
   ' batches status '+ajob.Status );
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            }
            
            else{
                
    
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   String[] toAddresses = new String[] {ajob.CreatedBy.Email};
   mail.setToAddresses(toAddresses);
   mail.setSubject('Apex Sharing Recalculation ' + ajob.Status);
   mail.setPlainTextBody
   ('The batch Apex job processed ' + ajob.TotalJobItems +
   ' batches with '+ ajob.NumberOfErrors + ' failures.');
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                
            }
        }     
       
    }

 
User-added imageUser-added imageUser-added imageLead is successfully converted is showing but not converting.