• Sid Lightning
  • NEWBIE
  • 50 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 41
    Questions
  • 48
    Replies

Hi,

i have to Count number of user logins for a Salesforce license in last 7 days and last 30 days in 2 seperate fields  and use it in a salesforce report.

Please note that, I don't need a reporting filter , i want a code, which counts the number of users who have logged in last 7/30 days and store it in 2 seperate fields

Hi,

I have a custom lightning page,
There are set of opportunity products, which gets added as a record. Every record has a picklist value.

But in the event of 100 products, i need to manually go and set the picklist value, even if they are same.

What i want is, if i can have a checkbox at the lightning component, which when checked, will populate the same picklist value as selected on the first record, and still allows the user to change the picklist value for records he wants to.

This way it will be easier for him
Hi,

I want to write a batch class to execute the below function.

Objects Involved: Opportunity, Estimations, Orders, BRT, Achievements

Estimations and orders are child of opportunity
Achievements is child to BRT
Both look up to Business and Location ( separate custom objects)

BRT and Opportunity are unrelated



Unique Key on Opportunity is  Year-Month-Location-Business, same is the unique key on BRT

When the opportunity is closed won and if the unique key on opportunity matches with a unique key on BRT(master table). I want a class to run, that  creates a record in the achievement object(child to BRT)

Records captured at Achievement are

1) Opportunity: Opportunity Name
2) Opportunity: Created Date
3) Opportunity: Closed Won Date
4) Order: Order lookup( Order lookups to opportunity) 
5) Order: Order amount
6) Order: Billed Date
7) Estimations: Estimation Amount
8) Estimations: Month
9) Estimations: Start Date
10) BRT:  Targets

BRT being parent of Achievements, a lookup will be present, also I want to order no. to populated in order lookup provided at Achievements object.

Also if we have to provide estimations and opportunity lookup , its no problem.
since one opportunity can have multiple orders
Hi,

I need help in writting test class for below written batch class.

Can anyone help please?

global class UpdateCurrentMonth implements Database.Batchable<sObject>,Schedulable, Database.stateful
{

  global void execute(SchedulableContext sc)
    {
        
    }


   global Database.queryLocator start(Database.BatchableContext BC )
   {
        String str = 'SELECT Id, Start_Date__c,End_Date__c,Current_Month__c FROM Business_Re_development_Target__c';
        return Database.getQueryLocator(str);
        
   }
    
    global void execute(Database.BatchableContext BC, List<Business_Re_development_Target__c> BRTToProcess)
     {
     List<Business_Re_development_Target__c> BRTList = new List<Business_Re_development_Target__c>();
       for(Business_Re_development_Target__c BRTObj : BRTToProcess){
       
       If(Date.Today().Year()  == BRTObj.End_Date__c.Year()){
      
       If(Date.Today().Month()  > BRTObj.End_Date__c.month())
       {
       
               BRTObj.Current_Month__c = False;
            BRTList.add(BRTObj);
            }            
            }
        
        else
         
       If(Date.Today().Year() > BRTObj.End_Date__c.Year()){
      
       If(Date.Today().Month()  < BRTObj.End_Date__c.month())
       {
       
               BRTObj.Current_Month__c = False;
            BRTList.add(BRTObj);
            }            
            }
               
            
          }
        update BRTList;
        }
   global void finish(Database.BatchableContext BC)
    {
   system.debug('finish');     
    }    
}
    
     

    
Hi,

I have a Lightning page to add products on opportunity and Deals(custom object)

However, when selecting multiple products, the user often faces challenges in filling adjacent fields for that product, since attributes remain the same.

Can I provide a checkbox(select all), that automatically copies the picklist value of the first product of all the products?
Hi,

Currently I am making an apex callout to external system using a lightning component button,

It generates an external system id ( CustomerId)

As a part of my requirement, when I change Account - Name, GST, PAN and email it should go to the external system only if CustomerId is present on account.

It should update the same external id in external system

I understand, I will require a REST API integration to make this update call. can anyone help me in this







 
Hi, 

I need help in writting test class for this batch class, It deletes opportunity if the custom record(child to Opportunity) is not present.

Opportunity is child to Account.

Please find the codee

