• shyam singh 41
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi Team,

I want to fix this by adding an alert message on my VF page when the upload file size is not more than 25MB. it should show the alert wherever the uploaded file is more than 25MB.

Here my vf page,
 
<apex:page sidebar="false" showheader="false" Controller="CaseController" id="Support">
<apex:form id="Page">
<apex:pageMessages />
  <html>
    <head>
        <title>My - Help</title>
        <link rel="stylesheet" href="{!URLFOR($Resource.SC_CSS,'css/index.css')}" />
        <link rel="stylesheet" href="{!URLFOR($Resource.SC_CSS,'css/grid.css')}" />
        <link rel="shortcut icon" href="{!URLFOR($Resource.SC_CSS,'css/favicon.ico')}" type="image/x-icon" />
        <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" />
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/> 
    </head>   
    <body>
        <section class="help-desk__navigation">
            <div class="container">
                <div class="table">
                    <div class="logo">
                        <img src="{!URLFOR($Resource.SC_CSS,'css/images/my-logo-black.png')}" />
                    </div>
                    <div class="cta">
                        <a class="btn">1-845-456-7888</a>
                    </div>
                </div>
            </div>
        </section>
        <section class="help-desk__header">
            <div class="container">
                <h1>Requests</h1>
            </div>
        </section>
        <section class="help-desk__sub-header">
            <div class="container">
                <ul class="help-desk__breadcrumbs">
                    <li><a href="//help.mysite.com" target="_blank">My Support Center</a></li>
                    <li>Submit a Request</li>
                </ul>
            </div>
        </section>
        <section class="help-desk__content">
            <div class="container">
                <div class="row">
                    <div class="col-md-5">
                        <h3>Submit a request</h3>
                        <div>&nbsp;</div>
                        <div class="form-field">
                            <label>Your email address<span class="required">*</span></label>                            
                            <apex:inputField id="Email" required="true" value="{!c.Email}"/>                            
                        </div>
                        <div class="form-field">
                            <label>Subject<span  class="required">*</span></label>                            
                            <apex:inputText id="Subject" required="true" value="{!strSubject }" maxlength="250" size="25" />
                        </div>
                        <div class="form-field">
                            <p>Please enter the details of your request. A member of our support staff will respond as soon as possible.</p>
                        </div>
                        <div class="form-field">
                            <label>Description<span class="required">*</span></label>                            
                            <apex:inputTextarea id="Description" required="true" value="{!strDescription}"/>
                        </div>
                       <!--<div class="form-field">
                            <label>Attachments</label>
                            <div class="upload-box text-center ripple">
                               <input type="file"  value="{!attachment.body}"  filename="{!attachment.name}" />
                                <span><img src="{!URLFOR($Resource.SC_CSS,'css/images/paperclip.png')}"  /></span>
                                <span><a>Add file</a> or drop files here</span>
                            </div>
                        </div>-->
                        <div class="form-field">
                            <label>Attachments</label>
                            <div>                                
                                <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"/>
                            </div>
                        </div>
                        <div class="form-field text-right">
                           <a class="btn" onclick="jsCallSavefn()" >Submit</a>                         
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <section class="help-desk__footer">
            <div class="container">
                <div class="row">
                    <div class="col-md-5">
                        <div class="logo">
                            <img src="{!URLFOR($Resource.SC_CSS,'css/images/my-logo-black.png')}"   />
                        </div>
                        <p>Mysite is the all-in-one solution for local business owners &ndash; equipping them with an HTML5, mobile-responsive website and an ever-expanding product suite that gives them the power to tell their story and reinvent their digital presence.</p>
                        <p>&copy; 2017 Mysite. All rights reserved.</p>
                    </div>
                    <div class="col-md-7">
                        <div class="row">
                            <div class="col-md-6">
                                <h3>Company</h3>
                                <ul class="bordered-list">
                                    <li><a href="//www.mysite.com/" target="_blank">What is Mysite?</a></li>
                                    <li><a href="//blog.mysite.com/" target="_blank">Blog</a></li>
                                </ul>
                            </div>
                            <div class="col-md-6">
                                <h3>Community</h3>
                                <ul class="bordered-list">
                                    <li><a href="https://www.facebook.com/MysiteTeam" target="_blank">Facebook</a></li>
                                    <li><a href="https://twitter.com/mysiteteam" target="_blank">Twitter</a></li>
                                    <li><a href="https://www.youtube.com/user/mysiteteam" target="_blank">Youtube</a></li>
                                    <li><a href="https://www.instagram.com/mysiteteam/" target="_blank">Instagram</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </body>
