• Amit Jadhav 13
  • NEWBIE
  • 130 Points
  • Member since 2019

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 18
    Replies
I am new when it comes to visualforce and creating custom controllers. 

I have a problem to solve where each Account needs the ability to quickly add an Invoice with only 1 Invoice line item. The ask is to be able to click a button on the Account and be prompted to enter the quantity prior to creating the invoice. 
The result should be after the quantity is entered, an Invoice record is created with 1 Invoice line item showing the fields price and quantity.

Help with how the code should be written would help a lot.

 
I have created a 6 objects 
Test1
Test2
Test3
Test4
Test5
Test6

Test6(Lookup with Test5)
Test5(Lookup with Test4)
Test4(Lookup with Test3)
Test3(Lookup with Test2)
Test2(Lookup with Test1)

i want Test1 records in test 6 using soql

Please Help

Thanks,

Regards
Amit Jadhav
My requirement is Display Avg IN Visualforce page 
Field Is a Quantity__c so Show the Average Of Quantity 
for example 
Price__c * Qyt__c = Total_Price__c (Total price is formula field)
Total_Price__c * Disscount_per__c = Disscount__c (Disscount Is also formula field)
Disscount__c + Total_Price__c = Amount (Amount is  also formula field)


how to cover this filed in test class
Controller:

public with sharing class costsheet {
   
    

    public String OrderId;
    public Order ord;
    
    
    public costsheet(ApexPages.StandardController controller) {
      listIex =0.0;
      CFSList =0.0;
      CHAList =0.0;
      CHAListS =0.0;
      ord= (Order)Controller.getRecord();
      OrderId=Apexpages.currentpage().getParameters().get('id');
      system.debug('listStemer>>'+OrderId);
      listStemer=[Select Id,subtotal__c,Supplier_Order__c from Shipper_Info_India__c where Supplier_Order__c =:ord.id AND RecordType.Name='Steamer Charges' limit 1]  ;
      system.debug('listStemer>>'+listStemer);
     if(listStemer.size()>0)
     {
     listIex =listStemer[0].subtotal__c;
     system.debug('listStemer>>'+listIex );
     }
     listCHAChargesR=[Select Id,subtotal__c,Supplier_Order__c  from Shipper_Info_India__c where Supplier_Order__r.id =:ord.id AND RecordType.Name='CHA Charges' AND Bill_Type__c = 'Reimbursement Type'] ;
     if(listCHAChargesR.size()>0)
     {
     CHAList =listCHAChargesR[0].subtotal__c;
     }
     listCHAChargesS=[Select Id,subtotal__c,Supplier_Order__c  from Shipper_Info_India__c where Supplier_Order__r.id =:ord.id AND RecordType.Name='CHA Charges' AND Bill_Type__c = 'Service Type'] ;
     if(listCHAChargesS.size()>0)
     {
     CHAListS =listCHAChargesS[0].subtotal__c;
     }
     listCFSCharges=[Select Id,subtotal__c,Supplier_Order__c  from Shipper_Info_India__c where Supplier_Order__r.id =:ord.id AND RecordType.Name='CFS Charges' limit 1] ;
     if(listCFSCharges.size()>0)
     {
     CFSList =(listCFSCharges[0].subtotal__c).setScale(2);
     }
     
     Calculation();
    
    
    }
    
        public List<Shipper_Info_India__c > listStemer;
        public List<Shipper_Info_India__c > listCFSCharges;
        public List<Shipper_Info_India__c > listCHAChargesR;
        public List<Shipper_Info_India__c > listCHAChargesS;
        public Decimal CFSList {get;set;}
        public Decimal CHAList {get;set;}
        Public Decimal listIex {get;set;}
        public Decimal CHAListS {get;set;}
        public List<Order> ordList = new List<Order>();
        public Decimal TotalAmount_3{get;set;}
        public Decimal TotalFreightAmount_19{get;set;}
        public Decimal TotalFreightAmount_21{get;set;}
        public Decimal TotalFreightAmount_c21{get;set;}
        public Decimal TotalFreightAmount_d21{get;set;}
        public Decimal BasicDuty_c23{get;set;}
        public Decimal BasicDuty_d23{get;set;}
        public Decimal Cess_c24{get;set;}
        public Decimal Cess_d24{get;set;}
        public Decimal TotalCustomDuty_g25{get;set;}
        public Decimal TotalCustomDuty_c25{get;set;}
        public Decimal TotalCustomDuty_d25{get;set;}
        public Decimal ShippingLine_c27 {get;set;}
        public Decimal ShippingLine_d27 {get;set;}
        public Decimal StorageCFS_c32 {get;set;}
        public Decimal StorageCFS_d32 {get;set;}
        public Decimal Others_c30 {get;set;} 
        public Decimal Others_d30 {get;set;} 
        public Decimal Clearing_c31 {get;set;}
        public Decimal Clearing_d31 {get;set;}
        public Decimal TotalC {get;set;}
        public Decimal TotalCost{get;set;}
        public decimal TotalC_c37 {get;set;}
        public decimal TotalC_d37 {get;set;}
        public decimal TotalCost_c38 {get;set;}
        public decimal TotalCost_d38 {get;set;}
        
            
        public void Calculation(){
         TotalAmount_3 = 0;
         TotalFreightAmount_19= 0;
         if(ord.Quantity__c != NULL && ord.Unit_Price__c != null){
            TotalAmount_3 = (ord.Unit_Price__c *ord.Quantity__c).setScale(2);
          }else{
           TotalAmount_3=0;
          }
          if(ord.Total_Insurance__c != null){
          // Need to update this with adding Freight charges
           TotalFreightAmount_19= (ord.Total_Insurance__c+ord.Total_Sea_Freight_Charges__c+TotalAmount_3).setscale(2) ;
           }else{
           TotalFreightAmount_19=0;
           }
           if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalFreightAmount_21 = (TotalFreightAmount_19*ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
            TotalFreightAmount_21=(0+TotalFreightAmount_19).setscale(2);
          }
          if(TotalFreightAmount_19 != 0)
           {
           TotalFreightAmount_c21 = (TotalFreightAmount_21/ord.Quantity__c/1000).setscale(2);
          }
           
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalFreightAmount_d21 = (TotalFreightAmount_c21*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
          TotalFreightAmount_d21=0;
          }
          if(ord.Basic_Customs_Duty_value__c != null)
           {
           BasicDuty_c23 = (ord.Basic_Customs_Duty_value__c/ord.Quantity__c/1000).setscale(2);
          }else{
           BasicDuty_c23=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           BasicDuty_d23 = (BasicDuty_c23*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
           BasicDuty_d23=0;
          }  
          if(ord.Social_Welfare_Surcharge__c != null)
           {
           Cess_c24 = (ord.Social_Welfare_Surcharge__c/ord.Quantity__c/1000).setscale(2);
          }else{
           Cess_c24=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           Cess_d24 = (Cess_c24*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
           Cess_d24=0;
          }  
          if(ord.Basic_Customs_Duty_value__c != null && ord.Social_Welfare_Surcharge__c != null)
          {
           TotalCustomDuty_g25=(ord.Basic_Customs_Duty_value__c+ord.Social_Welfare_Surcharge__c).setscale(2);
          }else{
            TotalCustomDuty_g25=0;
          }
          if(TotalCustomDuty_g25 != 0)
           {
           TotalCustomDuty_c25 = (TotalCustomDuty_g25/ord.Quantity__c/1000).setscale(2);
          }else{
           TotalCustomDuty_c25 =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalCustomDuty_d25 = (TotalCustomDuty_c25*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           TotalCustomDuty_d25 =0;
          }
          if(listIex != null)
           {
           ShippingLine_c27 = (listIex/ord.Quantity__c/1000).setscale(2);
          }else{
           ShippingLine_c27 =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           ShippingLine_d27 = (ShippingLine_c27*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           ShippingLine_d27 =0;
          }
          if(CFSList != null)
           {
           StorageCFS_c32 = (CFSList/ord.Quantity__c/1000).setscale(2);
          }else{
           StorageCFS_c32 =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           StorageCFS_d32 = (StorageCFS_c32*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           StorageCFS_d32 =0;
          }
          
          if(CHAList != null)
           {
           Others_c30 = (CHAList/ord.Quantity__c/1000).setscale(2);
          }else{
           Others_c30  =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           Others_d30  = (Others_c30 *1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           Others_d30  =0;
          }
          
          if(CHALists != null)
           {
           Clearing_c31 = (CHALists/ord.Quantity__c/1000).setscale(2);
          }else{
           Clearing_c31  =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           Clearing_d31  = (Clearing_c31 *1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           Clearing_c31  =0;
          }
          
          
          TotalC = (listIex+CHAList+CHAListS+CFSList).setscale(2);
          TotalCost = (TotalC+TotalFreightAmount_21+TotalCustomDuty_g25).setscale(2);
          
          if(TotalC != null)
           {
           TotalC_c37= (TotalC/ord.Quantity__c/1000).setscale(2);
          }else{
           TotalC_c37=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalC_d37= (TotalC_c37*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           TotalC_d37=0;
          }
          
           if(TotalCost != null)
           {
           TotalCost_c38= (TotalCost/ord.Quantity__c/1000).setscale(2);
          }else{
           TotalCost_c38=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalCost_d38= (TotalCost_c38*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           TotalCost_d38=0;
          }
          
          
        }
          
       
        
           
      
   //Method to Save Attachments   
    
    public PageReference  SaveAttachmentpdf() {
        system.debug('In save');
        blob pdfBody;
        PageReference thePDF =  new PageReference('/apex/costsheetpdf?id='+OrderId);
        system.debug('ORD--'+OrderId);
        thePDF.setRedirect(true);
           
          if(Test.isRunningTest()) { 
             pdfBody = blob.valueOf('Unit.Test');
            } else {
             pdfBody = thePDF.getContentAsPDF();
           }
            Attachment attach = new Attachment();
            attach.body = pdfBody;
            attach.Name='CostSheetPdf '+System.Now();
            system.debug('OrderId'+OrderId);
            attach.ParentId=OrderId;
            attach.ContentType = 'application/pdf';
            Insert attach;
            
        if (attach == null){
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error will Saving a file .Please check the content of the file'));  
           }
        if (attach != null){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Quote Pdf generated successfully'));
            
          }
      PageReference qtpage = new PageReference('/'+OrderId);
      qtpage.setRedirect(true); 
      
      return thePDF;
   }
This is my class
public with sharing class costsheet {

    

 
 public List<Order> ordwrap {get;set;}
 public List<Opportunity> oppwrap {get;set;}
  public List<SOWrapper> wrapper {get;set;}
 
 
 
 public costsheet()
 {
  ordwrap=[Select id from Order limit 5];
  oppwrap=[select Id,name,Account.Name from opportunity limit 5];
  wrapper = new List<SOWrapper>() ;
        for(Integer i=0 ; i < 5 ; i++)
            wrapper.add(new SOWrapper(ordwrap[i] , oppwrap[i])) ;
  
 }

  
        public class SOWrapper{
        public Order order{get;set;}
        public Opportunity opportunity{get;set;}
        //public Cost_Price__c costprice{get;set;}
        
        public SOWrapper(Order ord, Opportunity opp){
            order= ord;
            opportunity = opp;
            //costprice = cp;
        }
    }
    
}
This is Apex Class
public with sharing class costsheet {
 
 public costsheet(ApexPages.StandardController controller) {

    }

 public List<Order> ordwrap = new List<Order>();
 public List<Opportunity> oppwrap = new List<Opportunity>();
 
 
 
 public costsheet()
 {
  this.SOWrappers = new List<SOWrapper>();
  ordwrap=[Select id,Cost_Price_As_per_Allocation__r.CI__c from Order];
  oppwrap=[select Id,name,Account.Name from opportunity];
  for(opportunity opp:oppwrap){
                for(Order ord: ordwrap){
                    If(opp.id == ord.id)
                    {
                        SOWrapper wrapper = new SOWrapper(opp, ord);
                        this.SOWrappers.add(wrapper);
                    }
                        
                    }
                }
 }
 public List<SOWrapper> SOWrappers{get;set;}
 public class SOWrapper{
        public Order order{get;set;}
        public Opportunity opportunity{get;set;}
        public Cost_Price__c costprice{get;set;}
        
        public SOWrapper(Order ord, Opportunity opp,Cost_Price__c cp){
            order= ord;
            opportunity = opp;
            costprice = cp;
        }
    }
    
}
<apex:page controller="costsheet">
<apex:form >
  <apex:pageblock >
   <apex:pageblockSection >
   <table>
   <tr>
    <td><apex:inputField value="{!Ord.Status}"/></td>
    
    </tr>
   </table>
   </apex:pageblockSection>
  </apex:pageblock>
  </apex:form>
</apex:page>
 
I have created a 6 objects 
Test1
Test2
Test3
Test4
Test5
Test6

Test6(Lookup with Test5)
Test5(Lookup with Test4)
Test4(Lookup with Test3)
Test3(Lookup with Test2)
Test2(Lookup with Test1)

i want Test1 records in test 6 using soql

Please Help

Thanks,

Regards
Amit Jadhav
Please explain me soql subQuery.
when and how to use it in Apex Code(triggers) ?
in Map and in List
give me some examples
Hi,

I created an email action in the case feed and an apex class to show the default email template, but it doesn't work yet, the template doesn't load.

I have activated the default template checkbox in Support Settings as well, and the template is available for use.

Does anyone know why it doesn't work?

Thanks.

User-added image

User-added image
This is the class:
 
global class E1DefaultTemplateEmail implements Support.EmailTemplateSelector {

    global E1DefaultTemplateEmail() {    }

    global ID getDefaultEmailTemplateId(ID caseId) {

        Case c = [SELECT Subject, Description FROM Case WHERE Id=:caseId];

        EmailTemplate et;

        if (c.subject != null) {
            et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'E1HC_Send_e_mail_with_case_description'];
        }         

        return et.id;
    }
}

 
My requirement is Display Avg IN Visualforce page 
Field Is a Quantity__c so Show the Average Of Quantity 
I am new when it comes to visualforce and creating custom controllers. 

I have a problem to solve where each Account needs the ability to quickly add an Invoice with only 1 Invoice line item. The ask is to be able to click a button on the Account and be prompted to enter the quantity prior to creating the invoice. 
The result should be after the quantity is entered, an Invoice record is created with 1 Invoice line item showing the fields price and quantity.

Help with how the code should be written would help a lot.

 
for example 
Price__c * Qyt__c = Total_Price__c (Total price is formula field)
Total_Price__c * Disscount_per__c = Disscount__c (Disscount Is also formula field)
Disscount__c + Total_Price__c = Amount (Amount is  also formula field)


how to cover this filed in test class
Controller:

public with sharing class costsheet {
   
    

    public String OrderId;
    public Order ord;
    
    
    public costsheet(ApexPages.StandardController controller) {
      listIex =0.0;
      CFSList =0.0;
      CHAList =0.0;
      CHAListS =0.0;
      ord= (Order)Controller.getRecord();
      OrderId=Apexpages.currentpage().getParameters().get('id');
      system.debug('listStemer>>'+OrderId);
      listStemer=[Select Id,subtotal__c,Supplier_Order__c from Shipper_Info_India__c where Supplier_Order__c =:ord.id AND RecordType.Name='Steamer Charges' limit 1]  ;
      system.debug('listStemer>>'+listStemer);
     if(listStemer.size()>0)
     {
     listIex =listStemer[0].subtotal__c;
     system.debug('listStemer>>'+listIex );
     }
     listCHAChargesR=[Select Id,subtotal__c,Supplier_Order__c  from Shipper_Info_India__c where Supplier_Order__r.id =:ord.id AND RecordType.Name='CHA Charges' AND Bill_Type__c = 'Reimbursement Type'] ;
     if(listCHAChargesR.size()>0)
     {
     CHAList =listCHAChargesR[0].subtotal__c;
     }
     listCHAChargesS=[Select Id,subtotal__c,Supplier_Order__c  from Shipper_Info_India__c where Supplier_Order__r.id =:ord.id AND RecordType.Name='CHA Charges' AND Bill_Type__c = 'Service Type'] ;
     if(listCHAChargesS.size()>0)
     {
     CHAListS =listCHAChargesS[0].subtotal__c;
     }
     listCFSCharges=[Select Id,subtotal__c,Supplier_Order__c  from Shipper_Info_India__c where Supplier_Order__r.id =:ord.id AND RecordType.Name='CFS Charges' limit 1] ;
     if(listCFSCharges.size()>0)
     {
     CFSList =(listCFSCharges[0].subtotal__c).setScale(2);
     }
     
     Calculation();
    
    
    }
    
        public List<Shipper_Info_India__c > listStemer;
        public List<Shipper_Info_India__c > listCFSCharges;
        public List<Shipper_Info_India__c > listCHAChargesR;
        public List<Shipper_Info_India__c > listCHAChargesS;
        public Decimal CFSList {get;set;}
        public Decimal CHAList {get;set;}
        Public Decimal listIex {get;set;}
        public Decimal CHAListS {get;set;}
        public List<Order> ordList = new List<Order>();
        public Decimal TotalAmount_3{get;set;}
        public Decimal TotalFreightAmount_19{get;set;}
        public Decimal TotalFreightAmount_21{get;set;}
        public Decimal TotalFreightAmount_c21{get;set;}
        public Decimal TotalFreightAmount_d21{get;set;}
        public Decimal BasicDuty_c23{get;set;}
        public Decimal BasicDuty_d23{get;set;}
        public Decimal Cess_c24{get;set;}
        public Decimal Cess_d24{get;set;}
        public Decimal TotalCustomDuty_g25{get;set;}
        public Decimal TotalCustomDuty_c25{get;set;}
        public Decimal TotalCustomDuty_d25{get;set;}
        public Decimal ShippingLine_c27 {get;set;}
        public Decimal ShippingLine_d27 {get;set;}
        public Decimal StorageCFS_c32 {get;set;}
        public Decimal StorageCFS_d32 {get;set;}
        public Decimal Others_c30 {get;set;} 
        public Decimal Others_d30 {get;set;} 
        public Decimal Clearing_c31 {get;set;}
        public Decimal Clearing_d31 {get;set;}
        public Decimal TotalC {get;set;}
        public Decimal TotalCost{get;set;}
        public decimal TotalC_c37 {get;set;}
        public decimal TotalC_d37 {get;set;}
        public decimal TotalCost_c38 {get;set;}
        public decimal TotalCost_d38 {get;set;}
        
            
        public void Calculation(){
         TotalAmount_3 = 0;
         TotalFreightAmount_19= 0;
         if(ord.Quantity__c != NULL && ord.Unit_Price__c != null){
            TotalAmount_3 = (ord.Unit_Price__c *ord.Quantity__c).setScale(2);
          }else{
           TotalAmount_3=0;
          }
          if(ord.Total_Insurance__c != null){
          // Need to update this with adding Freight charges
           TotalFreightAmount_19= (ord.Total_Insurance__c+ord.Total_Sea_Freight_Charges__c+TotalAmount_3).setscale(2) ;
           }else{
           TotalFreightAmount_19=0;
           }
           if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalFreightAmount_21 = (TotalFreightAmount_19*ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
            TotalFreightAmount_21=(0+TotalFreightAmount_19).setscale(2);
          }
          if(TotalFreightAmount_19 != 0)
           {
           TotalFreightAmount_c21 = (TotalFreightAmount_21/ord.Quantity__c/1000).setscale(2);
          }
           
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalFreightAmount_d21 = (TotalFreightAmount_c21*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
          TotalFreightAmount_d21=0;
          }
          if(ord.Basic_Customs_Duty_value__c != null)
           {
           BasicDuty_c23 = (ord.Basic_Customs_Duty_value__c/ord.Quantity__c/1000).setscale(2);
          }else{
           BasicDuty_c23=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           BasicDuty_d23 = (BasicDuty_c23*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
           BasicDuty_d23=0;
          }  
          if(ord.Social_Welfare_Surcharge__c != null)
           {
           Cess_c24 = (ord.Social_Welfare_Surcharge__c/ord.Quantity__c/1000).setscale(2);
          }else{
           Cess_c24=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           Cess_d24 = (Cess_c24*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          }else{
           Cess_d24=0;
          }  
          if(ord.Basic_Customs_Duty_value__c != null && ord.Social_Welfare_Surcharge__c != null)
          {
           TotalCustomDuty_g25=(ord.Basic_Customs_Duty_value__c+ord.Social_Welfare_Surcharge__c).setscale(2);
          }else{
            TotalCustomDuty_g25=0;
          }
          if(TotalCustomDuty_g25 != 0)
           {
           TotalCustomDuty_c25 = (TotalCustomDuty_g25/ord.Quantity__c/1000).setscale(2);
          }else{
           TotalCustomDuty_c25 =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalCustomDuty_d25 = (TotalCustomDuty_c25*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           TotalCustomDuty_d25 =0;
          }
          if(listIex != null)
           {
           ShippingLine_c27 = (listIex/ord.Quantity__c/1000).setscale(2);
          }else{
           ShippingLine_c27 =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           ShippingLine_d27 = (ShippingLine_c27*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           ShippingLine_d27 =0;
          }
          if(CFSList != null)
           {
           StorageCFS_c32 = (CFSList/ord.Quantity__c/1000).setscale(2);
          }else{
           StorageCFS_c32 =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           StorageCFS_d32 = (StorageCFS_c32*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           StorageCFS_d32 =0;
          }
          
          if(CHAList != null)
           {
           Others_c30 = (CHAList/ord.Quantity__c/1000).setscale(2);
          }else{
           Others_c30  =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           Others_d30  = (Others_c30 *1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           Others_d30  =0;
          }
          
          if(CHALists != null)
           {
           Clearing_c31 = (CHALists/ord.Quantity__c/1000).setscale(2);
          }else{
           Clearing_c31  =0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           Clearing_d31  = (Clearing_c31 *1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           Clearing_c31  =0;
          }
          
          
          TotalC = (listIex+CHAList+CHAListS+CFSList).setscale(2);
          TotalCost = (TotalC+TotalFreightAmount_21+TotalCustomDuty_g25).setscale(2);
          
          if(TotalC != null)
           {
           TotalC_c37= (TotalC/ord.Quantity__c/1000).setscale(2);
          }else{
           TotalC_c37=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalC_d37= (TotalC_c37*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           TotalC_d37=0;
          }
          
           if(TotalCost != null)
           {
           TotalCost_c38= (TotalCost/ord.Quantity__c/1000).setscale(2);
          }else{
           TotalCost_c38=0;
          }
          if(ord.Exchange_Rate_PO_Currency_to_INR__c != null)
           {
           TotalCost_d38= (TotalCost_c38*1000/ord.Exchange_Rate_PO_Currency_to_INR__c).setscale(2);
          } else{
           TotalCost_d38=0;
          }
          
          
        }
          
       
        
           
      
   //Method to Save Attachments   
    
    public PageReference  SaveAttachmentpdf() {
        system.debug('In save');
        blob pdfBody;
        PageReference thePDF =  new PageReference('/apex/costsheetpdf?id='+OrderId);
        system.debug('ORD--'+OrderId);
        thePDF.setRedirect(true);
           
          if(Test.isRunningTest()) { 
             pdfBody = blob.valueOf('Unit.Test');
            } else {
             pdfBody = thePDF.getContentAsPDF();
           }
            Attachment attach = new Attachment();
            attach.body = pdfBody;
            attach.Name='CostSheetPdf '+System.Now();
            system.debug('OrderId'+OrderId);
            attach.ParentId=OrderId;
            attach.ContentType = 'application/pdf';
            Insert attach;
            
        if (attach == null){
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Error will Saving a file .Please check the content of the file'));  
           }
        if (attach != null){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Quote Pdf generated successfully'));
            
          }
      PageReference qtpage = new PageReference('/'+OrderId);
      qtpage.setRedirect(true); 
      
      return thePDF;
   }
This is my class
public with sharing class costsheet {

    

 
 public List<Order> ordwrap {get;set;}
 public List<Opportunity> oppwrap {get;set;}
  public List<SOWrapper> wrapper {get;set;}
 
 
 
 public costsheet()
 {
  ordwrap=[Select id from Order limit 5];
  oppwrap=[select Id,name,Account.Name from opportunity limit 5];
  wrapper = new List<SOWrapper>() ;
        for(Integer i=0 ; i < 5 ; i++)
            wrapper.add(new SOWrapper(ordwrap[i] , oppwrap[i])) ;
  
 }

  
        public class SOWrapper{
        public Order order{get;set;}
        public Opportunity opportunity{get;set;}
        //public Cost_Price__c costprice{get;set;}
        
        public SOWrapper(Order ord, Opportunity opp){
            order= ord;
            opportunity = opp;
            //costprice = cp;
        }
    }
    
}
<apex:page controller="costsheet">
<apex:form >
  <apex:pageblock >
   <apex:pageblockSection >
   <table>
   <tr>
    <td><apex:inputField value="{!Ord.Status}"/></td>
    
    </tr>
   </table>
   </apex:pageblockSection>
  </apex:pageblock>
  </apex:form>
</apex:page>
 
Hi,

I want to call a Lightning Component event from a Visualforce page in a Community.

I've tried in this way
 
<div id="lightning" style=""></div>

<script>
$Lightning.use("c:TheApp", function() {
	$Lightning.createComponent("c:TheComponent", {},
		"lightning",
		function(cmp) {
			createdCmp = cmp;
			var myExternalEvent;
			myExternalEvent = $A.get("e.c:TheEvent");
			myExternalEvent.setParams({
				"p": 'p',
			});
		myExternalEvent.fire();
	});
});
</script>
It's working but it is not what I exactly want, because in this way the compnent is inserted in the page a runtime.

Is there a way to call the event without inserting the component a runtime, but inserting it in the page with the community builder ?

Thanks in advance.