global class OpportunityDeleteBatch implements Database.Batchable<sObject>,Schedulable{
    
    global void execute(SchedulableContext sc){
        OpportunityDeleteBatch bc = new OpportunityDeleteBatch();
        database.executeBatch(bc);
    }
    global Database.QueryLocator start(Database.BatchableContext bc){
        return database.getQueryLocator([Select Id, Name From Opportunity WHERE RecordType.Name= 'Retail - FR' AND ID NOT IN ( Select Opportunity__c from Product_Interest__c)]);
    }
    global void execute(Database.BatchableContext bc,List<Opportunity> opp){
        if(!opp.isEmpty()){
            database.delete(opp,false);
        }
    }
    global void finish(Database.BatchableContext bc){
        
    }

}



 
Hi,

I have a custom object called PI (child to opportunity), which picks price from pricebook entry.

Now, when a PI is created price gets stamped and wont be revised even if the price in pricebook entry changes.

Price in pricebook entry gets updated from SAP via batch class every morning.

I want to write a batch class which checks, if the price of the product in PI to new price of the product in Pricebook entry ( if any updates)

If the price in Pricebook entry is lower than price in PI, i want to trigger a mail to mail-id specified in Opportunity.


The business rationale is to notify customer about downward revision in price, which can facilitate the deal
 
Hi,

I have an order object, it has 2 childs, NPS and Cases

On NPS, I have a lookup to cases. but both gets filled seperately

What I really want is, When  NPS rating is "4" on NPS. It should set the status close on all cases with "Type" NPS 4 

Point to remember is there can be multiple cases with this type

NPS rating --- > 4

Cases - type -(NPS4) ---- > Status = Closed

Can somebody help me in writting trigger and test class for the same

Hi,

I have an apex class method already written which gets called by a button in background,
 

I want a button on Accounts screen, which can call that lightning component and inturn the apex method.

So, I want a button on Accounts screen, which calls a component that calls the method written in Apex class.
Since the method makes the API call, do I need to write some extra code? Since the functionality for API is already written.


 

Hi,

I have a custom object as child to opportunity object. 

I want to delete opportuntity every night, when all the child records for it is 0.

I want to write a batch apex(schedulable), which deletes all such records at 12:00 in the night.

So lets say,

If an opportunity has 2 child records, and the Grand Total value on both child records is 0, I want to delete the opportunity along with its child record.

It should only happen, when both child records value is 0. In case where the child record value is there for one of the childs.. it shouldnt get deleted
The trigger automatically attaches pricebooks, when a produt get created. which pricebook it should attach depends upon the LOB

public class ProductTriggerHandler extends TriggerHandler{
    public ProductTriggerHandler() {
    }
    
    public override void afterUpdate() {
        System.debug('this is after update');
        
    }   
    
    public override void beforeUpdate() {
        
        
        
    }
    
    public override void beforeInsert() {
        
    }
    
    public override void afterInsert() {
        System.debug('this is after insert');
        createPricebookEntries((List<Product2>)Trigger.new);        
    }    
    
    public void createPricebookEntries(List<Product2> productList){
        
        List<PricebookEntry> peList = new List<PricebookEntry>();
        List<PricebookEntry> mpeList = new List<PricebookEntry>(); //For Modular Kitchen
        List<PricebookEntry> opeList = new List<PricebookEntry>(); // For All other LOB
        
       
        List<Pricebook2> pricebookIds = [Select id,Site_Code__c from Pricebook2 where Pricebook_Category__c ='FR']; // Fetches only Furniture Pricebook
        List<Pricebook2> MKpricebookIds = [Select id,Site_Code__c from Pricebook2 where Pricebook_Category__c ='MK' OR IsStandard = TRUE]; // Fethches only MK Pricebook and Standard Pricebook
        List<Pricebook2> opricebookIds = [Select id,Site_Code__c from Pricebook2 where IsStandard = TRUE]; // Fetches only Standard Pricebook
           
   
 // Attaching Standard Pricebook and Furniture Pricebooks when LOB is Furniture, Home Improvement , Home Improvements
        
        if(pricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
                if(prod.LOB__c!=null && Label.FR_Pricebook.contains(prod.LOB__c)){
                    for(Pricebook2 pb2 : pricebookIds){
                        PricebookEntry pe = new PricebookEntry();
                        pe.UnitPrice = 1;
                        pe.Pricebook2Id = pb2.id;
                        pe.Product2Id = prod.id;
                        peList.add(pe);
                    }
                    
                }
            }
            
         
            
            
            if(peList.size()>0){
                insert peList;
                System.debug('id:'+peList[0].id);
            }
        }
        
