• Sachin Prasad 16
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi All,
I have created a field for Gifts Sold Final on product for stock management.
Such that when a product is added to opportunity its quantity is subtracted from Gifts Stock through a process builder which runs on every opportunity (Every time it's edited) that has line item and updates it's quantity in stock. It works fine for the first time with product quantity however if a product quantity is changed after adding it to opportunity the same is not updated in stock.
Please let me know if i have missed on something.
Thanks in advance.


User-added image
Process Builder
The object is opportunity product and criteria is everytime it's edited.

User-added image
Hi All,

I have written a class as below:

public class NumbersToWordsConversionClass {     
public string wordText { get; set; }    
public Integer numberVal { get; set; }     
// Action method to be called by button or link    
 public void convert() {         wordText = numberToEnglish(numberVal);     }     static String[] firstTwenty = new String[] { 'NIL','One','Two','Three','Four','Five','Six','Seven','Eight','Nine',             'Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Ninteen' };     static String[] tens = new String[] { '','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety' };     static String[] powers = new String[] { 'Crore','Lakh','Thousand','Hundred' };     static Integer[] thresholds = new Integer[] { 10000000, 100000, 1000, 100 };     
static String[] convert(Integer value) {         
String[] result = new String[0];         
Boolean less20 = value < 20, less100 = value < 100;       
  if(less20) {             result.add(firstTwenty[value]);         }
 else if(less100) {            
 Integer tenValue = value / 10, oneValue = Math.mod(value, 10);             
result.add(tens[tenValue]);             
if(oneValue > 0) {                 
result.add(firstTwenty[oneValue]);             }         }       
  if(less100) {             return result;         }         if(value > 0) {           
  for(Integer index = 0; index < thresholds.size(); index++) {               
  if(thresholds[index] <= value) {                 
    result.addAll(convert(value / thresholds[index]));                
     result.add(powers[index]);                 
    value = Math.mod(value, thresholds[index]);                 }             }         
    if(value > 0) {                 result.addAll(convert(value));             }         }   
      return result;     }     public static String numberToEnglish(Integer value) {         return value != null && value >= 0? String.join(convert(value),' '): '';     } }

however when i am trying to  write the trigger as below it is failing please assist;
getting error as
Compile Error: expecting a right parentheses, found 'Value' at line 5 column 101

trigger ConvertCurrencyToWords on Opportunity (before insert, before update)
 { for(Opportunity record: Trigger.new)
  { if(record.Amount != null)
  {
   record.Amount_in_Words__c = NumbersToWordsConversionClass.numberToEnglish(record.Amount.‌​integer Value());
   }
   }
   }
Hi All,

I have written a class as below:

public class NumbersToWordsConversionClass {     
public string wordText { get; set; }    
public Integer numberVal { get; set; }     
// Action method to be called by button or link    
 public void convert() {         wordText = numberToEnglish(numberVal);     }     static String[] firstTwenty = new String[] { 'NIL','One','Two','Three','Four','Five','Six','Seven','Eight','Nine',             'Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Ninteen' };     static String[] tens = new String[] { '','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety' };     static String[] powers = new String[] { 'Crore','Lakh','Thousand','Hundred' };     static Integer[] thresholds = new Integer[] { 10000000, 100000, 1000, 100 };     
static String[] convert(Integer value) {         
String[] result = new String[0];         
Boolean less20 = value < 20, less100 = value < 100;       
  if(less20) {             result.add(firstTwenty[value]);         }
 else if(less100) {            
 Integer tenValue = value / 10, oneValue = Math.mod(value, 10);             
result.add(tens[tenValue]);             
if(oneValue > 0) {                 
result.add(firstTwenty[oneValue]);             }         }       
  if(less100) {             return result;         }         if(value > 0) {           
  for(Integer index = 0; index < thresholds.size(); index++) {               
  if(thresholds[index] <= value) {                 
    result.addAll(convert(value / thresholds[index]));                
     result.add(powers[index]);                 
    value = Math.mod(value, thresholds[index]);                 }             }         
    if(value > 0) {                 result.addAll(convert(value));             }         }   
      return result;     }     public static String numberToEnglish(Integer value) {         return value != null && value >= 0? String.join(convert(value),' '): '';     } }

however when i am trying to  write the trigger as below it is failing please assist;
getting error as
Compile Error: expecting a right parentheses, found 'Value' at line 5 column 101

trigger ConvertCurrencyToWords on Opportunity (before insert, before update)
 { for(Opportunity record: Trigger.new)
  { if(record.Amount != null)
  {
   record.Amount_in_Words__c = NumbersToWordsConversionClass.numberToEnglish(record.Amount.‌​integer Value());
   }
   }
   }