1

Controller:

public void geterp(string nicpn){
        // local variables
            String Accountcode; 
            Quote__c quoteWithAccountCode;
            Quote__c  langaugetranslation;
            string PartNic;
            string PartDescription ;
            string PartStock;
            string PartDescriptionUK;
            string PartClientPNREF;
            //Capturing Quote id


                    getRes1.GetInfoResult= soap.GetInfo(nicpn,'6f50456b91ef8ec5123e9c9600380ed5');
                }catch(Exception e){ 
                }
            }
            String XMLString;
            if(Test.isRunningTest()==True){
                 XMLString='<RESULT><PARTNUMBER>0F12</PARTNUMBER><DESCRIPTION>Boîtier série\'s 0F 12 pts</DESCRIPTION><DESCRIPTIONUK>housing serie\'s OF 12pts</DESCRIPTIONUK><STOCK>43382</STOCK><CLIENTPNS></CLIENTPNS></RESULT>';
            }else{
                 XMLString = getRes1.GetInfoResult;
            }
          //Getting the values from xml String
          if(XMLString!=null){
              Dom.Document doc = new Dom.Document();
                doc.load(XMLString);
                dom.XmlNode node=doc.getRootElement();
                //Condition to check the responce without error 
                if(node.getChildElements()[0].getName() != 'ERROR'){
                    PartNicomatic=node.getChildElement('PARTNUMBER',null).getText();
                    PartDescription=  node.getChildElement('DESCRIPTION',null).getText();
                    PartDescriptionUK=node.getChildElement('DESCRIPTIONUK',null).getText();
                    PartStock= node.getChildElement('STOCK',null).getText();
                    //Iterating the child elements
                     for(dom.XmlNode child:node.getChildElements()){
                        if(child.getName() =='CLIENTPNS'){
                        //iterating the grand child elements
                            for(dom.XmlNode gchild:child.getChildElements()){
                                if(gchild .getName() == 'CLIENTPN'){
                                    //Iterating the grand grand child elements
                                    for(dom.XmlNode ggchild:gchild.getChildElements()){
                                        if(ggchild .getName() == 'CLIENTPNREF'){
                                            PartClientPNREF=ggchild.getText();
                                        }
                                    }//End of for loop
                                }//End of if
                            }//End of for loop
                        }//End of if
                    }//End of for loop
                 }//End of if condition
             }//End of if
        }//End of method

    public quoteController(){
             Quote_line_item__c acc= new Quote_line_item__c();
             acc.Client_P_N__c=geterp(acc.Name).PartClientPNREF;
             acc.desc__c=geterp(acc.Name).PartDescription;
             acc.stock__c=geterp(acc.Name).Partstock;
             acclist.add(acc);  
          }

Visualforce page :

<apex:column headerValue="Nic P/N"><apex:inputField value="{!a.Name}" id="Name" style="width:110px"  StyleClass="AutoPin"  /><br/>
        <apex:commandlink Value="Fetch details" action="{!geterp}" rerender="wtable">
                       <apex:param assignTo="{!nicpn}" value="{!a.Name}" Name="parentname777"/>
                       </apex:commandlink>
      </apex:column>

I am passing the input value nicpn to get the details from ERP. I am retrieving partclient, partdescription and partstock.

I want to pass the values to the controller. How can I pass the values to controller.

I want to equate nicpn to acc.Name and I want to equate the value related value to related field

acc.Client_P_N__c=geterp(acc.Name).PartClientPNREF;
             acc.desc__c=geterp(acc.Name).PartDescription;
             acc.stock__c=geterp(acc.Name).Partstock;

quoteController Compile Error: Initial term of field expression must be a concrete SObject: void

2 Answers 2

1

geterp doesn't return a value, so you can't geterp(acc.Name).PartDescription. You can't just arbitrarily refer to any local function variable from outside that function. Most likely, you'll probably want to return a class that encapsulates all this data, or, if that's the only parameter you need, just return that one value. For example, you might do this:

public class LookupResult {
    public String PartNic, PartDescription, ...;
}
public LookupResult geterp(String nicpn) {
    LookupResult result = new LookupResult();
    // process xml here, assign values to result variable, omitted for brevity
    return result;
}

However, this will also affect this function's ability to be an action method, because action methods must return nothing (void) or a reference to a new page (ApexPages.PageReference). It's not a big deal, as you'll just have to move that logic to a different function.

Depending on exactly what you want to do, you'll probably want to make a LookupResult class member you can refer to, or a list thereof if you want to be able to show multiple results.

2
  • 4 split seconds :) Jul 3, 2015 at 11:21
  • 3
    Great minds think alike. We can't help it.
    – sfdcfox
    Jul 3, 2015 at 11:23
1

Your geterp method is void which means it doesn't return anything, but you're trying to reference variables inside the method.

Easiest way would be to create a wrapper class for all your required fields that you want to return to the caller method. So modify your geterp method and change it's return type, as well as create a wrapper class:

public class ERPResult
{
    public String PartClientPNREF;
    public String PartDescription;
    public String Partstock;
    // any other fields that you need to reference later
}

public ERPResult geterp(string nicpn)
{
    // your exising code here

    // add this at the bottom
    ERPResult result = new ERPResult ();
    result.PartClientPNREF = PartClientPNREF;
    result.PartDescription = PartDescription;
    result.Partstock = Partstock;

    return result;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .