• Robin Lindemann 14
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
So, I found and updated the code below to meet our needs.  It works perfectly, EXCEPT for round values of hundred thousands.  If the number is $435,000 - it translates to Four Hundred Thirty Five Dollars.  If the number is $400,000, however, it only shows Four Hundred Dollars.

I think the issue is around line 122 - 128 (where the hundred thousands are calculated)  I added bold font to highlight it.  I've tried everything I can think of, but can't get it to work both ways.  I've shown this to two colleagues and they are also stumped.  What am I missing?

public class NumberTOWordService {

    // Call this method with Number to convert
    public static String getDollars(Decimal num) {

        Decimal junkVal = num;
        Decimal junkValCent = junkVal - Math.floor(junkVal);
        junkVal = Math.floor(junkVal);

        String obStr = junkVal.toPlainString();
        String[] numReversed = obStr.split('');
        String[] actnumber = reverse(numReversed);
        String firstHalf = convertInWords(numReversed, actnumber);

        Integer tmp = Math.round(junkValCent * 100);
        junkValCent = (Decimal)tmp / 100; System.debug('jj :' + junkValCent);
        String CentStr = junkValCent.toPlainString();
        String secondHalf;
        if (CentStr == '0') {
            secondHalf = '';
        } else if (CentStr.length() != 4) {
            CentStr = CentStr + '0';
            CentStr = CentStr.substring(2);
            String [] numReversedCent = CentStr.split('');
            String[] actnumberCent = reverse(numReversedCent);
            secondHalf = convertInWords(numReversedCent, actnumberCent);
        } else {
            CentStr = CentStr.substring(2);
            String [] numReversedCent = CentStr.split('');
            String[] actnumberCent = reverse(numReversedCent);
            secondHalf = convertInWords(numReversedCent, actnumberCent);
        }

        String SumOFHalves = '';

        if (secondHalf.length() > 4) {
            firstHalf = firstHalf.replace('Only', 'Dollars And ');
            secondHalf = secondHalf.replace('Only', 'Cents');
            SumOFHalves = firstHalf + secondHalf;
        } else {
            firstHalf = firstHalf.replace('Only', 'Dollars');
            SumOFHalves = firstHalf;
        }

        // IF amount has any value
        if (SumOFHalves.length() > 5) {
            return SumOFHalves;
        } else {
            return '';
        }
    }
    // Method reverse the number
    public static List<String> reverse(List<String> strToRev) {
        List<String> revList = new List<String>();
        for (Integer i = strToRev.size() - 1; i >= 0; i--) {
            revList.add(strToRev.get(i));
        }
        revList.add('');
        return revList;
    }

    public static String convertInWords(String[] numRev, String[] actnum) {
        List<String> iWords = new List<String> {'Zero', ' One', ' Two', ' Three', ' Four', ' Five', ' Six', ' Seven', ' Eight', ' Nine'};
        List<String> ePlace = new List<String> {' Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'};
        List<String> tensPlace = new List<String> {'dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety' };

        Integer iWordsLength = numRev.size();
        String totalWords = '';
        List<String> inWords = new List<String>();
        for (Integer k = 0; k < iWordsLength; k++) {
            inWords.add('');
        }
        String finalWord = '';
        Integer j = 0;

        // Main For loop
        for (Integer i = 0; i < iWordsLength; i++) {

            if (i == 0) {
                if (actnum[i] == '0' || actnum[i + 1] == '1') {
                    inWords[j] = '';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
                inWords[j] = inWords[j] + ' Only';
            } else if (i == 1) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }
            } else if (i == 2) {
                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i - 1] != '0' && actnum[i - 2] != '0') {
                    inWords[j] = iWords[Integer.valueof(actnum[i])] + ' Hundred and';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])] + ' Hundred';
                }
            } else if (i == 3) {
                if (actnum[i] == '0' || actnum[i + 1] == '1') {
                    inWords[j] = '';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
                if (actnum[i + 1] != '0' || Integer.valueof(actnum[i]) > 0) {
                    inWords[j] = inWords[j] + ' Thousand';
                }
            } else if (i == 4) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }

            } else if (i == 5) {
                if (actnum[i] == '0' || actnum[i + 1] == '1') {
                    inWords[j] = '';
              } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
               if (actnum[i + 1] != '0' || Integer.valueof(actnum[i]) > 0) {
                inWords[j] = inWords[j] + ' Hundred';
               }
       
        
            } else if (i == 6) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }

            } else if (i == 7) {
                if (actnum[i] == '0' || actnum[i + 1] == '1' ) {
                    inWords[j] = '';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
                inWords[j] = inWords[j] + ' 10 Million';
            } else if (i == 8) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }

            }

            j++;
        }
        // End of For loop

        // Reverse the List
        inWords = reverse(inWords);

        for (Integer i = 0; i < inWords.size(); i++) {
            finalWord += inWords[i];
        }

        return finalWord;
    }


}
I've been updating some legacy code and it was working perfectly, until I added another product, just now. 

This is a custom VF page (used as a Quick action) that allows the user to place an order from the Contact record.  Each item in the Quick action/VF page has a box next to it for the numeric qty.  It seems that the VF page is not passing the quantity into the Controller, because I keep getting the following message:

Apex script unhandled exception by user/organization: 005o0000003MzSZ/00D4B0000009W1g Source organization: 00Do0000000JFHN (null) Visualforce Page: /apex/ContactOrderCreation1
 
caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Can't save order products with quantities of zero: [Quantity]
 
Class.ContactOrderCreationController.saveOrder: line 162, column 1

I have gone over and over the code, and I'm sure it's something trivial.  I went back and, instead of typing the new sections of code, I copied/pasted/updated them.  Still, no luck.

I have to deploy this code tomorrow, so have commented out the parts for the new product.  I have already confirmed the product code is accurate, the product is active and is in the Standard price book with the other products.
VF Page



<apex:page standardController="Contact"
           extensions="ContactOrderCreationController"
           showHeader="false"
           sidebar="false"
           standardStylesheets="true"
           docType="html-5.0">
  <apex:stylesheet value="{!URLFOR($Resource.CustomAction,'onestarter/icons.css')}"/>
  <apex:stylesheet value="{!URLFOR($Resource.CustomAction,'onestarter/styles.css')}"/>
  <apex:stylesheet value="{!URLFOR($Resource.CustomAction,'onestarter/OneStarter.css')}"/>
  <apex:includeScript value="{!URLFOR($Resource.CustomAction,'jquery-1.11.0.min.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.CustomAction,'onestarter/jquery.onestarter.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.CustomAction,'orderCreation.js')}"/>
  <apex:includeScript value="/canvas/sdk/js/publisher.js" />
  <div id="one-app">
    <apex:pageMessages id="pageMessages" />
    <apex:form >
      <apex:pageBlock id="formBlock">
        <apex:pageBlockButtons location="bottom" >
          <apex:commandButton value="Save"
                              action="{!saveOrder}"
                              rerender="pageMessages, formBlock"
                              oncomplete="afterRerender();" />
        </apex:pageBlockButtons>
        <apex:pageBlockSection columns="1" >
          
          <apex:outputField value="{!newOrder.AccountId}" />
          <apex:outputField value="{!newOrder.Fulfillment_For__c}" />
                    
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="quantityField"
                              value="L Bond Client Kit Quantity" />
            <apex:input value="{!clientQuantity}"
                        id="quantityField" />
          </apex:pageBlockSectionItem>
            
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="advisorQuantity"
                              value="L Bond Advisor Kit Quantity" />
            <apex:input value="{!advisorQuantity}"
                        id="advisorQuantity" />
          </apex:pageBlockSectionItem>
            
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="policykitQuantity"
                              value="L Bond RIA Kit Quantity" />
            <apex:input value="{!policykitQuantity}"
                        id="policykitQuantity" />
          </apex:pageBlockSectionItem> 
            
          <!-- <apex:pageBlockSectionItem >
                <apex:outputLabel for="LCXAgentKitQty"
                              value="LCX Agent Kit Quantity" />
                <apex:input value="{!LCXAgentKitQty}"
                                    id="LCXAgentKitQty" /> 
            </apex:pageBlockSectionItem> -->
            
           <apex:pageBlockSectionItem >
                <apex:outputLabel for="policySalivaKitQty"
                              value="GWG Policy Saliva Kit Quantity" />
                <apex:input value="{!policySalivaKitQty}"
                                    id="policySalivaKitQty" />
          </apex:pageBlockSectionItem>
          
          <apex:pageBlockSectionItem >
                <apex:outputLabel for="youSuranceSalivaKitQty"
                              value="YouSurance Saliva Kit Quantity" />
                <apex:input value="{!youSuranceSalivaKitQty}"
                                    id="youSuranceSalivaKitQty" />
          </apex:pageBlockSectionItem>
                
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="GelPenQty"
                              value="Gel Pen Quantity" />
                <apex:input value="{!GelPenQty}"
                                    id="GelPenQty" />
            </apex:pageBlockSectionItem>
                       
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="description"
                              value="Other (Description/Qty)" />
                <apex:inputTextArea value="{!description}"
                                    id="description" />
            </apex:pageBlockSectionItem>
            
                  
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="shipment"
                                value="ShipmentService" />
                <apex:selectList id="shipment" value="{!newOrder.Shipment_Service__c}" size="2">
                    <apex:selectOption itemValue="" itemLabel="--None--"/>
                    <apex:selectOption itemValue="Courier" itemLabel="Courier"/>
                    <apex:selectOption itemValue="UPS Ground" itemLabel="UPS Ground" html-selected="selected"/>
                    <apex:selectOption itemValue="UPS Next Day Air A.M." itemLabel="UPS Next Day Air A.M."/>
                    <apex:selectOption itemValue="UPS Next Day Air" itemLabel="UPS Next Day Air"/>
                    <apex:selectOption itemValue="UPS Next Day Air Saver" itemLabel="UPS Next Day Air Saver"/>
                    <apex:selectOption itemValue="UPS 2nd Day Air A.M." itemLabel="UPS 2nd Day Air A.M."/>
                    <apex:selectOption itemValue="UPS 2nd Day Air" itemLabel="UPS 2nd Day Air"/>
                    <apex:selectOption itemValue="UPS 3 Day Select" itemLabel="UPS 3 Day Select"/>
                    <apex:selectOption itemValue="USPS" itemLabel="USPS"/>    
                </apex:selectList>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
  </div>
  <apex:outputpanel rendered="false">
    {!Contact.Id}
    {!Contact.Accountid}
  </apex:outputpanel>
</apex:page>
 
Controller Class

public with sharing class ContactOrderCreationController
{
    private static final String ORDER_STATUS_TO_FULFILLMENT = 'Send to Fulfillment';
    private static final String ORDER_TYPE_KIT = 'Kit';
    private static final String ORDER_TYPE_OTHER = 'Other';
    private static final String ORDER_CREATED_MESSAGE = 'Your order has been created and sent to fulfillment.';
    private static final String QUANTITY_INVALID_MESSAGE = 'Quantity is invalid.';
    private static final String QUANTITY_MISSING_QUANTITY = 'Enter a quantity of least 1 for kits, or enter a description/qty for Other.';
    
    public Order newOrder { get; set; }
    public Integer clientQuantity { get; set; }
    public Integer advisorQuantity { get; set; }
    public Integer policykitQuantity {get; set;}
    public Integer policySalivaKitQty {get; set;}
    public Integer LCXAgentKitQty {get; set;}
    public Integer youSuranceSalivaKitQty {get; set;}
    public Integer GelPenQty {get; set;}
    public Boolean setTypeOther { get; set; }
    public Boolean setTypeKit {get; set; }
    public String description { get; set; }
    public String Status {get; set;}
    public String Shipment {get; set;}
    
    private Contact contact;
    
    public ContactOrderCreationController(ApexPages.StandardController ctr)
    {
        if (!Test.isRunningTest()) ctr.addFields(new List<String> {'Name', 'Email', 'Phone', 'MobilePhone', 'Account_Name__c', 'MailingStreet', 'MailingCity', 'MailingState', 'MailingPostalCode', 'MailingCountry'});
        this.contact = (Contact) ctr.getRecord();
        resetOrder();
    }
    
    public PageReference saveOrder()
    {
        if (this.clientQuantity == null) { this.clientQuantity = 0; }
        if (this.advisorQuantity == null) { this.advisorQuantity = 0; }
        if (this.policykitQuantity == null) { this.policykitQuantity = 0; }
        if (this.policySalivaKitQty == null) {this.policySalivaKitQty = 0; }
        if (this.LCXAgentKitQty == null) {this.LCXAgentKitQty = 0; }
        if (this.youSuranceSalivaKitQty == null) {this.youSuranceSalivaKitQty = 0; }
        if (this.GelPenQty == null) {this.GelPenQty = 0; }
        
        system.debug('clientQuantity: ' + clientQuantity +
                     ' advisorQuantity: ' + advisorQuantity +
                     'policykitQuantity: ' + policykitquantity +
                     policySalivaKitQty + ' policySalivaKitQty' +
                     youSuranceSalivaKitQty + ' youSuranceSalivaKitQty' +
                     GelPenQty + ' GelPenQty');
        
        if (this.clientQuantity == 0 &&
            this.advisorQuantity == 0 &&
            this.policykitQuantity == 0 &&
            this.policySalivaKitQty == 0 &&
            this.LCXAgentKitQty == 0 &&
            this.youSuranceSalivaKitQty == 0 &&
            this.GelPenQty == 0 &&
            this.description == ' ')
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, QUANTITY_MISSING_QUANTITY));
            return null;
        }
        
        if (this.clientQuantity < 0 ||
            this.advisorQuantity < 0 ||
            this.policykitQuantity < 0 ||
            this.policySalivaKitQty < 0 ||
            this.LCXAgentKitQty < 0 ||
            this.youSuranceSalivaKitQty < 0 ||
            this.GelPenQty < 0)
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, QUANTITY_INVALID_MESSAGE));
            return null;
        }
        
        if (this.clientQuantity > 0 ||
            this.advisorQuantity > 0 ||
            this.LCXAgentKitQty > 0 ||
            this.policykitQuantity > 0) newOrder.Type = 'Kit';
        else if (this.policySalivaKitQty > 0 ||
                 this.youSuranceSalivaKitQty > 0)  newOrder.Type = 'Saliva Kit';
        else if (this.GelPenQty >0) newOrder.Type = 'Promotional';
        else newOrder.Type = 'Other';
        
        this.newOrder.Name = Contact.Name + ' - ' + newOrder.Type;
        this.newOrder.Description = description;
        
        OrderItem oi;
        List<OrderItem> orderItems = new List<OrderItem>();
        
        Pricebook2 pb;
        
        List<Pricebook2> pbs = [SELECT Id, Name
                              FROM Pricebook2
                              WHERE Name = 'Standard Price Book'];
        
        For(Pricebook2 pb2:pbs)
        {
            pb = pb2;
        }
        
        
        
        List<PriceBookEntry> pbes = [SELECT Id, Product2.Name, Product2.ProductCode, Product2.Id, UnitPrice, Pricebook2.id,
                                     Pricebook2.Name
                                     FROM PriceBookEntry
                                     WHERE Product2.ProductCode IN ('GWG25PROMO2015','SKitYSBox','SKitPolicy', 'LCXAgentKit',
                                                                    'LB2riaKIT2018','LBadvKIT2018', 'LB2CKIT2018')];
        this.newOrder.Pricebook2Id = pb.Id;
        
        Map<String, Decimal> UnitQtybyProductCode = new Map<String, Decimal>();
        Map<String, Id> IDbyProductCode = new Map<String, Id>();      
        
        For (PriceBookEntry pbe:pbes)
        {
            UnitQtybyProductCode.put(pbe.product2.productCode,pbe.UnitPrice);
            IDbyProductCode.put(pbe.product2.productCode,pbe.Id);
        }
        
        insert this.newOrder;
        
        if (clientQuantity > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LB2CKIT2018'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.clientQuantity,
                                         UnitPrice = UnitQtybyProductCode.containskey('LB2CKIT2018') ? UnitQtybyProductCode.get('LB2CKIT2018') : 0));
        
        if (advisorQuantity > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LBadvKIT2018'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.advisorQuantity,
                                         UnitPrice = UnitQtybyProductCode.containskey('LBadvKIT2018') ? UnitQtybyProductCode.get('LBadvKIT2018') : 0));
        
        if (policykitQuantity > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LB2riaKIT2018'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.policykitQuantity,
                                         UnitPrice = UnitQtybyProductCode.containskey('LB2riaKIT2018') ? UnitQtybyProductCode.get('LB2riaKIT2018') : 0));
        
        if (policySalivaKitQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('SKitPolicy'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.policySalivaKitQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('SKitPolicy') ? UnitQtybyProductCode.get('SKitPolicy') : 0));
        /**if (LCXAgentKitQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LCXAgentKit'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.policySalivaKitQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('LCXAgentKit') ? UnitQtybyProductCode.get('LCXAgentKit') : 0));**/
        
        if (youSuranceSalivaKitQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('SKitYSBox'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.youSuranceSalivaKitQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('SKitYSBox') ? UnitQtybyProductCode.get('SKitYSBox') : 0));
        
        if (GelPenQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('GWG25PROMO2015'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.GelPenQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('GWG25PROMO2015') ? UnitQtybyProductCode.get('GWG25PROMO2015') : 0));
        
        insert orderItems;
        
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, ORDER_CREATED_MESSAGE));
        
        resetOrder();
        return null;
    }
    
    private void resetOrder()
    {
        this.newOrder = new Order(Fulfillment_For__c = this.contact.Id,
                                  AccountId = this.contact.AccountId,
                                  Status = ORDER_STATUS_TO_FULFILLMENT,
                                  EffectiveDate = Date.today(),
                                  Type = ORDER_TYPE_KIT,
                                  Recipient__c = this.contact.Id,
                                  Recipient_Name__c = this.contact.Name,
                                  Recipient_Email__c = this.contact.Email,
                                  Recipient_Phone__c = (this.contact.Phone != null ? this.contact.Phone : this.contact.MobilePhone),
                                  Recipient_Company__c = this.contact.Account_Name__c,
                                  ShipToContactId = this.contact.Id,
                                  ShippingStreet = this.contact.MailingStreet,
                                  ShippingCity = this.contact.MailingCity,
                                  ShippingState = this.contact.MailingState,
                                  ShippingPostalCode = this.contact.MailingPostalCode,
                                  ShippingCountry = this.contact.MailingCountry
                                 );
        
        this.clientQuantity = null;
        this.advisorQuantity = null;
        this.policykitQuantity = null;
        this.LCXAgentKitQty = null;
        this.policySalivaKitQty = null;
        this.youSuranceSalivaKitQty = null;
        this.GelPenQty = null;
        this.setTypeOther = false;
        this.setTypeKit = false;
        this.description = '';
        this.status = '';
        this.shipment = '';
    }
}
Thanks for any help you are able to provide.  I have left those sections commented out, for your review.  It is the LCX Agent Kit that is the issue.

 
OK, I am stuck.