</html>
<apex:actionFunction action="{!Save}" name="jsCallSavefn">  
</apex:actionFunction>
</apex:form>
</apex:page>

Controller,
 
public with sharing class CaseController {

    public Contact c { get; set; }
    
    public CaseController(){
       c = new Contact();
    }
    
    public Attachment attachment {
    get {
      if (attachment == null)
        attachment = new Attachment();
      return attachment;
    }
    set;
    }
     
    public string strSubject {get;set;}     
    public string strDescription {get;set;}     

    public PageReference save()
    {   
        String Body  = strDescription;

        String Subject = strSubject;
        List<String> toAddresses  = new List<String>();
        toAddresses.add('mysitesupportcase@z-279vlo46d4dn63rs8liuxfyuv0t1fjox5sgnsyr0nc6ccct0n0.m-4etgeaq.cs20.apex.sandbox.salesforce.com');
        toAddresses.add('ckarthikeyanbtechit@gmail.com');
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setSubject(Subject);
        mail.setReplyTo(c.Email);
        mail.setSenderDisplayName(c.Email);
        mail.setToAddresses(toAddresses);
        mail.setHtmlBody(body);
        if(attachment.body != null)
        {
            Blob b = attachment.body;
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            efa.setFileName(attachment.name);
            efa.setBody(b); 
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
        }       
        
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        
        PageReference newocp = new PageReference('/apex/SampleRedirectPage');
        newocp.setRedirect(true);
        return newocp;
        return null;
    }
    
     
   
}

Can anyone fix this ASAP?

Thanks,

Working on a Rock Paper Scissors game to learn Apex/visualforce with (and to be able to play with other devs on the org). Somewhere in the main body, something is not working right. It is running, that much I know, but somewhere down the line it is not updating the page nor the database as to the result. Here is the VF page:

 

<apex:page showheader="false">
<c:rps ></c:rps>
</apex:page>

 

Here is the Component:

 

<apex:component controller="rps" allowDML="true">
Lets play Rock Paper Scissors!
    <apex:form >
        <apex:selectList id="rps" value="{!input}" size="1" title="Choose Your Weapon">
            <apex:selectOptions value="{!inputSelect}"/>
        </apex:selectList>
        <apex:selectList id="rps2" value="{!partners}" size="1" title="Choose Your Weapon">
            <apex:selectOptions value="{!partner}"/>
        </apex:selectList>
        <apex:commandButton action="{!makeNew}" value="Create Game"/>
        <apex:commandButton action="{!makePlayable}" value="Allow Multiplayer"/>
    </apex:form>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Play" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!ListAvailable}" var="a" id="table">
                <apex:column >
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <apex:column value="{!a.game.Name}" />
            </apex:pageBlockTable>
        </apex:pageBlock>

    </apex:form>
    <apex:outputPanel id="dynamic">
        {!output}<br/>
    </apex:outputPanel>
</apex:component>

 

Here is the controller class:

 

public class rps{
    
    public PageReference makeNew(){
        Asynch_RPS_Game__c a = new Asynch_RPS_Game__c();
        a.move__c = input;
        a.user2__c = partners;
        INSERT a;
        
        return null;
    }
    
    public List<SelectOption> getPartner(){
        List<selectOption> op = new List<selectOption>();
        for(RPS_Save__c rps : [SELECT Name FROM RPS_Save__c WHERE MakePlayable__c = true]){
            op.add(new selectOption(rps.Name,rps.Name));
        }
        System.debug('op: ' + op);
        return op;
    }
    
    //Gives options to click
    public List<SelectOption> getinputSelect(){
        List<selectOption> options = new List<selectOption>();
        options.add(new selectOption('rock','Rock'));
        options.add(new selectOption('paper','Paper'));
        options.add(new selectOption('scissors','Scissors'));
        return options;
    }
    
    public String partners {get;set;}
    public String input {get;set;}
    public String output {get;set;}
    public integer wins {get;set;}
    public integer losses {get;set;}
    public integer ties {get;set;}
    private RPS_Save__c userScore;
    public List<aAsynch_RPS_Game> gamesList {get;set;}
    
