You need to sign in to do that
Don't have an account?
Sanjeev SFDC
Please help me to deply this trigger
Hi I'm Trying deploy this trigger but it is showing exception can any one will help in this
Trigger
Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, convertNumbersToWords: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.convertNumbersToWords: line 55, column 1 Trigger.convertNumber...
Trigger
- trigger convertNumbersToWords on Transaction__c(before update) {
- String[] units=new String[]{'',' One',' Two',' Three',' Four',' Five',' Six',' Seven',' Eight',' Nine'};
- String[] teen=new String[]{' Ten',' Eleven',' Twelve',' Thirteen',' Fourteen',' Fifteen',' Sixteen',' Seventeen',' Eighteen',' Nineteen'};
- String[] tens=new String[]{' Twenty',' Thirty',' Fourty',' Fifty',' Sixty',' Seventy',' Eighty',' Ninety'};
- String[] maxs=new String[]{'','',' Hundred',' Thousand',' Lakh',' Crore'};
- For(Transaction__c T : trigger.new){
- if(t.Net_Supplementary_Amount__c >0){
- t.Net_Suppl_Interset_words__c =convert(integer.valueof(t.Net_Supplementary_Amount__c)) ;}
- else{
- t.Net_Suppl_Interset_words__c=' ';
- }
- t.Net_Supplementary_Brokerage_in_words__c =convert(integer.valueof(t.Net_Suppl_Brokerage__c)) ;
- t.Net_Interest_till_31st_March_in_words__c =convert(integer.valueof(t.Interest_pre_31_Mar__c));
- t.Net_Interest_post_31st_March_in_words__c =convert(integer.valueof(t.Intrst_post_31_Mar__c));
- t.Net_Brokerage_Amt_in_Words__c =convert(integer.valueof(t.Net_Brokerage_INR__c));
- }
- public string digitsToWord(string val){
- String Convertedtext='';
- list<string> Vallist=val.split('');
- string sss=Vallist.remove(0);
- for(integer i=Vallist.size()-1;i>=0;i--){
- integer index=integer.valueof(Vallist[i]);
- if(i==0&&index>1&&Vallist.size()>1)
- Convertedtext=tens[index-2]+Convertedtext;
- else if(i==0&&index==1&&Vallist.size()==2){
- integer sum=0;
- for(integer j=0;j<2;j++){
- sum=(sum*10)+integer.valueof(Vallist[j]);
- }
- return teen[sum-10];
- }
- else{
- if(index>0)
- Convertedtext=units[index]+Convertedtext;
- }
- }
- return Convertedtext;
- }
- public String convert(integer n) {
- if(n==0)
- return 'Zero';
- if(n>999999999)
- return 'More then 100 corers ';
- string amount=string.valueOf(n);
- integer positioning=1;
- boolean IsHundred=false;
- string Convertedtext='';
- while(amount.length()>0){
- if(positioning==1){
- if(amount.length()>=2){
- String C=amount.substring(amount.length()-2,amount.length());
- amount=amount.substring(0,amount.length()-2);
- Convertedtext+=digitsToWord(C);
- } else if(amount.length()==1){
- Convertedtext+=digitsToWord(amount);
- amount='';
- }positioning++;
- }
- else if(positioning==2){
- String C=amount.substring(amount.length()-1,amount.length());
- amount=amount.substring(0,amount.length()-1);
- if(Convertedtext.length()>0&&digitsToWord(C)!=''){
- Convertedtext=(digitsToWord(C)+maxs[positioning]+' and')+Convertedtext;
- IsHundred=true;
- }
- else{
- if(digitsToWord(C)!='')
- Convertedtext=(digitsToWord(C)+maxs[positioning])+Convertedtext;IsHundred=true;
- }
- positioning++;
- }
- else if(positioning>2){
- if(amount.length()>=2){
- String C=amount.substring(amount.length()-2,amount.length()); amount=amount.substring(0,amount.length()-2);
- if(!IsHundred&&Convertedtext.length()>0)
- Convertedtext=digitsToWord(C)+maxs[positioning]+' and'+Convertedtext;
- else{ if(digitsToWord(C)=='') {} else Convertedtext=digitsToWord(C)+maxs[positioning]+Convertedtext; }
- } else if(amount.length()==1){
- if(!IsHundred&&Convertedtext.length()>0)
- Convertedtext=digitsToWord(amount)+maxs[positioning]+' and'+Convertedtext;
- else{ if(digitsToWord(amount)==''){}else Convertedtext=digitsToWord(amount)+maxs[positioning]+Convertedtext; amount=''; }
- }
- positioning++;
- }
- }
- return Convertedtext;
- }
- }
Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, convertNumbersToWords: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.convertNumbersToWords: line 55, column 1 Trigger.convertNumber...
Is the error thrown only during deployment.?
If so I think some of your test calss is faling.
Let me know.
From the code I understand that the issue is because of the variable amount in line 55.
What actually happens is the amount variable some how assigned null. so when you use length() method on this null value it throws that error.
so to fix this issue add a if condition before while loop
line 54: If(amount!=null) // New line
line 55: while(amount.length()>0){
after this change run all the test calsses and try deploying it.
Thanks
Can you Mark it as best asnwer so that it would be helpful for others?