I've been tasked with writing a class/trigger that will put a new/updated user into a Public Group, if they have a certain profile.  I've been working on this for some time, with varying results.   I found an example from this forum of a trigger and class that allowed me to put the user into the group.  It worked!  But there was not a parameter for the profile requirement.  I found one and tried to add it.  No errors happen, and the new user is created, but they are not placed into the public group.  

The odd thing is, when I removed the new line of code and tried again, it still doesn't put the user in the public group.

This is just the first part of the task I've been given.  I'm also supposed to remove users from the PG, when they are deactivated, or moved to a different profile.

Any suggestions?
//Class references trigger AddintoPublicGroup in order to add users automatically to public groups.
public class AddUser{

@future
public static void AddToGroups(Set<Id> userIds)
{
 //Get the group that the user should be added to
Group g=[select Id from Group Where DeveloperName='Broker_Dealer_Portal_Users'];

 List<User> users=[Select Id,Name from user Where Id IN :userIds];
 
 List<GroupMember>listGroupMember =new List<GroupMember>();  
 // for loop add each user to public group if profile is Broker Dealer
 for (User user : users){
     If (User.profile.name.equals('Community Login User - Broker Dealer')){
      GroupMember gm= new GroupMember(); 
      gm.GroupId=g.id;
      gm.UserOrGroupId = user.id;
      listGroupMember.add(gm);   
     } 
 } 
 insert listGroupMember;
}
}
 
trigger addintoPublicgroup on User (after insert) {
   AddUser.AddToGroups(trigger.newMap.keySet());

}
Thanks for any help/advice you are able to provide.
Robin
 
So, I found and updated the code below to meet our needs.  It works perfectly, EXCEPT for round values of hundred thousands.  If the number is $435,000 - it translates to Four Hundred Thirty Five Dollars.  If the number is $400,000, however, it only shows Four Hundred Dollars.

I think the issue is around line 122 - 128 (where the hundred thousands are calculated)  I added bold font to highlight it.  I've tried everything I can think of, but can't get it to work both ways.  I've shown this to two colleagues and they are also stumped.  What am I missing?

public class NumberTOWordService {

    // Call this method with Number to convert
    public static String getDollars(Decimal num) {

        Decimal junkVal = num;
        Decimal junkValCent = junkVal - Math.floor(junkVal);
        junkVal = Math.floor(junkVal);

        String obStr = junkVal.toPlainString();
        String[] numReversed = obStr.split('');
        String[] actnumber = reverse(numReversed);
        String firstHalf = convertInWords(numReversed, actnumber);

        Integer tmp = Math.round(junkValCent * 100);
        junkValCent = (Decimal)tmp / 100; System.debug('jj :' + junkValCent);
        String CentStr = junkValCent.toPlainString();
        String secondHalf;
        if (CentStr == '0') {
            secondHalf = '';
        } else if (CentStr.length() != 4) {
            CentStr = CentStr + '0';
            CentStr = CentStr.substring(2);
            String [] numReversedCent = CentStr.split('');
            String[] actnumberCent = reverse(numReversedCent);
            secondHalf = convertInWords(numReversedCent, actnumberCent);
        } else {
            CentStr = CentStr.substring(2);
            String [] numReversedCent = CentStr.split('');
            String[] actnumberCent = reverse(numReversedCent);
            secondHalf = convertInWords(numReversedCent, actnumberCent);
        }

        String SumOFHalves = '';

        if (secondHalf.length() > 4) {
            firstHalf = firstHalf.replace('Only', 'Dollars And ');
            secondHalf = secondHalf.replace('Only', 'Cents');
            SumOFHalves = firstHalf + secondHalf;
        } else {
            firstHalf = firstHalf.replace('Only', 'Dollars');
            SumOFHalves = firstHalf;
        }

        // IF amount has any value
        if (SumOFHalves.length() > 5) {
            return SumOFHalves;
        } else {
            return '';
        }
    }
    // Method reverse the number
    public static List<String> reverse(List<String> strToRev) {
        List<String> revList = new List<String>();
        for (Integer i = strToRev.size() - 1; i >= 0; i--) {
            revList.add(strToRev.get(i));
        }
        revList.add('');
        return revList;
    }

    public static String convertInWords(String[] numRev, String[] actnum) {
        List<String> iWords = new List<String> {'Zero', ' One', ' Two', ' Three', ' Four', ' Five', ' Six', ' Seven', ' Eight', ' Nine'};
        List<String> ePlace = new List<String> {' Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'};
        List<String> tensPlace = new List<String> {'dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety' };

        Integer iWordsLength = numRev.size();
        String totalWords = '';
        List<String> inWords = new List<String>();
        for (Integer k = 0; k < iWordsLength; k++) {
            inWords.add('');
        }
        String finalWord = '';
        Integer j = 0;

        // Main For loop
        for (Integer i = 0; i < iWordsLength; i++) {

            if (i == 0) {
                if (actnum[i] == '0' || actnum[i + 1] == '1') {
                    inWords[j] = '';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
                inWords[j] = inWords[j] + ' Only';
            } else if (i == 1) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }
            } else if (i == 2) {
                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i - 1] != '0' && actnum[i - 2] != '0') {
                    inWords[j] = iWords[Integer.valueof(actnum[i])] + ' Hundred and';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])] + ' Hundred';
                }
            } else if (i == 3) {
                if (actnum[i] == '0' || actnum[i + 1] == '1') {
                    inWords[j] = '';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
                if (actnum[i + 1] != '0' || Integer.valueof(actnum[i]) > 0) {
                    inWords[j] = inWords[j] + ' Thousand';
                }
            } else if (i == 4) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }

            } else if (i == 5) {
                if (actnum[i] == '0' || actnum[i + 1] == '1') {
                    inWords[j] = '';
              } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
               if (actnum[i + 1] != '0' || Integer.valueof(actnum[i]) > 0) {
                inWords[j] = inWords[j] + ' Hundred';
               }
       
        
            } else if (i == 6) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }

            } else if (i == 7) {
                if (actnum[i] == '0' || actnum[i + 1] == '1' ) {
                    inWords[j] = '';
                } else {
                    inWords[j] = iWords[Integer.valueof(actnum[i])];
                }
                inWords[j] = inWords[j] + ' 10 Million';
            } else if (i == 8) {

                if (actnum[i] == '0') {
                    inWords[j] = '';
                } else if (actnum[i] == '1') {
                    inWords[j] = ePlace[Integer.valueof(actnum[i - 1])];
                } else {
                    inWords[j] = tensPlace[Integer.valueof(actnum[i])];
                }

            }

            j++;
        }
        // End of For loop

        // Reverse the List
        inWords = reverse(inWords);

        for (Integer i = 0; i < inWords.size(); i++) {
            finalWord += inWords[i];
        }

        return finalWord;
    }


}
I've been updating some legacy code and it was working perfectly, until I added another product, just now. 

This is a custom VF page (used as a Quick action) that allows the user to place an order from the Contact record.  Each item in the Quick action/VF page has a box next to it for the numeric qty.  It seems that the VF page is not passing the quantity into the Controller, because I keep getting the following message:

Apex script unhandled exception by user/organization: 005o0000003MzSZ/00D4B0000009W1g Source organization: 00Do0000000JFHN (null) Visualforce Page: /apex/ContactOrderCreation1
 
caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Can't save order products with quantities of zero: [Quantity]
 
