Guest User

Untitled

a guest
Dec 12th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <apex:page standardController="Account" extensions="myaccountcontroller">
  2. <apex:form >
  3. <apex:pagemessages ></apex:pagemessages>
  4. <apex:commandButton value="Save" action="{!Save}"/>
  5. </apex:form>
  6. </apex:page>
  7.  
  8. public class myaccountcontroller
  9. {
  10. public string accId {get;set;}
  11. public String finalamount {get;set;}
  12.  
  13. public myaccountcontroller(ApexPages.StandardController sc)
  14. {
  15. accId = ApexPages.CurrentPage().getParameters().get('Id');
  16.  
  17. doCalculation();
  18. }
  19.  
  20. public void doCalculation()
  21. {
  22. Account AccObj = [SELECT Id,Name,Amount__c,Total_Amount__c FROM Account WHERE Id=:accId ];
  23. system.debug('TotalAmount ###:'+AccObj.Total_Amount__c );
  24. try{
  25. finalamount = String.ValueOf(AccObj.Amount__c/0);
  26. system.debug('finalamount###:'+finalamount);
  27. }catch(Exception e)
  28. {
  29. if(e.getMessage() == 'System.NullPointerException: Attempt to de-reference a null object')
  30. {
  31.  
  32. ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Unite Price should not be empty'));
  33. }
  34. }
  35. }
  36.  
  37.  
  38. }
Add Comment
Please, Sign In to add comment