• Alex Kirby 8
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 11
    Replies
Hi All,

I am struggling to return the value of a field as a two decimal place field i.e. currency fields back to my VF page.

Here is my class:
 
public class ESDCDA {
    
    private final Opportunity opp;
    public ESDCDA(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
        
    }
    
    double eop; double op;
    
    
    list<AggregateResult>  aK;
    transient public double total {get; set;} 
    transient public decimal oppr {get; set;}
    transient public decimal losm {get; set;}
    transient public decimal mc {get; set;}  
    transient public decimal dcc {get; set;}
    transient public decimal ssp {get; set;}
    transient public decimal ans {get; set;}
    
    
    public void showlist(){
        
        aK=[select mpan__c, 
            siteaddress__c,
            Site_Contact__c,
            Site_Telephone_Number__c,
            Sub_Product__c,
            sum(on_supply_service_charge__c)ossc,
            InvoiceAddress__c
            from es_mpan__c
            where opportunity_name__c =:opp.id 
            group by mpan__c, 
            siteaddress__c,
            Site_Contact__c,
            Site_Telephone_Number__c,
            Sub_Product__c,
            InvoiceAddress__c]; 
        
        if(opp.ES_Opportunity_2__c != Null){
            
            aggregateResult[]aK1 = [select mpan__c, 
                                    siteaddress__c,
                                    Site_Contact__c,
                                    Site_Telephone_Number__c,
                                    Sub_Product__c,
                                    InvoiceAddress__c,
                                    sum(on_supply_service_charge__c)ossc
                                    from es_mpan__c 
                                    where opportunity_name__c = :opp.ES_Opportunity_2__c 
                                    group by mpan__c, 
                                    siteaddress__c,
                                    Site_Contact__c,
                                    Site_Telephone_Number__c,
                                    Sub_Product__c,
                                    InvoiceAddress__c];
            ak.addAll(ak1);
            
            AggregateResult[] t = [select sum(Total_Annual_Charges__c)tc, 
                                   sum(es_opportunity_2__r.Total_Annual_Charges__c)etc 
                                   from opportunity 
                                   where id =:opp.id];
            
            if(double.valueof(t[0].get('tc')) == Null){op = 0.00;}else{op = double.valueof(t[0].get('tc'));}
            if(double.valueof(t[0].get('etc')) == Null){eop = 0.00;}else{eop = double.valueof(t[0].get('etc'));}
            
            total = op + eop;
        }else{
            
            AggregateResult[] t = [select sum(Total_Annual_Charges__c)tc                               	 	  
                                   from opportunity 
                                   where id =:opp.id];
            
            op = double.valueof(t[0].get('tc'));
            total = op;
            
            AggregateResult[] sm = [select
                                    sum(Outright_Purchase_Price__c)oppr,
                                    sum(Lease_of_Secondary_Metering__c)losm,
                                    sum(Maintenance_Charge__c)mc,
                                    sum(Data_Collection_Charge__c)dcc,
                                    sum(Supply_Software_Package__c)ssp,
                                    sum(Ancillary_Services__c)ans
                                    from es_mpan__c
                                    where opportunity_name__c =:opp.id];
            
            oppr = decimal.valueof(sm[0].get('oppr'));
            losm = decimal.valueof(sm[0].get('losm'));
            mc = decimal.valueof(sm[0].get('mc'));
            dcc = decimal.valueof(sm[0].get('dcc'));
            ssp = decimal.valueof(sm[0].get('ssp'));
            ans = decimal.valueof(sm[0].get('ans'));
        }
    }
    
    public list<AggregateResult> jalist{
        get { return aK;}
    }
    
}
If I use double I only get one decimal place unless the field was entered with two i.e. 10.25 will return 10.25 but 10 return 10.0

With decimal I get the error: Variable does not exist: decimal at line 87

Any help is appreciated.

Thanks

 
Hi All,

I am trying to generate a pdf on from a VF page and attach it to the opportunity.