Class.ContactOrderCreationController.saveOrder: line 162, column 1

I have gone over and over the code, and I'm sure it's something trivial.  I went back and, instead of typing the new sections of code, I copied/pasted/updated them.  Still, no luck.

I have to deploy this code tomorrow, so have commented out the parts for the new product.  I have already confirmed the product code is accurate, the product is active and is in the Standard price book with the other products.
VF Page



<apex:page standardController="Contact"
           extensions="ContactOrderCreationController"
           showHeader="false"
           sidebar="false"
           standardStylesheets="true"
           docType="html-5.0">
  <apex:stylesheet value="{!URLFOR($Resource.CustomAction,'onestarter/icons.css')}"/>
  <apex:stylesheet value="{!URLFOR($Resource.CustomAction,'onestarter/styles.css')}"/>
  <apex:stylesheet value="{!URLFOR($Resource.CustomAction,'onestarter/OneStarter.css')}"/>
  <apex:includeScript value="{!URLFOR($Resource.CustomAction,'jquery-1.11.0.min.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.CustomAction,'onestarter/jquery.onestarter.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.CustomAction,'orderCreation.js')}"/>
  <apex:includeScript value="/canvas/sdk/js/publisher.js" />
  <div id="one-app">
    <apex:pageMessages id="pageMessages" />
    <apex:form >
      <apex:pageBlock id="formBlock">
        <apex:pageBlockButtons location="bottom" >
          <apex:commandButton value="Save"
                              action="{!saveOrder}"
                              rerender="pageMessages, formBlock"
                              oncomplete="afterRerender();" />
        </apex:pageBlockButtons>
        <apex:pageBlockSection columns="1" >
          
          <apex:outputField value="{!newOrder.AccountId}" />
          <apex:outputField value="{!newOrder.Fulfillment_For__c}" />
                    
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="quantityField"
                              value="L Bond Client Kit Quantity" />
            <apex:input value="{!clientQuantity}"
                        id="quantityField" />
          </apex:pageBlockSectionItem>
            
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="advisorQuantity"
                              value="L Bond Advisor Kit Quantity" />
            <apex:input value="{!advisorQuantity}"
                        id="advisorQuantity" />
          </apex:pageBlockSectionItem>
            
          <apex:pageBlockSectionItem >
            <apex:outputLabel for="policykitQuantity"
                              value="L Bond RIA Kit Quantity" />
            <apex:input value="{!policykitQuantity}"
                        id="policykitQuantity" />
          </apex:pageBlockSectionItem> 
            
          <!-- <apex:pageBlockSectionItem >
                <apex:outputLabel for="LCXAgentKitQty"
                              value="LCX Agent Kit Quantity" />
                <apex:input value="{!LCXAgentKitQty}"
                                    id="LCXAgentKitQty" /> 
            </apex:pageBlockSectionItem> -->
            
           <apex:pageBlockSectionItem >
                <apex:outputLabel for="policySalivaKitQty"
                              value="GWG Policy Saliva Kit Quantity" />
                <apex:input value="{!policySalivaKitQty}"
                                    id="policySalivaKitQty" />
          </apex:pageBlockSectionItem>
          
          <apex:pageBlockSectionItem >
                <apex:outputLabel for="youSuranceSalivaKitQty"
                              value="YouSurance Saliva Kit Quantity" />
                <apex:input value="{!youSuranceSalivaKitQty}"
                                    id="youSuranceSalivaKitQty" />
          </apex:pageBlockSectionItem>
                
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="GelPenQty"
                              value="Gel Pen Quantity" />
                <apex:input value="{!GelPenQty}"
                                    id="GelPenQty" />
            </apex:pageBlockSectionItem>
                       
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="description"
                              value="Other (Description/Qty)" />
                <apex:inputTextArea value="{!description}"
                                    id="description" />
            </apex:pageBlockSectionItem>
            
                  
            <apex:pageBlockSectionItem >
                <apex:outputLabel for="shipment"
                                value="ShipmentService" />
                <apex:selectList id="shipment" value="{!newOrder.Shipment_Service__c}" size="2">
                    <apex:selectOption itemValue="" itemLabel="--None--"/>
                    <apex:selectOption itemValue="Courier" itemLabel="Courier"/>
                    <apex:selectOption itemValue="UPS Ground" itemLabel="UPS Ground" html-selected="selected"/>
                    <apex:selectOption itemValue="UPS Next Day Air A.M." itemLabel="UPS Next Day Air A.M."/>
                    <apex:selectOption itemValue="UPS Next Day Air" itemLabel="UPS Next Day Air"/>
                    <apex:selectOption itemValue="UPS Next Day Air Saver" itemLabel="UPS Next Day Air Saver"/>
                    <apex:selectOption itemValue="UPS 2nd Day Air A.M." itemLabel="UPS 2nd Day Air A.M."/>
                    <apex:selectOption itemValue="UPS 2nd Day Air" itemLabel="UPS 2nd Day Air"/>
                    <apex:selectOption itemValue="UPS 3 Day Select" itemLabel="UPS 3 Day Select"/>
                    <apex:selectOption itemValue="USPS" itemLabel="USPS"/>    
                </apex:selectList>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
  </div>
  <apex:outputpanel rendered="false">
    {!Contact.Id}
    {!Contact.Accountid}
  </apex:outputpanel>
</apex:page>
 
Controller Class

