• Mooda Mayu
  • NEWBIE
  • -1 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
How to insert product and pricebook under opportunity using apex code through Anonymous window.
Hello Team,

I am new to salesforce, while practcing Calculator VFP, I have encountered the the below issue.

I have controll named; Calci_ctrl with the below apex class;

public class Calci_ctrl {
    
    public integer a {get; set;}
    public integer b {get; set;}
    public integer c {get; set;}
    
    public Calci_ctrl (){
        
        a = 0;
        b = 0;
        
    }
    
    public void multiply(){
        
        c = a*b;
  
    }
    
    public void devide (){
        
        c = a/b;
    }
}

And extension is;

public class Calci_extension {
    
    public integer a;
    public integer b;
    public integer c;
    
    public Calci_extension (Calci_ctrl Ctrrl){
       
    }
    
    public void addition (){
        
        c= a+b;
    }
    
        public void substract (){
        
        c= a-b;
    }

}

And VFP is;

<apex:page controller="Calci_ctrl" extensions="Calci_extension">
    <apex:form >
        <apex:pageBlock title="Calculator">
            <apex:pageBlockSection >
                <apex:inputText label="Enter 1st value" value="{!a}"/>
                <apex:inputText label="Enter 2nd value" value="{!b}"/>
                <apex:outputText label="Result" value="{!c}" id="a1"/>      
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="+" action="{!addition}"  rerender="a1"/>
                <apex:commandButton value="-" action="{!substract}" rerender="a1"/>
                <apex:commandButton value="x" action="{!multiply}" rerender="a1"/>
                <apex:commandButton value="/" action="{!devide}" rerender="a1"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

****
This above code working fine for multiplication and devide, however, getting error for addition and substract. Can someone please help me with the basics and code.

Here are the errors;
Attempt to de-reference a null object
Error is in expression '{!addition}' in component <apex:commandButton> in page calcipage: Class.Calci_extension.addition: line 14, column 1

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

Controll is for multiplication and Device
Extension is for addition and substraction.

Can someone help please?
 
How to insert product and pricebook under opportunity using apex code through Anonymous window.

On a standard Salesforce edit page, when the save button is clicked, the button immediately grays out and prevents the user from clicking the button multiple times.  I'm trying to get the same effect on a VFP but I am having no luck.  Has anybody already done this?  I don't know if it's pertinent, but my save button is calling a method called Save in a custom controller.

 

 

<apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save" id="saveBtn" /> </apex:pageBlockButtons>

 

 

 

  • March 02, 2009
  • Like
  • 0