I used a custom controller and tried to modify it for use as an extension controller as I don't want any user input. The pdf must be saved to the opp on a button click etc.

I think I am missing something from my controller as when I call the {!savepdf} method I am getting this error:

Error: Unknown property 'Credit_Check__cStandardController.savepdf'

Here is the controller:
 
public with sharing class PdfGeneratorController {

    Public final Credit_Check__c CC;    
    
    public PdfGeneratorController (ApexPages.StandardController 
                                       stdController) {
                                           this.CC= (Credit_check__c)stdController.getrecord();
                                           
                                             
}
  

  public PageReference savePdf1() {

    PageReference pdf = Page.Cvs_PDF;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',cc.Opportunity__r.accountid);

    // create the new attachment
    Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = cc.name;
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = cc.Opportunity__r.accountid;
    insert attach;

    // send the user to the account to view results
    return new PageReference('/'+cc.Opportunity__r.accountid);

  }

}

In the VF page I am simply calling {!savepdf}

Any help is much appreciated.

Al

 
Hello Everyone,

First post on here, pleae be gentle. I have recently started working my way intp apex and visualforce etc and I have come across a problem.

I am trying to create an opportunity off the back of another i.e. for cross selling purposes. I want a custom button which opens a pop up where information from the opportunity is held and then used with new information to create a new opportunity.

I have managed to get the button and popup working and I can now see old opportunity data and some blank fields to enter data in, hoorah! Now I have a problem when it comes to saving.

The Error:

Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page iframecontent: Class.OpportunityInformationPage.save: line 19, column 1

The Class:

public class OpportunityInformationPage {

     private final Opportunity oppy;
  
    public OpportunityInformationPage (ApexPages.StandardController
        stdController) {
   this.oppy = (Opportunity)stdController.getrecord();

    }
Public opportunity oppstring{get; set;}
public OpportunityInformationPage(){
oppstring= new opportunity();
}

public void save(){

opportunity opp= new opportunity();

opp.Accountid= oppstring.accountid;
system.debug(oppstring.accountid);
opp.name= oppstring.name;

opp.closedate= oppstring.closedate;

opp.StageName= oppstring.StageName;

opp.leadSource= oppstring.LeadSource;

opp.Ownerid= oppstring.Ownerid;

opp.Amount= oppstring.Amount;

opp.Type= oppstring.Type;

opp.Probability= oppstring.Probability;

opp.Product_type__c = oppstring.Product_type__c;


insert opp;

}


}

The VF Page:

<apex:page showHeader="false" sidebar="False" standardcontroller="Opportunity" extensions="OpportunityInformationPage">

<apex:form >

<apex:pageBlock >

<apex:commandButton value="save" action="{!save}"/>

<apex:pageBlockSection columns="2" title="Old Opportunity Information">

<apex:outputfield value="{!opportunity.Product_Type__c}"/>
<apex:outputfield value="{!opportunity.closedate}"/>
<apex:outputfield value="{!opportunity.Start_Date__c}"/>
<apex:outputfield value="{!opportunity.End_Date__c}"/>

</apex:pageBlockSection>

<apex:pageBlockSection columns="2" title="Opportunity Information">


<apex:inputField value="{!opportunity.Ownerid}"/>

<apex:inputField value="{!oppstring.Amount}"/>

<apex:inputField value="{!oppstring.CloseDate}"/>

<apex:inputField value="{!oppstring.name}"/>

<apex:inputField value="{!oppstring.Accountid}"/>

<apex:inputField value="{!oppstring.StageName}"/>

<apex:inputField value="{!oppstring.Type}"/>

<apex:inputField value="{!oppstring.Probability}"/>

<apex:inputField value="{!oppstring.LeadSource}"/>

<apex:inputfield value="{!oppstring.Product_Type__c}"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

Any help will be appreciated as I mentioned I am no hero when it comes to Apex.

Thanks in advance.

Alex
Hi All,

