+ Start a Discussion
Ben Merton 15Ben Merton 15 

Arithmetic expressions must use numeric arguments at line 45 column 50

I am trying to do a multiplication between a string and a method called using the dot notation:

indent.Indent_Quantity__c = item.Quantity__c*woquantity;

It is saying that "Arithmetic expressions must use numeric arguments

Can you help?

Full code below...
 
public class CreateIndentController{
    string workOrderId;
    string productId;
    string woquantity;

    public CreateIndentController()
    {
        workOrderId = ApexPages.currentPage().getParameters().get('id');
        productId = ApexPages.currentPage().getParameters().get('productId');
        woquantity = ApexPages.currentPage().getParameters().get('quantity');
        System.debug('Product ID 1' + productId);
        System.debug('Work Order ID 1' + workorderId);
    }
    public pageReference onLoad()
    {
               
                List<Material_Request__c> indents = new List<Material_Request__c>();
        for (BOM_Item__c item : bomItems)
        {
            Material_Request__c indent = new Material_Request__c();
            indent.Work_Order__c = workOrderId;
            indent.Indent_Quantity__c = item.Quantity__c*woquantity;
            indent.Good_Service__c = item.GSI_No__c;
            indents.add(indent);
        }
        if (indents.size() > 0)
        {
            insert indents;
        }
        return new PageReference('/' + workOrderId);
    }
}

 
Best Answer chosen by Ben Merton 15
Waqar Hussain SFWaqar Hussain SF
public class CreateIndentController{
    string workOrderId;
    string productId;
    string woquantity;

    public CreateIndentController()
    {
        workOrderId = ApexPages.currentPage().getParameters().get('id');
        productId = ApexPages.currentPage().getParameters().get('productId');
        woquantity = ApexPages.currentPage().getParameters().get('quantity');
        System.debug('Product ID 1' + productId);
        System.debug('Work Order ID 1' + workorderId);
    }
    public pageReference onLoad()
    {
               
                List<Material_Request__c> indents = new List<Material_Request__c>();
        for (BOM_Item__c item : bomItems)
        {
            Material_Request__c indent = new Material_Request__c();
            indent.Work_Order__c = workOrderId;
            indent.Indent_Quantity__c = item.Quantity__c*integer.valueOf(woquantity);
            indent.Good_Service__c = item.GSI_No__c;
            indents.add(indent);
        }
        if (indents.size() > 0)
        {
            insert indents;
        }
        return new PageReference('/' + workOrderId);
    }
}

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try to change woquantity from String to Integer.
 
public class CreateIndentController{
    string workOrderId;
    string productId;
    String woquantity;

    public CreateIndentController()
    {
        workOrderId = ApexPages.currentPage().getParameters().get('id');
        productId = ApexPages.currentPage().getParameters().get('productId');
        woquantity = ApexPages.currentPage().getParameters().get('quantity');
        System.debug('Product ID 1' + productId);
        System.debug('Work Order ID 1' + workorderId);
    }
    public pageReference onLoad()
    {
               
                List<Material_Request__c> indents = new List<Material_Request__c>();
        for (BOM_Item__c item : bomItems)
        {
            Material_Request__c indent = new Material_Request__c();
            indent.Work_Order__c = workOrderId;
			Integer   =  Integer.valueOf(woquantity); 
            indent.Indent_Quantity__c = item.Quantity__c * wq;
            indent.Good_Service__c = item.GSI_No__c;
            indents.add(indent);
        }
        if (indents.size() > 0)
        {
            insert indents;
        }
        return new PageReference('/' + workOrderId);
    }
}
Please let us know if this will help you
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_integer.htm

 
Waqar Hussain SFWaqar Hussain SF
public class CreateIndentController{
    string workOrderId;
    string productId;
    string woquantity;

    public CreateIndentController()
    {
        workOrderId = ApexPages.currentPage().getParameters().get('id');
        productId = ApexPages.currentPage().getParameters().get('productId');
        woquantity = ApexPages.currentPage().getParameters().get('quantity');
        System.debug('Product ID 1' + productId);
        System.debug('Work Order ID 1' + workorderId);
    }
    public pageReference onLoad()
    {
               
                List<Material_Request__c> indents = new List<Material_Request__c>();
        for (BOM_Item__c item : bomItems)
        {
            Material_Request__c indent = new Material_Request__c();
            indent.Work_Order__c = workOrderId;
            indent.Indent_Quantity__c = item.Quantity__c*integer.valueOf(woquantity);
            indent.Good_Service__c = item.GSI_No__c;
            indents.add(indent);
        }
        if (indents.size() > 0)
        {
            insert indents;
        }
        return new PageReference('/' + workOrderId);
    }
}
This was selected as the best answer