Slide Show in Salesforce

Visualforce:

<apex:page standardController="Photo__c" extensions="SlideShow" sidebar="false">

  <apex:form >

    <center>

    <apex:image url="{!tmp}"/>

    <br/>
    <br/>
    <br/>
   
    <apex:commandButton action="{!prev}" value="Previous"/>&nbsp;&nbsp;&nbsp;
    <apex:commandButton action="{!nxt}" value="Next"/>

    </center>

  </apex:form>

</apex:page>


Apex Controller:

Public Class SlideShow
{
    public List<Photo__c> photo {get; set;}
    public String imageTag {get; set;}
    public String photoUrl {get; set;}
    public Integer strt=0,ed=1,len=0,i=0,indx=0;
   
    public String tmp {get; set;}
   
    public SlideShow(ApexPages.StandardController controller)
    {          
      String sql = 'SELECT image__c FROM Photo__c';
      photo = Database.query(sql);
      imageTag = photo.get(indx).image__c;
     
      strt = imageTag.indexOf('src=',0) + 5;
      ed = imageTag.lastIndexOf('alt=') - 2;
      tmp = imageTag.substring(strt,ed);
    }          
   
    public void prev()
    {
      if(indx != 0)
      {
      indx = indx - 1;
      String sql = 'SELECT image__c FROM Photo__c';
      photo = Database.query(sql);
      imageTag = photo.get(indx).image__c;
     
      strt = imageTag.indexOf('src=',0) + 5;
      ed = imageTag.lastIndexOf('alt=') - 2;
      tmp = imageTag.substring(strt,ed);
      }
    }   

    public void nxt()
    {  
      len = [SELECT COUNT() FROM Photo__c];
      if(indx != (len-1))
      {
      indx = indx + 1;
      String sql = 'SELECT image__c FROM Photo__c';
      photo = Database.query(sql);
      imageTag = photo.get(indx).image__c;
     
      len =imageTag.length();
      strt = imageTag.indexOf('src=',0) + 5;
      ed = imageTag.lastIndexOf('alt=') - 2;
      tmp = imageTag.substring(strt,ed);
      }     
    }       
}

Cheers!!!

4 comments:

  1. if i run this code i got error like Photo__c does not exist.can u tel me how to solve

    ReplyDelete
  2. You have to create a new custom object name "Photo" and after that a custom field "Image"

    ReplyDelete
  3. I have create the object and Field and some records also but am not getting any mages in VF its showing empty

    ReplyDelete
  4. Hi Neha,

    What should b the data type of custom field "image" ?

    ReplyDelete