    //allows the multiplayer
    public PageReference makePlayable(){
        RPS_Save__c[] userScores = [SELECT id FROM RPS_Save__c WHERE Name=:userInfo.getName()];
        if(userScores.size() > 0){
            userScore = userScores[0];
        } else {
            userScore = new RPS_Save__c(Name = userInfo.getName(), Wins__c = 0, Losses__c = 0, Ties__c = 0);
            INSERT userScore;
        }
        userScore.makePlayable__c = true;
        UPDATE userScore;
        return null;
    }
    
    //Lists games that still need to be finished
    public List<aAsynch_RPS_Game> getListAvailable(){
        if(gamesList == null) {
            gamesList = new List<aAsynch_RPS_Game>();
            for(Asynch_RPS_Game__c a : [SELECT Name, Owner.Name, Move__c, Finished__c FROM Asynch_RPS_Game__c WHERE User2__c =: userInfo.getName()]) {
                if(a.Finished__c == null){
                    gamesList.add(new aAsynch_RPS_Game(a));
                }
          }
        }
        return gamesList;
    }
    
    
    
    //does stuff when you select things
    public PageReference processSelected(){
        system.debug('is this even running?');
        List<Asynch_RPS_Game__c> available = new List<Asynch_RPS_Game__c>();
        for(aAsynch_RPS_Game ggame : getListAvailable()){
            if(ggame.selected == true){
                available.add(ggame.game);
                system.debug('sup from avail.add');
            }
        }
        
        integer l;
        integer w;
        integer t;
        
        RPS_Save__c[] userScores = [SELECT id, Wins__c, Losses__c, Ties__c, Name FROM RPS_Save__c WHERE Name=:userInfo.getName()];
        if(userScores.size() > 0){
            userScore = userScores[0];
          w = integer.valueOf(userScore.Wins__c);
          l = integer.valueOf(userScore.Losses__c);
          t = integer.valueOf(userScore.Ties__c);
        } else {
            userScore = new RPS_Save__c(Name = userInfo.getName(), Wins__c = 0, Losses__c = 0, Ties__c = 0);
            INSERT userScore;
        }
        
        for(Asynch_RPS_Game__c a : available){
          integer comp;
            if(a.move__c == 'rock'){
                comp = 0;
            }else if(a.move__c == 'paper'){
                comp = 1;
            }else{
                comp = 2;}
        
            //check win/loss/tie
          if(comp == 0){
              if(input == 'rock'){
                  output = 'Tie';
                  if(t > 0){
                      t++;
                  }else{
                      t = 1;
                  }
                  return null;
              }else if(input == 'paper'){
                  output = 'Win';
                  if(w > 0){
                      w++;
                  }else{
                        w = 1;
                  }
                  return null;
              }else if(input == 'scissors'){
                  output = 'Lose';
                  if(l > 0){
                      l++;
                  }else{
                      l = 1;
                  }
                  return null;
              }else{
                  output = ' ';
                  return null;
              }
          }else if(comp == 1){
              if(input == 'rock'){
                  output = 'Lose';
                  if(l > 0){
                      l++;
                  }else{
                      l = 1;
                  }
                  return null;
              }else if(input == 'paper'){
                  output = 'Tie';
                  if(t > 0){
                      t++;
                  }else{
                      t = 1;
                  }
                  return null;
              }else if(input == 'scissors'){
                  output = 'Win';
                  if(w > 0){
                      w++;
                  }else{
                        w = 1;
                  }
                  return null;
              }else{
                  output = ' ';
                  return null;
              }
          }else{
              if(input == 'rock'){
                  output = 'Win';
                  if(w > 0){
                        w++;
                  }else{
                      w = 1;
                  }
                  return null;
              }else if(input == 'paper'){
                  output = 'Lose';
                  if(l > 0){
                      l++;
                  }else{
                       l = 1;
                  }
                  return null;
              }else if(input == 'scissors'){
                  output = 'Tie';
                  if(t > 0){
                      t++;
                  }else{
                      t = 1;
                  }
                  return null;
              }else{
                  output = ' ';
                  return null;
              }
            }
            a.Finished__c = System.Today();
            UPDATE a;
        }
        
        userScore.Wins__c = w;
        userScore.Losses__c = l;
        userScore.Ties__c = t;
        userScore.Name = userInfo.getName();
        UPDATE userScore;
        
        available = null;
            return null;
    }
    
        //wrapper class for list
    public class aAsynch_RPS_Game {
        public Asynch_RPS_Game__c game {get; set;}
        public Boolean selected {get; set;}
        
        public aAsynch_RPS_Game(Asynch_RPS_Game__c g){
          game = g;
          selected = false;
        }
    }
}

 

Any help given is greatly appreciated!