 // Attaches Standard pricebook to all products whose LOB is not Furniture, Modular Kitchen, Mk , Home Improvement,Home Improvements       
      
      if(opricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
if(prod.LOB__c!=null && Label.Other_Pricebooks.contains(prod.LOB__c)){
                    for(Pricebook2 opb2 : opricebookIds){
                        PricebookEntry ope = new PricebookEntry();
                        ope.UnitPrice = 1;
                        ope.Pricebook2Id = opb2.id;
                        ope.Product2Id = prod.id;
                        opeList.add(ope);
                    }
                    
                }
            }
            
         
            
            
            if(opeList.size()>0){
                insert opeList;
                System.debug('id:'+opeList[0].id);
            }
        }
        
        
        
// Attaching Standard Pricebook and Modular Kitchen Pricebook when LOB is Modular Kitchen or MK    
        
           if(MKpricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
                if(prod.LOB__c == 'Modular Kitchen' || prod.LOB__c == 'MK'){
                    for(Pricebook2 mpb2 : mkpricebookIds){
                        PricebookEntry mpe = new PricebookEntry();
                        mpe.UnitPrice = 1;
                        mpe.Pricebook2Id = mpb2.id;
                        mpe.Product2Id = prod.id;
                        mpeList.add(mpe);
                    }
                    
                }
            }
            
         
            
            
            if(mpeList.size()>0){
                insert mpeList;
                System.debug('id:'+mpeList[0].id);
            }
        }
    }
    
}
Hi,

I want to save attachement of the email template that gets sent via batch apex to the user email.

I want to save it under Attachements under Opportunities, can someone suggest how can I do this 

Hi,
I have a test class that deletes custom object record  at the end of day if the value of Grand Total field is 0.

Grand Total field is a roll up field, and is calculated basis the line item value.

Here is my batch class.

global class ProductInterestDeleteBatch implements Database.Batchable<sObject>,Schedulable{
    
    global void execute(SchedulableContext sc){
        ProductInterestDeleteBatch bc = new ProductInterestDeleteBatch();
        database.executeBatch(bc);
    }
    global Database.QueryLocator start(Database.BatchableContext bc){
        return database.getQueryLocator([SELECT Id FROM Product_Interest__c WHERE Grand_Total__c=0]);
    }
    global void execute(Database.BatchableContext bc,List<Product_Interest__c> productInterestList){
        if(!productInterestList.isEmpty()){
            database.delete(productInterestList,false);
        }
    }
    global void finish(Database.BatchableContext bc){
        
    }

}



I need help in writting test class for the same.

Hi,

 want to create a save button on lightning component for my object Shipping Address which is child to parent Account.

There are 6 fields in shipping address, I want those fields to get saved and displayed on the lightning component 

I am tricked about how do i save it into database and get it displayed on my screen.

Here is my code