public with sharing class ContactOrderCreationController
{
    private static final String ORDER_STATUS_TO_FULFILLMENT = 'Send to Fulfillment';
    private static final String ORDER_TYPE_KIT = 'Kit';
    private static final String ORDER_TYPE_OTHER = 'Other';
    private static final String ORDER_CREATED_MESSAGE = 'Your order has been created and sent to fulfillment.';
    private static final String QUANTITY_INVALID_MESSAGE = 'Quantity is invalid.';
    private static final String QUANTITY_MISSING_QUANTITY = 'Enter a quantity of least 1 for kits, or enter a description/qty for Other.';
    
    public Order newOrder { get; set; }
    public Integer clientQuantity { get; set; }
    public Integer advisorQuantity { get; set; }
    public Integer policykitQuantity {get; set;}
    public Integer policySalivaKitQty {get; set;}
    public Integer LCXAgentKitQty {get; set;}
    public Integer youSuranceSalivaKitQty {get; set;}
    public Integer GelPenQty {get; set;}
    public Boolean setTypeOther { get; set; }
    public Boolean setTypeKit {get; set; }
    public String description { get; set; }
    public String Status {get; set;}
    public String Shipment {get; set;}
    
    private Contact contact;
    
    public ContactOrderCreationController(ApexPages.StandardController ctr)
    {
        if (!Test.isRunningTest()) ctr.addFields(new List<String> {'Name', 'Email', 'Phone', 'MobilePhone', 'Account_Name__c', 'MailingStreet', 'MailingCity', 'MailingState', 'MailingPostalCode', 'MailingCountry'});
        this.contact = (Contact) ctr.getRecord();
        resetOrder();
    }
    
    public PageReference saveOrder()
    {
        if (this.clientQuantity == null) { this.clientQuantity = 0; }
        if (this.advisorQuantity == null) { this.advisorQuantity = 0; }
        if (this.policykitQuantity == null) { this.policykitQuantity = 0; }
        if (this.policySalivaKitQty == null) {this.policySalivaKitQty = 0; }
        if (this.LCXAgentKitQty == null) {this.LCXAgentKitQty = 0; }
        if (this.youSuranceSalivaKitQty == null) {this.youSuranceSalivaKitQty = 0; }
        if (this.GelPenQty == null) {this.GelPenQty = 0; }
        
        system.debug('clientQuantity: ' + clientQuantity +
                     ' advisorQuantity: ' + advisorQuantity +
                     'policykitQuantity: ' + policykitquantity +
                     policySalivaKitQty + ' policySalivaKitQty' +
                     youSuranceSalivaKitQty + ' youSuranceSalivaKitQty' +
                     GelPenQty + ' GelPenQty');
        
        if (this.clientQuantity == 0 &&
            this.advisorQuantity == 0 &&
            this.policykitQuantity == 0 &&
            this.policySalivaKitQty == 0 &&
            this.LCXAgentKitQty == 0 &&
            this.youSuranceSalivaKitQty == 0 &&
            this.GelPenQty == 0 &&
            this.description == ' ')
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, QUANTITY_MISSING_QUANTITY));
            return null;
        }
        
        if (this.clientQuantity < 0 ||
            this.advisorQuantity < 0 ||
            this.policykitQuantity < 0 ||
            this.policySalivaKitQty < 0 ||
            this.LCXAgentKitQty < 0 ||
            this.youSuranceSalivaKitQty < 0 ||
            this.GelPenQty < 0)
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, QUANTITY_INVALID_MESSAGE));
            return null;
        }
        
        if (this.clientQuantity > 0 ||
            this.advisorQuantity > 0 ||
            this.LCXAgentKitQty > 0 ||
            this.policykitQuantity > 0) newOrder.Type = 'Kit';
        else if (this.policySalivaKitQty > 0 ||
                 this.youSuranceSalivaKitQty > 0)  newOrder.Type = 'Saliva Kit';
        else if (this.GelPenQty >0) newOrder.Type = 'Promotional';
        else newOrder.Type = 'Other';
        
        this.newOrder.Name = Contact.Name + ' - ' + newOrder.Type;
        this.newOrder.Description = description;
        
        OrderItem oi;
        List<OrderItem> orderItems = new List<OrderItem>();
        
        Pricebook2 pb;
        
        List<Pricebook2> pbs = [SELECT Id, Name
                              FROM Pricebook2
                              WHERE Name = 'Standard Price Book'];
        
        For(Pricebook2 pb2:pbs)
        {
            pb = pb2;
        }
        
        
        
        List<PriceBookEntry> pbes = [SELECT Id, Product2.Name, Product2.ProductCode, Product2.Id, UnitPrice, Pricebook2.id,
                                     Pricebook2.Name
                                     FROM PriceBookEntry
                                     WHERE Product2.ProductCode IN ('GWG25PROMO2015','SKitYSBox','SKitPolicy', 'LCXAgentKit',
                                                                    'LB2riaKIT2018','LBadvKIT2018', 'LB2CKIT2018')];
        this.newOrder.Pricebook2Id = pb.Id;
        
        Map<String, Decimal> UnitQtybyProductCode = new Map<String, Decimal>();
        Map<String, Id> IDbyProductCode = new Map<String, Id>();      
        
        For (PriceBookEntry pbe:pbes)
        {
            UnitQtybyProductCode.put(pbe.product2.productCode,pbe.UnitPrice);
            IDbyProductCode.put(pbe.product2.productCode,pbe.Id);
        }
        
        insert this.newOrder;
        
        if (clientQuantity > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LB2CKIT2018'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.clientQuantity,
                                         UnitPrice = UnitQtybyProductCode.containskey('LB2CKIT2018') ? UnitQtybyProductCode.get('LB2CKIT2018') : 0));
        
        if (advisorQuantity > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LBadvKIT2018'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.advisorQuantity,
                                         UnitPrice = UnitQtybyProductCode.containskey('LBadvKIT2018') ? UnitQtybyProductCode.get('LBadvKIT2018') : 0));
        
        if (policykitQuantity > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LB2riaKIT2018'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.policykitQuantity,
                                         UnitPrice = UnitQtybyProductCode.containskey('LB2riaKIT2018') ? UnitQtybyProductCode.get('LB2riaKIT2018') : 0));
        
        if (policySalivaKitQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('SKitPolicy'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.policySalivaKitQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('SKitPolicy') ? UnitQtybyProductCode.get('SKitPolicy') : 0));
        /**if (LCXAgentKitQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('LCXAgentKit'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.policySalivaKitQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('LCXAgentKit') ? UnitQtybyProductCode.get('LCXAgentKit') : 0));**/
        
        if (youSuranceSalivaKitQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('SKitYSBox'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.youSuranceSalivaKitQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('SKitYSBox') ? UnitQtybyProductCode.get('SKitYSBox') : 0));
        
        if (GelPenQty > 0)
            orderItems.add(new OrderItem(PricebookEntryId = IdbyProductCode.get('GWG25PROMO2015'),
                                         OrderId = this.newOrder.Id,
                                         Quantity = this.GelPenQty,
                                         UnitPrice = UnitQtybyProductCode.containskey('GWG25PROMO2015') ? UnitQtybyProductCode.get('GWG25PROMO2015') : 0));
        
        insert orderItems;
        
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, ORDER_CREATED_MESSAGE));
        
        resetOrder();
        return null;
    }
    
    private void resetOrder()
    {
        this.newOrder = new Order(Fulfillment_For__c = this.contact.Id,
                                  AccountId = this.contact.AccountId,
                                  Status = ORDER_STATUS_TO_FULFILLMENT,
                                  EffectiveDate = Date.today(),
                                  Type = ORDER_TYPE_KIT,
                                  Recipient__c = this.contact.Id,
                                  Recipient_Name__c = this.contact.Name,
                                  Recipient_Email__c = this.contact.Email,
                                  Recipient_Phone__c = (this.contact.Phone != null ? this.contact.Phone : this.contact.MobilePhone),
                                  Recipient_Company__c = this.contact.Account_Name__c,
                                  ShipToContactId = this.contact.Id,
                                  ShippingStreet = this.contact.MailingStreet,
                                  ShippingCity = this.contact.MailingCity,
                                  ShippingState = this.contact.MailingState,
                                  ShippingPostalCode = this.contact.MailingPostalCode,
                                  ShippingCountry = this.contact.MailingCountry
                                 );
        
        this.clientQuantity = null;
        this.advisorQuantity = null;
        this.policykitQuantity = null;
        this.LCXAgentKitQty = null;
        this.policySalivaKitQty = null;
        this.youSuranceSalivaKitQty = null;
        this.GelPenQty = null;
        this.setTypeOther = false;
        this.setTypeKit = false;
        this.description = '';
        this.status = '';
        this.shipment = '';
    }
}
Thanks for any help you are able to provide.  I have left those sections commented out, for your review.  It is the LCX Agent Kit that is the issue.

 
Hello! I have built a custom clone button on contacts to only clone certain fields and not others. One of the fields I would like to carry over to the new contact is Account Name. My issue is that when the Account Name is carried to the new contact, it overrides the contact's mailing address fields to reflect the address of the Account. This is not always the case, as not all contacts work at the main account headquarters. I would like the mailing address fields of the existing contact to transfer to the mailing address fields of the new contact, without being overridden when different from the account address. Here is what I have currently:

https://na8.salesforce.com/003/e?
&con4={!Account.Name}
&con19street={!Contact.MailingStreet}
&con19city={!Contact.MailingCity}
&con19state={!Contact.MailingState}
&con19zip={!Contact.MailingPostalCode}
&con19country={!Contact.MailingCountry}
&00NC0000004j5vK={!Contact.Status__c}
&00NC0000004jI0b={!Contact.Prospect_or_Client__c}
&con6={!Contact.Department}
&CF00NC0000005LWEw={!Contact.Advisor_Consultant_Group_Name__c}
&00NC0000004jI0C={!Contact.Functional_Role__c}
&00NC0000005PrMV={!Contact.Advisor_AUM__c}
&00NC0000004jF12={!Contact.Office_Main_Phone__c}
&con11={!Contact.Fax}
&00NC0000004j5Wt={!Contact.Website__c}
&00NC0000005L4Zg={!Contact.Sales_Territory__c}
&00NC0000005LJHn={!Contact.Trip_Planning_Codes__c}
&00NC0000004jF4V={!Contact.Pre_Merger_Firm__c}
&00NC0000004j5m3={!Contact.Branch_Id_Number__c}
&00NC0000004j5m8={!Contact.Broker_Number__c}
&RecordType={!Contact.RecordTypeId}

Any guidance would be very much appreciated! Thanks!