I am struggling to return the value of a field as a two decimal place field i.e. currency fields back to my VF page.

Here is my class:
 
public class ESDCDA {
    
    private final Opportunity opp;
    public ESDCDA(ApexPages.StandardController stdController) {
        this.opp = (Opportunity)stdController.getRecord();
        
    }
    
    double eop; double op;
    
    
    list<AggregateResult>  aK;
    transient public double total {get; set;} 
    transient public decimal oppr {get; set;}
    transient public decimal losm {get; set;}
    transient public decimal mc {get; set;}  
    transient public decimal dcc {get; set;}
    transient public decimal ssp {get; set;}
    transient public decimal ans {get; set;}
    
    
    public void showlist(){
        
        aK=[select mpan__c, 
            siteaddress__c,
            Site_Contact__c,
            Site_Telephone_Number__c,
            Sub_Product__c,
            sum(on_supply_service_charge__c)ossc,
            InvoiceAddress__c
            from es_mpan__c
            where opportunity_name__c =:opp.id 
            group by mpan__c, 
            siteaddress__c,
            Site_Contact__c,
            Site_Telephone_Number__c,
            Sub_Product__c,
            InvoiceAddress__c]; 
        
        if(opp.ES_Opportunity_2__c != Null){
            
            aggregateResult[]aK1 = [select mpan__c, 
                                    siteaddress__c,
                                    Site_Contact__c,
                                    Site_Telephone_Number__c,
                                    Sub_Product__c,
                                    InvoiceAddress__c,
                                    sum(on_supply_service_charge__c)ossc
                                    from es_mpan__c 
                                    where opportunity_name__c = :opp.ES_Opportunity_2__c 
                                    group by mpan__c, 
                                    siteaddress__c,
                                    Site_Contact__c,
                                    Site_Telephone_Number__c,
                                    Sub_Product__c,
                                    InvoiceAddress__c];
            ak.addAll(ak1);
            
            AggregateResult[] t = [select sum(Total_Annual_Charges__c)tc, 
                                   sum(es_opportunity_2__r.Total_Annual_Charges__c)etc 
                                   from opportunity 
                                   where id =:opp.id];
            
            if(double.valueof(t[0].get('tc')) == Null){op = 0.00;}else{op = double.valueof(t[0].get('tc'));}
            if(double.valueof(t[0].get('etc')) == Null){eop = 0.00;}else{eop = double.valueof(t[0].get('etc'));}
            
            total = op + eop;
        }else{
            
            AggregateResult[] t = [select sum(Total_Annual_Charges__c)tc                               	 	  
                                   from opportunity 
                                   where id =:opp.id];
            
            op = double.valueof(t[0].get('tc'));
            total = op;
            
            AggregateResult[] sm = [select
                                    sum(Outright_Purchase_Price__c)oppr,
                                    sum(Lease_of_Secondary_Metering__c)losm,
                                    sum(Maintenance_Charge__c)mc,
                                    sum(Data_Collection_Charge__c)dcc,
                                    sum(Supply_Software_Package__c)ssp,
                                    sum(Ancillary_Services__c)ans
                                    from es_mpan__c
                                    where opportunity_name__c =:opp.id];
            
            oppr = decimal.valueof(sm[0].get('oppr'));
            losm = decimal.valueof(sm[0].get('losm'));
            mc = decimal.valueof(sm[0].get('mc'));
            dcc = decimal.valueof(sm[0].get('dcc'));
            ssp = decimal.valueof(sm[0].get('ssp'));
            ans = decimal.valueof(sm[0].get('ans'));
        }
    }
    
    public list<AggregateResult> jalist{
        get { return aK;}
    }
    
}
If I use double I only get one decimal place unless the field was entered with two i.e. 10.25 will return 10.25 but 10 return 10.0

With decimal I get the error: Variable does not exist: decimal at line 87

Any help is appreciated.

Thanks

 
Hi All,