Apex:
1public class InsertAndDisplayC {
2     
3    @AuraEnabled
4    public static Id saveDetails(Contact con){
5        // DML operation to save Contact Details  
6        INSERT con;
7        return con.Id;
8    }
9}
Component:
01<aura:component controller="InsertAndDisplayC"
02                implements="lightning:isUrlAddressable,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
03     
04    <aura:attribute name="PageHeading" type="String" default="Create and Display Contacts"/>
05    <aura:attribute name="RegForm" type="Contact" default="{'sobjectType' : 'Contact'}"/>
06    <aura:attribute name="showDetails" type="boolean" default="false" />
07     
08    <div class="slds-m-top--xx-large">
09        <div class="slds-page-header">
10            <div class="slds-align--absolute-center">
11                <div class="slds-text-heading--large">      
12                    {!v.PageHeading}
13                </div>
14            </div>
15        </div>
16    </div>
17    <br/> <br/>
18     
19    <div class = "slds-size--3-of-8">
20        <lightning:input label="Enter First Name" name="fname" value="{!v.RegForm.FirstName}"/>
21        <br/>
22        <lightning:input label="Enter Last Name" name="lname" value="{!v.RegForm.LastName}"/>
23        <br/>
24        <lightning:input label="Enter Phone" name="phone" value="{!v.RegForm.Phone}"/>
25        <br/>
26        <lightning:input label="Enter Email" name="email" value="{!v.RegForm.Email}"/>
27        <br/>
28        <lightning:button label="Submit" onclick="{!c.doSubmit}"/>
29    </div>
30    <br/>
31    <aura:if isTrue="{!v.showDetails}">
32        <div class = "slds-size--3-of-8">
33            <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Contact">
34                <div class="slds-box">
35                    <lightning:outputField fieldName="Name" />
36                    <lightning:outputField fieldName="Phone" />
37                    <lightning:outputField fieldName="Email" />
38                </div>
39            </lightning:recordViewForm>
40        </div>
41    </aura:if>
42</aura:component>
Controller:
01({
02    doSubmit : function(component, event, helper) {
03        var regForm = component.get("v.RegForm");
04        var action = component.get("c.saveDetails");
05        action.setParams({con  : regForm});
06        action.setCallback(this, function(response) {
07            var state = response.getState();         
08            if (state === "SUCCESS") {
09                var res = response.getReturnValue();
10                component.set('v.recordId',res);
11                component.set("v.showDetails", true);
12                alert('Successfully Saved' + res);
13                component.set('v.RegForm','');
14            }
15            else if (state === "ERROR") {
16                var errors = response.getError();
17                if (errors) {
18                    if (errors[0] && errors[0].message) {
19                        console.log("Error message: " +
20                                    errors[0].message);
21                    }
22                }
23                else {
24                    console.log(response.getReturnValue());
25                }
26            }
27        });
28        $A.enqueueAction(action);
29    },
30})
CSS:
01.THIS {
02 
03}
04 
05.THIS.slds-size--3-of-8 {
06     
07    margin-left: 430px;
08}
09 
10.THIS label.slds-form-element__label{
11     
12    font-size: 1.00rem;
13    color: blue;
14}
Application:
view sourceprint?
1<aura:application extends="force:slds">
2    <c:InsertAndDisplay/>
3</aura:application>
Hi,

I have a logic , when marks a checkbox to be TRUE. basis which the mail gets sent to customer.

However for reporting purpose , I need to know on which ids the mail got sent .

Is there any way?
Hi,

I want to create a save button on lightning component for my object Shipping Address which is child to parent Account.

There are 6 fields in shipping address, I want those fields to get saved and displayed on the lightning component 

I am tricked about how do i save it into database and get it displayed on my screen.

Can anyone help me on this please
 
Hi,

I am trying to update details of my account.I have created a lightning button and have associated a lightnening component to it. On click of that lightning component, I am trying to update the updated records in an external System.

However, after clicking on the action, i am getting following message.
Uncaught Action failed: c:UpdateCustomerHub$controller$handleclick [Cannot read property 'Opportunity__c' of null]


Can anyone help me with this??

Below is my code :

Cmp :

<aura:component controller="ProductInterestController" implements="force:lightningQuickAction ">
    <aura:attribute name= "accts" type ="Account[]"/>
    <aura:attribute name="productInterest" type="Product_Interest__c"/>
    <aura:attribute name="accountId" type="Id"/>
    <aura:attribute name="selectedAddress" type="Shipping_Address__c" default="{Name : '',
                                                                               Shipping_City__c : ''}"/>
    <aura:attribute name="ShowHideNotification" type="Boolean" default="false"/>
    <aura:attribute name="Spinner" type="boolean" default="false"/>
    <aura:attribute name="oppty" type="Opportunity"/>
    <aura:attribute name="errorShow" type="String"/>
    
    <lightning:button variant  = "brand" label = "Update in Customer Hub" onclick= "{!c.handleclick}"/>                                                  
                                                         
</aura:component>

Controller :

