function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hylim12hylim12 

Display field result in Visualforce

Hi all, i would need some help to display a list of result in list view (pageBlockTable)

 

i have a very simple VF page just to display result (retrieve from webservive in format [aaa;bbb;ccc;ddd;eee]) in list view after clicking a button.

 

this is my VF code:

<apex:page standardController="Contact" extensions="SalesforceDB" recordSetVar="contacts">
    <apex:sectionHeader title="External DB Conn" subtitle="Getting data from Local DB"/>
    <apex:form >
        <apex:pageBlock title="Policy Listing">
                <apex:pageBlockButtons >
                    <apex:commandButton value="Confirm" action="{!getDBInfo}" />
                    
                    <apex:pageBlockTable value = "??" var = "c">
                
                    </apex:pageBlockTable>
                
                </apex:pageBlockButtons>
            <apex:pageblocksection >
                <!--apex:pageBlockSectionItem -->
                    <!--apex:outputlabel value="{!'Label'}"></apex:outputlabel-->
                    <!--apex:inputText /-->
                <!--/apex:pageBlockSectionItem-->
                
                                                      
            </apex:pageblocksection>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

this is my extensions class:

 

public class SalesforceDB{
        
    private final Contact conc;
    private List <String> result;
    
    public SalesforceDB(ApexPages.StandardSetController stdcontroller) {
        this.conc = (Contact)stdcontroller.getRecord();

    }

    public List<String> getDBInfo() {
        string MyReturn;
        salesforceconLocalConDB.Contactdetails stub = new salesforceconLocalConDB.Contactdetails();
        stub.timeout_x = 120000 ;     
        result = stub.getname(conc.Policy_No__c);
        System.debug('* Result:' + result);
        MyReturn = result[0];
        System.debug('* MyRetrun:' + MyReturn);
        return result;
    }
}

 

what should i put to display the result in list view??

Best Answer chosen by Admin (Salesforce Developers) 
Puja_mfsiPuja_mfsi

Hi,

It looks as the "result" list is empty.and u are trying to get the 0th element from that list

 

String spl_value = result[0];

That's why it gives error.Why r u not using System.Debug to check whether the list has value or not and u need to use NUll check in each places.

 

 

Please let me know if u have any problem on same and if this post hepls u please throw KUDOS by click on star at left.

All Answers

souvik9086souvik9086

You can use your list in

 

<apex:pageBlockTable value = "{!YouList}" var = "VariableName">
     <apex:column value="{!VariableName.FieldName}"/>
</apex:pageBlockTable>

Assuming that the list is your object list.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

hylim12hylim12

i've changed my VF to:

 

<apex:page standardController="Contact" extensions="SalesforceDB" recordSetVar="contacts">
<!--It will be a nice to get output from the controller<p>My webservice is now returning {!HelloWorld} !! -->
    <apex:sectionHeader title="External DB Conn" subtitle="Getting data from Local DB"/>
     <apex:form >  
         <apex:pageBlock mode="edit" id="block">  
  
             <apex:pageBlockSection >  
                 <apex:pageBlockSectionItem >  
                     <apex:panelGroup >  
                     <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/><p />
                     <apex:actionStatus id="status" startText="Searching... please wait..."/> 
                     </apex:panelGroup>  
                 </apex:pageBlockSectionItem>  
             </apex:pageBlockSection>  
   
              
             <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1">  
                 <apex:pageBlockTable value="{!result2}" var="c" >
                     <apex:column value="{!c}" headerValue="Key" />
                     <apex:column value="{!c}" headerValue="Name" />
                 </apex:pageBlockTable>
             </apex:pageBlockSection>  
             


         </apex:pageBlock>  
     </apex:form> 
    
    

</apex:page>

 and my controller extensions to:

 

public class SalesforceDB{

      
    private final Contact conc;
    public List <String> result2  {get;set;}
    private List <String> result {get;set;}
    public String stra {get;set;}
    private Map<String, String> hmap;
    
    public SalesforceDB(ApexPages.StandardSetController stdcontroller) {
        this.conc = (Contact)stdcontroller.getRecord();
        
    }
    
    public List <String> result2() {
        return result;
    }
    
    
    public PageReference search(){

        salesforceconDB.Contactdetails stub = new salesforceconDB.Contactdetails();
        stub.timeout_x = 120000 ;
        result = stub.getname(conc.Policy_No__c);
        
        
        for(Integer a = 0; a <= result.size(); a++){
            String spl_value = result[0];
            
            List<String> splt = spl_value.split(';');
        }

        
        return null;
    }
}

 but when i click on Search button, i still didnt see my result return.

 

my result return from Wenservice is [aaa;bbb;ccc;ddd]. any help pls?

Puja_mfsiPuja_mfsi

HI,

Please change your code as:

public void search(){

           result2  = new List<String>();

          salesforceconDB.Contactdetails stub = new salesforceconDB.Contactdetails();
           stub.timeout_x = 120000 ;
           result = stub.getname(conc.Policy_No__c);
           for(Integer a = 0; a <= result.size(); a++){
                       String spl_value = result[0];
                        result2.addAll( spl_value.split(';'));
            }

}

 

And remove 

public List <String> result2() {
     return result;
}

 

Please let me know if u have any problem on same if this post helps u please throw KUDOS by click on star at left.

hylim12hylim12
Hi Puja,

there is one part i do not understand. My return result from my webservice is something like [2013-10-01;1200001;AAA;BBB;CCC]

when i want to display a list view in my contact page, with this line of code
<apex:pageBlockTable value="{!result2}" var="c" >
<apex:column value="{!c}" headerValue="Key" />
<apex:column value="{!c}" headerValue="Name" />
</apex:pageBlockTable>

how it determine that column 1 is Date, 2 is Ref_No and so on?

Thanks!
hylim12hylim12

I modify my apexcode to:

 

public class SalesforceDB{

    

      
    private final Contact conc;
    public List <myData> result2  {get;set;}
    private List <String> result {get;set;}
    public String stra {get;set;}
    public String PolicyNo{get; set;}
    private Map<String, String> hmap;
    
    public SalesforceDB(ApexPages.StandardController controller) {
            this.conc = (Contact)controller.getRecord();
    }

    
    public SalesforceDB(ApexPages.StandardSetController stdcontroller) {
        
         Contact conc2 = (Contact)stdcontroller.getRecord();
    }
    
    public class myData{
        String col1;
        String col2;
    }
    
    myData md;

    
    
    public void search(){
        String kk;
        String nn;
        result2  = new List<myData>();
        result = new List<String>();
        salesforceconDB.Contactdetails stub = new salesforceconDB.Contactdetails();
        stub.timeout_x = 120000 ;
        result = stub.getname(PolicyNo);
        
        //if(result.size != 0){
            //for(Integer a = 0; a <= result.size(); a++){
                String spl_value = result[0];
                
                List<String> splt = spl_value.split(';');
                    //for(Integer k = 0; k <= splt.size(); k++){
                        md = null;
                        myData md = new myData();
                        
                        kk = splt[0];
                        nn = splt[1];
                        md.col1 = kk;
                        md.col2 = nn;
                        
                        
                        result2.add(md);
                    //}
                
                //result2.addAll(spl_value.split(';'));

            //}
        //}         
    }
}

 However, i keep getting error

 

'System.NullPointerException: Attempt to de-reference a null object

Error is in expression  in page salesforcews

 

 

Class.SalesforceDB.search: line 43, column 1'

 

What am i missing?

Puja_mfsiPuja_mfsi

Hi,

It looks as the "result" list is empty.and u are trying to get the 0th element from that list

 

String spl_value = result[0];

That's why it gives error.Why r u not using System.Debug to check whether the list has value or not and u need to use NUll check in each places.

 

 

Please let me know if u have any problem on same and if this post hepls u please throw KUDOS by click on star at left.

This was selected as the best answer
hylim12hylim12
Hi Puja,

Yes you are right. System.Debug helps me found my problem.
Thanks alot! You save my day =)