I am trying to generate a pdf on from a VF page and attach it to the opportunity.

I used a custom controller and tried to modify it for use as an extension controller as I don't want any user input. The pdf must be saved to the opp on a button click etc.

I think I am missing something from my controller as when I call the {!savepdf} method I am getting this error:

Error: Unknown property 'Credit_Check__cStandardController.savepdf'

Here is the controller:
 
public with sharing class PdfGeneratorController {

    Public final Credit_Check__c CC;    
    
    public PdfGeneratorController (ApexPages.StandardController 
                                       stdController) {
                                           this.CC= (Credit_check__c)stdController.getrecord();
                                           
                                             
}
  

  public PageReference savePdf1() {

    PageReference pdf = Page.Cvs_PDF;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',cc.Opportunity__r.accountid);

    // create the new attachment
    Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = cc.name;
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = cc.Opportunity__r.accountid;
    insert attach;

    // send the user to the account to view results
    return new PageReference('/'+cc.Opportunity__r.accountid);

  }

}

In the VF page I am simply calling {!savepdf}

Any help is much appreciated.

Al

 
Hello Everyone,

First post on here, pleae be gentle. I have recently started working my way intp apex and visualforce etc and I have come across a problem.

I am trying to create an opportunity off the back of another i.e. for cross selling purposes. I want a custom button which opens a pop up where information from the opportunity is held and then used with new information to create a new opportunity.

I have managed to get the button and popup working and I can now see old opportunity data and some blank fields to enter data in, hoorah! Now I have a problem when it comes to saving.

The Error:

Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page iframecontent: Class.OpportunityInformationPage.save: line 19, column 1

The Class:

public class OpportunityInformationPage {

     private final Opportunity oppy;
  
    public OpportunityInformationPage (ApexPages.StandardController
        stdController) {
   this.oppy = (Opportunity)stdController.getrecord();

    }
Public opportunity oppstring{get; set;}
public OpportunityInformationPage(){
oppstring= new opportunity();
}

public void save(){

opportunity opp= new opportunity();

opp.Accountid= oppstring.accountid;
system.debug(oppstring.accountid);
opp.name= oppstring.name;

opp.closedate= oppstring.closedate;

opp.StageName= oppstring.StageName;

opp.leadSource= oppstring.LeadSource;

opp.Ownerid= oppstring.Ownerid;

opp.Amount= oppstring.Amount;

opp.Type= oppstring.Type;

opp.Probability= oppstring.Probability;

opp.Product_type__c = oppstring.Product_type__c;


insert opp;

}


}

The VF Page:

<apex:page showHeader="false" sidebar="False" standardcontroller="Opportunity" extensions="OpportunityInformationPage">

<apex:form >

<apex:pageBlock >

<apex:commandButton value="save" action="{!save}"/>

<apex:pageBlockSection columns="2" title="Old Opportunity Information">

<apex:outputfield value="{!opportunity.Product_Type__c}"/>
<apex:outputfield value="{!opportunity.closedate}"/>
<apex:outputfield value="{!opportunity.Start_Date__c}"/>
<apex:outputfield value="{!opportunity.End_Date__c}"/>

</apex:pageBlockSection>

<apex:pageBlockSection columns="2" title="Opportunity Information">


<apex:inputField value="{!opportunity.Ownerid}"/>

<apex:inputField value="{!oppstring.Amount}"/>

<apex:inputField value="{!oppstring.CloseDate}"/>

<apex:inputField value="{!oppstring.name}"/>

<apex:inputField value="{!oppstring.Accountid}"/>

<apex:inputField value="{!oppstring.StageName}"/>

<apex:inputField value="{!oppstring.Type}"/>

<apex:inputField value="{!oppstring.Probability}"/>

<apex:inputField value="{!oppstring.LeadSource}"/>

<apex:inputfield value="{!oppstring.Product_Type__c}"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

Any help will be appreciated as I mentioned I am no hero when it comes to Apex.

Thanks in advance.

Alex