({
    
     handleclick: function(cmp, event, helper) {
        cmp.set('v.Spinner', true);
        var action = cmp.get("c.pushToCustomerHub");
        action.setParams({ acct : cmp.get('v.accountId') ,
                           status : cmp.get('v.imSearchStatus'),
                           shipAddress : cmp.get('v.selectedAddress'),
                           opptyId : cmp.get('v.productInterest').Opportunity__c,
                           piId : cmp.get('v.productInterest').Id,
                          oppty : cmp.get('v.oppty'),
                          email : cmp.get('v.oppty').Account.PersonEmail});
        action.setCallback(this, function(response) {
            var state = response.getState();
            var resultData = response.getReturnValue();
            if (state === "SUCCESS" && resultData != undefined && !resultData.hasOwnProperty('error')) {                
               // console.log(resultData);
                helper.searchCallout(cmp,event,helper,resultData);
            }
            else{
                cmp.set('v.Spinner', false);
                if(resultData!= undefined && resultData.error!= undefined){
                    cmp.set('v.error', resultData.error);
                }                
            }
        });
        $A.enqueueAction(action);
    },
    
    searchCallout : function(cmp,event,helper,resp){
        var action = cmp.get("c.callFutureMethod");
        action.setParams({ imIdList : resp.imList });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
               // console.log('make callout');
                helper.fetchData(cmp,event,helper,resp.imId);     
            }
            else{
                cmp.set('v.Spinner', false);
                var error = response.getError();
                if(Array.isArray(error) && error.length > 0) {
                    var errorMsg = error[0].message;
                    cmp.set('v.error', response.getError()[0].message);
                //    console.log('error', response.getError()[0].message);
                }
            } 
        });
        $A.enqueueAction(action);
    },
    
    
    fetchData : function(cmp,event,helper, resp){
        var action = cmp.get("c.parseUpdatedIMResponse");
        action.setParams({ imId : resp });
        action.setCallback(this, function(response){
            var state = response.getState();
            var resp = JSON.parse(response.getReturnValue());
           // console.log('resp:', resp);
            if (state === "SUCCESS" && resp!=null && resp.error== null) {
                cmp.set('v.Spinner', false);
              //  console.log('response', response.getReturnValue());  
                cmp.getEvent("cdfEvent").fire();
            }else{
                cmp.set('v.Spinner', false);
                if(resp.error!= null){
                    cmp.set('v.error', resp.error);
                }
            } 
        });
        $A.enqueueAction(action);
    }
})

 
Hi,

I want to update details on account, which further should update in external system. 

We have an API already made, which updates through a backend event. However, I want to create a custom lightning button on Accounts , which should call that method and hence update the call.

Can someone tell, how is this achievable?
Hi,

I have a lookup on both case and case line item

While backend uploading of Order Line items , Order lookup is required.

Howevr, what I require on front end is, whenever a case is created, and whenever we try to create a line item against the case object, 

it should copy the lookup value of order from parent to child, so that user can easily select order line item on which the case needs to be raised 
Hi,

I have a custom lightning page,
There are set of opportunity products, which gets added as a record. Every record has a picklist value.

But in the event of 100 products, i need to manually go and set the picklist value, even if they are same.

What i want is, if i can have a checkbox at the lightning component, which when checked, will populate the same picklist value as selected on the first record, and still allows the user to change the picklist value for records he wants to.

This way it will be easier for him
Hi,

I want to write a batch class to execute the below function.

Objects Involved: Opportunity, Estimations, Orders, BRT, Achievements

Estimations and orders are child of opportunity
Achievements is child to BRT
Both look up to Business and Location ( separate custom objects)

BRT and Opportunity are unrelated



Unique Key on Opportunity is  Year-Month-Location-Business, same is the unique key on BRT

When the opportunity is closed won and if the unique key on opportunity matches with a unique key on BRT(master table). I want a class to run, that  creates a record in the achievement object(child to BRT)

Records captured at Achievement are

1) Opportunity: Opportunity Name
2) Opportunity: Created Date
3) Opportunity: Closed Won Date
4) Order: Order lookup( Order lookups to opportunity) 
5) Order: Order amount
6) Order: Billed Date
7) Estimations: Estimation Amount
8) Estimations: Month
9) Estimations: Start Date
10) BRT:  Targets

BRT being parent of Achievements, a lookup will be present, also I want to order no. to populated in order lookup provided at Achievements object.

Also if we have to provide estimations and opportunity lookup , its no problem.
since one opportunity can have multiple orders
Hi,

I have a custom object called PI (child to opportunity), which picks price from pricebook entry.

Now, when a PI is created price gets stamped and wont be revised even if the price in pricebook entry changes.

Price in pricebook entry gets updated from SAP via batch class every morning.

I want to write a batch class which checks, if the price of the product in PI to new price of the product in Pricebook entry ( if any updates)

If the price in Pricebook entry is lower than price in PI, i want to trigger a mail to mail-id specified in Opportunity.


The business rationale is to notify customer about downward revision in price, which can facilitate the deal
 

Hi,

I have an apex class method already written which gets called by a button in background,
 

I want a button on Accounts screen, which can call that lightning component and inturn the apex method.

So, I want a button on Accounts screen, which calls a component that calls the method written in Apex class.
Since the method makes the API call, do I need to write some extra code? Since the functionality for API is already written.


 

Hi,

I have a custom object as child to opportunity object. 

I want to delete opportuntity every night, when all the child records for it is 0.

I want to write a batch apex(schedulable), which deletes all such records at 12:00 in the night.

So lets say,

If an opportunity has 2 child records, and the Grand Total value on both child records is 0, I want to delete the opportunity along with its child record.

It should only happen, when both child records value is 0. In case where the child record value is there for one of the childs.. it shouldnt get deleted
The trigger automatically attaches pricebooks, when a produt get created. which pricebook it should attach depends upon the LOB

public class ProductTriggerHandler extends TriggerHandler{
    public ProductTriggerHandler() {
    }
    
    public override void afterUpdate() {
        System.debug('this is after update');
        
    }   
    
    public override void beforeUpdate() {
        
        
        
    }
    
    public override void beforeInsert() {
        
    }
    
    public override void afterInsert() {
        System.debug('this is after insert');
        createPricebookEntries((List<Product2>)Trigger.new);        
    }    
    
    public void createPricebookEntries(List<Product2> productList){
        
        List<PricebookEntry> peList = new List<PricebookEntry>();
        List<PricebookEntry> mpeList = new List<PricebookEntry>(); //For Modular Kitchen
        List<PricebookEntry> opeList = new List<PricebookEntry>(); // For All other LOB
        
       
        List<Pricebook2> pricebookIds = [Select id,Site_Code__c from Pricebook2 where Pricebook_Category__c ='FR']; // Fetches only Furniture Pricebook
        List<Pricebook2> MKpricebookIds = [Select id,Site_Code__c from Pricebook2 where Pricebook_Category__c ='MK' OR IsStandard = TRUE]; // Fethches only MK Pricebook and Standard Pricebook
        List<Pricebook2> opricebookIds = [Select id,Site_Code__c from Pricebook2 where IsStandard = TRUE]; // Fetches only Standard Pricebook
           
   
 // Attaching Standard Pricebook and Furniture Pricebooks when LOB is Furniture, Home Improvement , Home Improvements
        
        if(pricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
                if(prod.LOB__c!=null && Label.FR_Pricebook.contains(prod.LOB__c)){
                    for(Pricebook2 pb2 : pricebookIds){
                        PricebookEntry pe = new PricebookEntry();
                        pe.UnitPrice = 1;
                        pe.Pricebook2Id = pb2.id;
                        pe.Product2Id = prod.id;
                        peList.add(pe);
                    }
                    
                }
            }
            
         
            
            
            if(peList.size()>0){
                insert peList;
                System.debug('id:'+peList[0].id);
            }
        }
        
 // Attaches Standard pricebook to all products whose LOB is not Furniture, Modular Kitchen, Mk , Home Improvement,Home Improvements       
      
      if(opricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
if(prod.LOB__c!=null && Label.Other_Pricebooks.contains(prod.LOB__c)){
                    for(Pricebook2 opb2 : opricebookIds){
                        PricebookEntry ope = new PricebookEntry();
                        ope.UnitPrice = 1;
                        ope.Pricebook2Id = opb2.id;
                        ope.Product2Id = prod.id;
                        opeList.add(ope);
                    }
                    
                }
            }
            
         
            
            
            if(opeList.size()>0){
                insert opeList;
                System.debug('id:'+opeList[0].id);
            }
        }
        
        
        
// Attaching Standard Pricebook and Modular Kitchen Pricebook when LOB is Modular Kitchen or MK    
        
           if(MKpricebookIds.size() > 0){
            for(Product2 prod: productList){
                System.debug('prod.LOB__c:'+prod.LOB__c);
                if(prod.LOB__c == 'Modular Kitchen' || prod.LOB__c == 'MK'){
                    for(Pricebook2 mpb2 : mkpricebookIds){
                        PricebookEntry mpe = new PricebookEntry();
                        mpe.UnitPrice = 1;
                        mpe.Pricebook2Id = mpb2.id;
                        mpe.Product2Id = prod.id;
                        mpeList.add(mpe);
                    }
                    
                }
            }
            
         
            
            
            if(mpeList.size()>0){
                insert mpeList;
                System.debug('id:'+mpeList[0].id);
            }
        }
    }
    
}
Hi,

I want to save attachement of the email template that gets sent via batch apex to the user email.

I want to save it under Attachements under Opportunities, can someone suggest how can I do this 
Hi,

 want to create a save button on lightning component for my object Shipping Address which is child to parent Account.

There are 6 fields in shipping address, I want those fields to get saved and displayed on the lightning component 

I am tricked about how do i save it into database and get it displayed on my screen.

Here is my code

Apex:
1public class InsertAndDisplayC {
2     
3    @AuraEnabled
4    public static Id saveDetails(Contact con){
5        // DML operation to save Contact Details  
6        INSERT con;
7        return con.Id;
8    }
9}
Component:
01<aura:component controller="InsertAndDisplayC"
02                implements="lightning:isUrlAddressable,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
03     
04    <aura:attribute name="PageHeading" type="String" default="Create and Display Contacts"/>
05    <aura:attribute name="RegForm" type="Contact" default="{'sobjectType' : 'Contact'}"/>
06    <aura:attribute name="showDetails" type="boolean" default="false" />
07     
08    <div class="slds-m-top--xx-large">
09        <div class="slds-page-header">
10            <div class="slds-align--absolute-center">
11                <div class="slds-text-heading--large">      
12                    {!v.PageHeading}
13                </div>
14            </div>
15        </div>
16    </div>
17    <br/> <br/>
18     
19    <div class = "slds-size--3-of-8">
20        <lightning:input label="Enter First Name" name="fname" value="{!v.RegForm.FirstName}"/>
21        <br/>
22        <lightning:input label="Enter Last Name" name="lname" value="{!v.RegForm.LastName}"/>
23        <br/>
24        <lightning:input label="Enter Phone" name="phone" value="{!v.RegForm.Phone}"/>
25        <br/>
26        <lightning:input label="Enter Email" name="email" value="{!v.RegForm.Email}"/>
27        <br/>
28        <lightning:button label="Submit" onclick="{!c.doSubmit}"/>
29    </div>
30    <br/>
31    <aura:if isTrue="{!v.showDetails}">
32        <div class = "slds-size--3-of-8">
33            <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Contact">
34                <div class="slds-box">
35                    <lightning:outputField fieldName="Name" />
36                    <lightning:outputField fieldName="Phone" />
37                    <lightning:outputField fieldName="Email" />
38                </div>
39            </lightning:recordViewForm>
40        </div>
41    </aura:if>
42</aura:component>
Controller:
01({
02    doSubmit : function(component, event, helper) {
03        var regForm = component.get("v.RegForm");
04        var action = component.get("c.saveDetails");
05        action.setParams({con  : regForm});
06        action.setCallback(this, function(response) {
07            var state = response.getState();         
08            if (state === "SUCCESS") {
09                var res = response.getReturnValue();
10                component.set('v.recordId',res);
11                component.set("v.showDetails", true);
12                alert('Successfully Saved' + res);
13                component.set('v.RegForm','');
14            }
15            else if (state === "ERROR") {
16                var errors = response.getError();
17                if (errors) {
18                    if (errors[0] && errors[0].message) {
19                        console.log("Error message: " +
20                                    errors[0].message);
21                    }
22                }
23                else {
24                    console.log(response.getReturnValue());
25                }
26            }
27        });
28        $A.enqueueAction(action);
29    },
30})
CSS:
01.THIS {
02 
03}
04 
05.THIS.slds-size--3-of-8 {
06     
07    margin-left: 430px;
08}
09 
10.THIS label.slds-form-element__label{
11     
12    font-size: 1.00rem;
13    color: blue;
14}
Application:
view sourceprint?
1<aura:application extends="force:slds">
2    <c:InsertAndDisplay/>
3</aura:application>
Hi,

I want to create a save button on lightning component for my object Shipping Address which is child to parent Account.

There are 6 fields in shipping address, I want those fields to get saved and displayed on the lightning component 

I am tricked about how do i save it into database and get it displayed on my screen.

Can anyone help me on this please
 
Hi,

I am trying to update details of my account.I have created a lightning button and have associated a lightnening component to it. On click of that lightning component, I am trying to update the updated records in an external System.

However, after clicking on the action, i am getting following message.
Uncaught Action failed: c:UpdateCustomerHub$controller$handleclick [Cannot read property 'Opportunity__c' of null]


Can anyone help me with this??

Below is my code :

Cmp :

<aura:component controller="ProductInterestController" implements="force:lightningQuickAction ">
    <aura:attribute name= "accts" type ="Account[]"/>
    <aura:attribute name="productInterest" type="Product_Interest__c"/>
    <aura:attribute name="accountId" type="Id"/>
    <aura:attribute name="selectedAddress" type="Shipping_Address__c" default="{Name : '',
                                                                               Shipping_City__c : ''}"/>
    <aura:attribute name="ShowHideNotification" type="Boolean" default="false"/>
    <aura:attribute name="Spinner" type="boolean" default="false"/>
    <aura:attribute name="oppty" type="Opportunity"/>
    <aura:attribute name="errorShow" type="String"/>
    
    <lightning:button variant  = "brand" label = "Update in Customer Hub" onclick= "{!c.handleclick}"/>                                                  
                                                         
</aura:component>

Controller :

({
    
     handleclick: function(cmp, event, helper) {
        cmp.set('v.Spinner', true);
        var action = cmp.get("c.pushToCustomerHub");
        action.setParams({ acct : cmp.get('v.accountId') ,
                           status : cmp.get('v.imSearchStatus'),
                           shipAddress : cmp.get('v.selectedAddress'),
                           opptyId : cmp.get('v.productInterest').Opportunity__c,
                           piId : cmp.get('v.productInterest').Id,
                          oppty : cmp.get('v.oppty'),
                          email : cmp.get('v.oppty').Account.PersonEmail});
        action.setCallback(this, function(response) {
            var state = response.getState();
            var resultData = response.getReturnValue();
            if (state === "SUCCESS" && resultData != undefined && !resultData.hasOwnProperty('error')) {                
               // console.log(resultData);
                helper.searchCallout(cmp,event,helper,resultData);
            }
            else{
                cmp.set('v.Spinner', false);
                if(resultData!= undefined && resultData.error!= undefined){
                    cmp.set('v.error', resultData.error);
                }                
            }
        });
        $A.enqueueAction(action);
    },
    
    searchCallout : function(cmp,event,helper,resp){
        var action = cmp.get("c.callFutureMethod");
        action.setParams({ imIdList : resp.imList });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
               // console.log('make callout');
                helper.fetchData(cmp,event,helper,resp.imId);     
            }
            else{
                cmp.set('v.Spinner', false);
                var error = response.getError();
                if(Array.isArray(error) && error.length > 0) {
                    var errorMsg = error[0].message;
                    cmp.set('v.error', response.getError()[0].message);
                //    console.log('error', response.getError()[0].message);
                }
            } 
        });
        $A.enqueueAction(action);
    },
    
    
    fetchData : function(cmp,event,helper, resp){
        var action = cmp.get("c.parseUpdatedIMResponse");
        action.setParams({ imId : resp });
        action.setCallback(this, function(response){
            var state = response.getState();
            var resp = JSON.parse(response.getReturnValue());
           // console.log('resp:', resp);
            if (state === "SUCCESS" && resp!=null && resp.error== null) {
                cmp.set('v.Spinner', false);
              //  console.log('response', response.getReturnValue());  
                cmp.getEvent("cdfEvent").fire();
            }else{
                cmp.set('v.Spinner', false);
                if(resp.error!= null){
                    cmp.set('v.error', resp.error);
                }
            } 
        });
        $A.enqueueAction(action);
    }
})