-
ChatterFeed
-
0Best Answers
-
2Likes Received
-
0Likes Given
-
21Questions
-
58Replies
Can apex:inputFile have the html5 validation function?
My web page is a form using html5 validation to check blank. All field in my form can use html5 to perform validation, except the inputFile field for uploading attachment. Can apex:inputFile have the html5 validation function? Or is there any way to perform validation for checking whether the attachment field is blank or not? Thanks.
- Alex Wong 4
- August 18, 2016
- Like
- 0
How to validate email address or URL on client side?
My page is form. There are fields for email and url input. How to validate them? Since I have try the same technique, it works on the "required", but not the "email" field. For the required validation, when I click the save button, there is a message box shows under the field which is blank. But the message will only show one by one. Can they all show at the same time? How can I solve it?
Here is my code:
Here is my code:
<apex:page standardController="Artist__c" extensions="extattachfile" showHeader="false" sidebar="false" docType="html-5.0"> <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <style type="text/css"> h1 {font-size: 150%; font-weight: bold;} h2 {font-size: ;} p { width:100%; font-size: 120%; text-align: justify; text-justify: inter-word;} .reddot {color: red; font-size:120%;} .textarea { height:200px; width:300px; border-radius: 5px;} .url {width:300px;} .title {font-size:175%;} .standard {width: 310px;} @media only screen and (min-width: 900px) { /* For desktop: */ p { width:890px; font-size: 120%; text-align: justify; text-justify: inter-word;} } .color { background-color: #F7F6D2; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -o-transition: all 1s ease; transition: all 1s ease; } </style> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/> <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /> <apex:includeScript value="https://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"/> <apex:includeScript value="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"/> <apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" /> <apex:includescript value="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js" /> </head> <script> $ = jQuery.noConflict(); $(document).ready(function() { $('[id$=artistform]').validate(); $('[id$=chiname]').rules("add",{ required: true, }); $('[id$=engname]').rules("add",{ required: true, }); $('[id$=chibio]').rules("add",{ required: true, }); $('[id$=engname]').rules("add",{ required: true, }); $('[id$=contactperson]').rules("add",{ required: true, }); $('[id$=contactno]').rules("add",{ required: true, }); $('[id$=email]').rules("add",{ required: true, email: true }); /* Customised the messages */ jQuery.validator.messages.required = "<label style='color:red'>This field is required</label>"; jQuery.validator.messages.email = "<label style='color:red'>This is an invalid email.</label>"; }); </script> <apex:form styleclass="form" id="artistform"> <apex:pageBlock > <apex:pageMessages /> <div><b class="title">Artist Submission Form</b></div><br/> <br/> <h1>Artist / Group Information</h1> <br/><br/> <div class="standard"> <h2>Artist / Group Name (Chinese)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputText value="{!artist.Artist_Group_Name_Chinese__c}" id="chiname" required="true"/ > <apex:outputlabel id="op2" /> </apex:panelGroup> <br/> </div> <br/> <div class="standard"> <h2 >Artist / Group Name (English)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputText value="{!artist.Artist_Group_Name_English__c}" label="" id="engname" required="true"/> </apex:panelGroup> <br/> </div> <br/> <div class="standard"> <h2 >Artist / Group Biography (Chinese)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputTextarea value="{!artist.Artist_Group_Biography_Chinese__c}" label="" styleClass="textarea" id="chibio" required="true"/> </apex:panelGroup> <br/> </div> <br/> <div class="standard"> <h2 >Artist / Group Biography (English)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputTextarea value="{!artist.Artist_Group_Biography_English__c}" label="" styleClass="textarea" id="engbio" required="true"/> </apex:panelGroup> <br/><br/> </div> <br/> <div class="heading"> <h1>Name and Roles of Group Members (if applicable)</h1> <br/> <br/><br/> </div> <br/> <div class="standard"> <h2>Name and Roles of Group Members</h2><br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Member_Name_Role__c}" label="" styleClass="textarea"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >Photo of Artist/ Group : max 3 attachments</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}" required="false" id="photo"/><br/></apex:panelGroup> <apex:inputFile value="{!objAttachment2.body}" fileName="{!objAttachment2.name}" required="false" /><br/> <apex:inputFile value="{!objAttachment3.body}" fileName="{!objAttachment3.name}" required="false" /> <br/><br/> </div> <br/> <div class="standard"> <h2>Website </h2><outputtext/><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Website__c}" label="" styleClass="url" id="web"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >Facebook</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Facebook__c}" label="" styleClass="url" id="facebook"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >SoundCloud</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.SoundCloud__c}" label="" styleClass="url" id="soundcloud"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >YouTube</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.YouTube__c}" label="" styleClass="url" id="youtube"/> <br/> </div> <br/><br/> <div class="standard"> <h2>Technical Rider (File to be less than 1 MB) : max 1 attachment</h2><br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputFile value="{!objAttachmentt.body}" fileName="{!objAttachmentt.name}" /><br/> </div> <br/> <div class="standard"> <h2>Stage Plot (File to be less than 1 MB) : max 1 attachment</h2> <br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputFile value="{!objAttachments.body}" fileName="{!objAttachments.name}" required="false" /><br/><br/> </div> <br/> <div class="heading"> <h1>Contact Information </h1> <br/><br/> </div> <br/> <div class="standard"> <h2>Contact Person </h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputText value="{!artist.Contact_Person__c}" label="" id="contactperson" required="true"/> <br/> </apex:panelGroup> </div> <br/> <div class="standard"> <h2 >Contact No. </h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputText value="{!artist.Contact_Number__c}" label="" id="contactno" required="true"/> <br/> </apex:panelGroup> </div> <br/> <div class="standard"> <h2>Email </h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputText value="{!artist.Email__c}" label="" id="email" required="true"/> <br/> </apex:panelGroup> </div> <br/> > <br/> <div> <apex:commandButton action="{!save}" value="Save"/> </div> <script> var addclass = 'color'; var $cols = $('.standard').click(function(e) { $cols.removeClass(addclass); $(this).addClass(addclass); }); </script> </apex:pageBlock> </apex:form> <apex:pageMessages /> </apex:page>
- Alex Wong 4
- August 17, 2016
- Like
- 0
Is there a way to perform validation for apex:inputField?
I am creating a form in Visualforce. Since my form is a bit long, it is hard for users to remember the error message at the top and revise it. On top of the error message, I want to create a validation when users typing in their information.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.
- Alex Wong 4
- August 15, 2016
- Like
- 1
How to achieve validation by jQuery in Visualforce?
I have seen this article and try to adopt this method.
Salesforce Form Validation Enhanced:
https://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/
However, I do not know why I get nothing happen even I have followed the step. Here is my code:
Thanks for your help.
Salesforce Form Validation Enhanced:
https://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/
However, I do not know why I get nothing happen even I have followed the step. Here is my code:
<apex:page standardController="Artist__c" extensions="extattachfile" showHeader="false" sidebar="false"> <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <style type="text/css"> h1 {font-size: 150%; font-weight: bold;} h2 {font-size: ;} p { width:100%; font-size: 120%; text-align: justify; text-justify: inter-word;} .reddot {color: red; font-size:120%;} .textarea { height:200px; width:300px; border-radius: 5px;} .url {width:300px;} .title {font-size:175%;} .standard {width: 310px;} @media only screen and (min-width: 900px) { /* For desktop: */ p { width:890px; font-size: 120%; text-align: justify; text-justify: inter-word;} } .color { background-color: #F7F6D2; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -o-transition: all 1s ease; transition: all 1s ease; } </style> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/> <apex:includescript value="{!$Resource.jQuery}"></apex:includescript> <apex:includescript value="http://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"></apex:includescript> </head> <script type="text/javascript"> $(document).ready(function() { $('[id$=artistform]').validate(); $('[id$=engname]').rules("add",{ required: true, }); $('[id$=email]').rules("add",{ required: true, email: true }); /* Customised the messages */ jQuery.validator.messages.required = "You better have entered a value.. or else!"; jQuery.validator.messages.equalTo = "No silly, you're supposed to type the same set of characters AGAIN."; }); </script> <apex:form styleclass="form" id="artistform"> <apex:pageBlock > <apex:pageMessages /> <div><b class="title">Artist Submission Form</b></div><br/> <br/> <h1>Artist / Group Information 表演者 / 團體資料</h1> <br/><br/> <br/> <div class="standard"> <h2 >Artist Name (English)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Artist_Group_Name_English__c}" label="" id="engname"/> </apex:panelGroup> <br/> </div> <br/> <br/> <div class="standard"> <h2 >Artist Biography (English)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Artist_Group_Biography_English__c}" label="" styleClass="textarea" id="engbio"/> </apex:panelGroup> <br/><br/> </div> <br/> <div class="heading"> <h1>Name and Roles of Group Members (if applicable)</h1> <br/><br/> </div> <br/> <div class="standard"> <h2>Name and Roles of Group Members</h2><br/> <h2>團體成員姓名及崗位</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Member_Name_Role__c}" label="" styleClass="textarea"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >Photo of Artist : max 3 attachments</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}" required="false" id="photo"/><br/></apex:panelGroup> <apex:inputFile value="{!objAttachment2.body}" fileName="{!objAttachment2.name}" required="false" /><br/> <apex:inputFile value="{!objAttachment3.body}" fileName="{!objAttachment3.name}" required="false" /> <br/><br/> </div> <br/> <div class="standard"> <h2>Website</h2><outputtext/><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Website__c}" label="" styleClass="url" id="web"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >Facebook</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Facebook__c}" label="" styleClass="url" id="facebook"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >SoundCloud</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.SoundCloud__c}" label="" styleClass="url" id="soundcloud"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >YouTube</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.YouTube__c}" label="" styleClass="url" id="youtube"/> <br/> </div> <br/><br/> <div class="standard"> <h2>Technical Rider : max 1 attachment</h2><br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputFile value="{!objAttachmentt.body}" fileName="{!objAttachmentt.name}" /><br/> </div> <br/> <div class="standard"> <h2>Stage Plot : max 1 attachment</h2> <br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputFile value="{!objAttachments.body}" fileName="{!objAttachments.name}" required="false" /><br/><br/> </div> <br/> <div class="heading"> <h1>Contact Information</h1> <br/><br/> </div> <br/> <div class="standard"> <h2>Contact Person</h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Contact_Person__c}" label="" id="contactperson"/> <br/> </apex:panelGroup> </div> <br/> <div class="standard"> <h2 >Contact No.</h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Contact_Number__c}" label="" id="contactno"/> <br/> </apex:panelGroup> </div> <br/> <div class="standard"> <h2>Email</h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Email__c}" label="" id="email"/> <br/> </apex:panelGroup> </div> <br/> <br/> <div> <apex:commandButton action="{!save}" value="Save"/> </div> <script> var addclass = 'color'; var $cols = $('.standard').click(function(e) { $cols.removeClass(addclass); $(this).addClass(addclass); }); </script> </apex:pageBlock> </apex:form> <apex:pageMessages /> </apex:page>
Thanks for your help.
- Alex Wong 4
- August 15, 2016
- Like
- 0
Red bar of the input field
In my page, there are some field are required the users to insert. However, I cannot use the required="true" method in the apex:inputfield. Because this will lead to a standard error message, which cannot shows with the custom error message at the same time. Thus, I remove all the checking in the system and setup checking in the apex code, to generate a custom error message. Is there any althernative to show the red bar in order to alert the users? Thanks.
- Alex Wong 4
- August 12, 2016
- Like
- 0
Is there a way to check phone number format?
If I try the phone format in the field, it can provide a phone format.However, even I type in character, the system still accept it. If I use the number format, it can restrict users only to type number. However, the outlook of data will become a number format with this sign (","). How can I solve this problem? Thank you.
- Alex Wong 4
- August 12, 2016
- Like
- 0
Is it possible to show standard and custom error message at the same time?
I want to know that is there a method to show the standard error message and custom error message at the same time? Also, in my script, there are several custom error message. Is it possilbe to show them at the same time?
Here is my code:
Thank you for your help.
Here is my code:
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; Boolean isValidUrl = true; if(artist.Id == null){ if(artist.Website__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Website__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Website URL.')); isValidUrl = false; } } if(artist.Facebook__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Facebook__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Facebook URL.')); isValidUrl = false; } } if(artist.SoundCloud__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.SoundCloud__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Soundcloud URL.')); isValidUrl = false; } } if(artist.YouTube__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.YouTube__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Youtube URL.')); isValidUrl = false; } } if(isValidUrl){ insert artist; }else{ return null; } } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; List<String> splitStrList = objAttachment.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachment.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo1'+'.' + fileExtension; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; List<String> splitStrList = objAttachment2.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachment2.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo2'+'.' + fileExtension; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; List<String> splitStrList = objAttachment3.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachment3.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo3'+'.' + fileExtension; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; List<String> splitStrList = objAttachmentt.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'.' + fileExtension; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; List<String> splitStrList = objAttachments.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachments.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Stage'+'.' + fileExtension; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; attachmentList = null; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
Thank you for your help.
- Alex Wong 4
- August 11, 2016
- Like
- 0
How to rename the attachments in custom objects?
In my application, I create a form for public to fill in thier information. There questions of all require public to insert attachment. The default name of the attachment are the name decidie by public, but it is hard for administraion. Thus, I want to rename it in a meaningful way:
(RecordID)_(UserName)_(DateOfCreate)_(Q).(Format)
RecordID is the name of the record of custom object.
UserName is the data insert by users in the field "Artist_English_Name__c"
DateOfCreate is the date of creating the record of custom object.
Q is the question that the attachment belongs to.
Format is the type of attachment indicated, as I need them for the name conversion in data export.
Because I want to trace back the attachment ie owned by who and which question.
At this stage, I only achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical_field2.png") by this code:
But I want to achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical.png").
The whole code for reference:
Thank you.
(RecordID)_(UserName)_(DateOfCreate)_(Q).(Format)
RecordID is the name of the record of custom object.
UserName is the data insert by users in the field "Artist_English_Name__c"
DateOfCreate is the date of creating the record of custom object.
Q is the question that the attachment belongs to.
Format is the type of attachment indicated, as I need them for the name conversion in data export.
Because I want to trace back the attachment ie owned by who and which question.
At this stage, I only achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical_field2.png") by this code:
objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'_'+objAttachmentt.Name;
But I want to achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical.png").
The whole code for reference:
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; Boolean isValidUrl = true; if(artist.Id == null){ if(artist.Website__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Website__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Website URL.')); isValidUrl = false; } } if(artist.Facebook__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Facebook__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Facebook URL.')); isValidUrl = false; } } if(artist.SoundCloud__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.SoundCloud__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Soundcloud URL.')); isValidUrl = false; } } if(artist.YouTube__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.YouTube__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Youtube URL.')); isValidUrl = false; } } if(isValidUrl){ insert artist; }else{ return null; } } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; objAttachment.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo1'+'_'+objAttachment.Name; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; objAttachment2.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo2'+'_'+objAttachment2.Name; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; objAttachment3.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo3'+'_'+objAttachment3.Name; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'_'+objAttachmentt.Name; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; objAttachments.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Stage'+'_'+objAttachments.Name; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; attachmentList = null; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
Thank you.
- Alex Wong 4
- August 04, 2016
- Like
- 1
How to write a trigger for renaming attachments in custom objects?
I am quite new for salesofrce and I want to write a trigger to modify attachments name after user inserting the attachments. For my situation, my page is form for public input their information. It includes 3 question that requires users to insert attachments. One question can allow users to upload 1-3 attachmetns, and the other two require only 1. Since I want to classify them from the their name, I want a trigger to rename the attachments after insert. Thank you for your great effort.
- Alex Wong 4
- August 02, 2016
- Like
- 0
How to export attachment?
Is there any method to export the attacments of custom object?
- Alex Wong 4
- August 01, 2016
- Like
- 0
3 questions for the attachment part of custom objects
I created a form for public information collection, which included several attachment. These 5 attachments are belong to 5 different question. Since there are only one attachment for each custom object record, how to sepearate or classify them so that I would know which attachment belongs to which question.
Also, is there any method to rename the attachment that public submit?
The last question is, how can I export all the data for the form (custom object) including the attachment. Or the only way is to keep in salesforce system?
Thank you.
Also, is there any method to rename the attachment that public submit?
The last question is, how can I export all the data for the form (custom object) including the attachment. Or the only way is to keep in salesforce system?
Thank you.
- Alex Wong 4
- July 26, 2016
- Like
- 0
How can I show/ hide a div when the checkbox is selected?
In my case, I want to show pessage with a div, when a checkbox is checked. But when it is unchecked, I want to hide the div. I can it by using javascript, but it failed. Is there any problem for the script?
Thank you so much.
<apex:page standardController="M_Pioneers__c" extensions="addPionners"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <apex:form > <script> $(".showp").hide(); $("#checkbox").click(function() { if($(this).is(":checked")) { $(".showp").show("slow"); } else { $(".showp").hide("slow"); } }); </script> <apex:pagemessages /> <div> <label for="M_Pioneers_Name__c">Name</label> <apex:inputField value="{!pioneers.M_Pioneers_Name__c}" id="M_Pioneers_Name__c"/> </div> <div> <label for="M_Pioneers_Email__c">Email</label> <apex:inputField value="{!pioneers.M_Pioneers_Email__c}" id="M_Pioneers_Email__c"/> </div> <div> <label for="M_Pioneers_Phone__c">Contact Number</label> <apex:inputField value="{!pioneers.M_Pioneers_Phone__c}" id="M_Pioneers_Phone__c"/> </div> <div> <apex:inputCheckbox id="checkbox" onfocus="showp()"/> </div> <div class="showp" style="display: none"> <p>HI!</p> </div> </apex:form> </apex:page>
Thank you so much.
- Alex Wong 4
- July 26, 2016
- Like
- 0
Text width in Responsive Design
I am quite new for both html and salesforce. I am going to create a form for public information collection. At this stage, I can create a simple responsive design with this code.
Since all my elements are short in length, everything work fine. However, when I want to add passage for introduction, the problems come. If I do not modify any properties, it work fine in mobile design. But in standard design, it would be too wide. I want to utilize 40%-50% in standard view. But when I set it in the css, the problem appear in mobile design. Mobile design will only blindly follow the 40%-50% rules, but I want it to be a 100% on mobile design. Thanks for all your help.
<meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
Since all my elements are short in length, everything work fine. However, when I want to add passage for introduction, the problems come. If I do not modify any properties, it work fine in mobile design. But in standard design, it would be too wide. I want to utilize 40%-50% in standard view. But when I set it in the css, the problem appear in mobile design. Mobile design will only blindly follow the 40%-50% rules, but I want it to be a 100% on mobile design. Thanks for all your help.
- Alex Wong 4
- July 21, 2016
- Like
- 0
How to perform URL check at apex code level?
My page is a form for user to input data. There are 4 fields for them to input URL, but not necessary. Therefore, validation rule at field level is not suitable for my case. And I want to search for a method to validate URL at apex code level.
Here is my code, and my 4 URL field are called Website__c, Facebook__c, SoundCloud__c and YouTube__c in custom object "artist".
Thank you.
Here is my code, and my 4 URL field are called Website__c, Facebook__c, SoundCloud__c and YouTube__c in custom object "artist".
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; if(artist.Id == null){ insert artist; } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
Thank you.
- Alex Wong 4
- July 15, 2016
- Like
- 0
How to show several error message of validation rules in the same time?
My page is a form for information inserting. There are 4 fields for URL input and I want to check for their format. I wrote 4 validation rules in the custom object for each fields. However, the error message just show up one each time, even 4 of them are all wrong. How can I show all 4 in the same time when users type it wrong for all at the same time?
Here is my apex code:
My validation rule at the field level:
Thank you.
Here is my apex code:
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; try{ if(artist.Id == null){ insert artist; } }catch (DMLException e) { if(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION')){ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter a valid URL.')); }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,string.valueof(e))); } return null; } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
My validation rule at the field level:
if(REGEX(Facebook__c,"^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$"),false,true)
Thank you.
- Alex Wong 4
- July 15, 2016
- Like
- 0
Responsive Design for VisualForce Page
I am quite new for VisualForce and want to ask a question. Is there any way on VisualForce to help me to have a responsive design on my page? Or I need to desgin the css to solve this problem? Thanks for your help.
- Alex Wong 4
- July 14, 2016
- Like
- 0
URL validation through apex
Since the field type URL cannot check for the data whether it is really a URL or not, I want to ask for how to write a controller for check the URL when submiting. Thank you for all your work!
- Alex Wong 4
- July 13, 2016
- Like
- 0
Cannot insert data through a public page
My page is a form which collect the data from public. When I insert data through a page which is public, it shows the below statement:
Authorization Required
You must first log in or register before accessing this page.
If you have forgotten your password, click Forgot Password to reset it.
The whole process works fine before, until I change the field inside the my custom objects. Is it related to the error?
Authorization Required
You must first log in or register before accessing this page.
If you have forgotten your password, click Forgot Password to reset it.
The whole process works fine before, until I change the field inside the my custom objects. Is it related to the error?
- Alex Wong 4
- July 13, 2016
- Like
- 0
Why data cannot be insert through a public page?
First of all, my page is a form designed for public input their information. Why data cannot be insert through a public page? Is there any permission needed to be set up? If I use my admin account and access page like this (https://ap2.visualforce.com/apex/form), the data can be recorded in the objects. However, when I access the public link like this (https://mycompanyname-developer-edition.ap2.force.com/artisitform/form), the data cannot be recorded even i submit the form. Thanks for your help.
- Alex Wong 4
- July 13, 2016
- Like
- 0
How can I change the visualforce page to a public one?
I am quite new for salesforce. How can I change the visualforce page to a public one? Thank you for your help.
- Alex Wong 4
- July 12, 2016
- Like
- 0
Is there a way to perform validation for apex:inputField?
I am creating a form in Visualforce. Since my form is a bit long, it is hard for users to remember the error message at the top and revise it. On top of the error message, I want to create a validation when users typing in their information.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.
- Alex Wong 4
- August 15, 2016
- Like
- 1
How to rename the attachments in custom objects?
In my application, I create a form for public to fill in thier information. There questions of all require public to insert attachment. The default name of the attachment are the name decidie by public, but it is hard for administraion. Thus, I want to rename it in a meaningful way:
(RecordID)_(UserName)_(DateOfCreate)_(Q).(Format)
RecordID is the name of the record of custom object.
UserName is the data insert by users in the field "Artist_English_Name__c"
DateOfCreate is the date of creating the record of custom object.
Q is the question that the attachment belongs to.
Format is the type of attachment indicated, as I need them for the name conversion in data export.
Because I want to trace back the attachment ie owned by who and which question.
At this stage, I only achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical_field2.png") by this code:
But I want to achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical.png").
The whole code for reference:
Thank you.
(RecordID)_(UserName)_(DateOfCreate)_(Q).(Format)
RecordID is the name of the record of custom object.
UserName is the data insert by users in the field "Artist_English_Name__c"
DateOfCreate is the date of creating the record of custom object.
Q is the question that the attachment belongs to.
Format is the type of attachment indicated, as I need them for the name conversion in data export.
Because I want to trace back the attachment ie owned by who and which question.
At this stage, I only achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical_field2.png") by this code:
objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'_'+objAttachmentt.Name;
But I want to achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical.png").
The whole code for reference:
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; Boolean isValidUrl = true; if(artist.Id == null){ if(artist.Website__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Website__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Website URL.')); isValidUrl = false; } } if(artist.Facebook__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Facebook__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Facebook URL.')); isValidUrl = false; } } if(artist.SoundCloud__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.SoundCloud__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Soundcloud URL.')); isValidUrl = false; } } if(artist.YouTube__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.YouTube__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Youtube URL.')); isValidUrl = false; } } if(isValidUrl){ insert artist; }else{ return null; } } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; objAttachment.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo1'+'_'+objAttachment.Name; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; objAttachment2.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo2'+'_'+objAttachment2.Name; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; objAttachment3.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo3'+'_'+objAttachment3.Name; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'_'+objAttachmentt.Name; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; objAttachments.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Stage'+'_'+objAttachments.Name; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; attachmentList = null; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
Thank you.
- Alex Wong 4
- August 04, 2016
- Like
- 1
Can apex:inputFile have the html5 validation function?
My web page is a form using html5 validation to check blank. All field in my form can use html5 to perform validation, except the inputFile field for uploading attachment. Can apex:inputFile have the html5 validation function? Or is there any way to perform validation for checking whether the attachment field is blank or not? Thanks.
- Alex Wong 4
- August 18, 2016
- Like
- 0
Is there a way to perform validation for apex:inputField?
I am creating a form in Visualforce. Since my form is a bit long, it is hard for users to remember the error message at the top and revise it. On top of the error message, I want to create a validation when users typing in their information.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.
For example, there are 2 field, users name and email. Users cannot leave the name field blank, if so, I want to show a message of "This field is required to fill in" beside the field. And for email field, I want to have another message to remind users to insert a valid email.
Is there anyway in visualforce to do so? Thanks for your help.
- Alex Wong 4
- August 15, 2016
- Like
- 1
How to achieve validation by jQuery in Visualforce?
I have seen this article and try to adopt this method.
Salesforce Form Validation Enhanced:
https://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/
However, I do not know why I get nothing happen even I have followed the step. Here is my code:
Thanks for your help.
Salesforce Form Validation Enhanced:
https://th3silverlining.com/2010/03/02/visualforce-form-validation-enhanced/
However, I do not know why I get nothing happen even I have followed the step. Here is my code:
<apex:page standardController="Artist__c" extensions="extattachfile" showHeader="false" sidebar="false"> <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <style type="text/css"> h1 {font-size: 150%; font-weight: bold;} h2 {font-size: ;} p { width:100%; font-size: 120%; text-align: justify; text-justify: inter-word;} .reddot {color: red; font-size:120%;} .textarea { height:200px; width:300px; border-radius: 5px;} .url {width:300px;} .title {font-size:175%;} .standard {width: 310px;} @media only screen and (min-width: 900px) { /* For desktop: */ p { width:890px; font-size: 120%; text-align: justify; text-justify: inter-word;} } .color { background-color: #F7F6D2; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -o-transition: all 1s ease; transition: all 1s ease; } </style> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"/> <apex:includescript value="{!$Resource.jQuery}"></apex:includescript> <apex:includescript value="http://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"></apex:includescript> </head> <script type="text/javascript"> $(document).ready(function() { $('[id$=artistform]').validate(); $('[id$=engname]').rules("add",{ required: true, }); $('[id$=email]').rules("add",{ required: true, email: true }); /* Customised the messages */ jQuery.validator.messages.required = "You better have entered a value.. or else!"; jQuery.validator.messages.equalTo = "No silly, you're supposed to type the same set of characters AGAIN."; }); </script> <apex:form styleclass="form" id="artistform"> <apex:pageBlock > <apex:pageMessages /> <div><b class="title">Artist Submission Form</b></div><br/> <br/> <h1>Artist / Group Information 表演者 / 團體資料</h1> <br/><br/> <br/> <div class="standard"> <h2 >Artist Name (English)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Artist_Group_Name_English__c}" label="" id="engname"/> </apex:panelGroup> <br/> </div> <br/> <br/> <div class="standard"> <h2 >Artist Biography (English)</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Artist_Group_Biography_English__c}" label="" styleClass="textarea" id="engbio"/> </apex:panelGroup> <br/><br/> </div> <br/> <div class="heading"> <h1>Name and Roles of Group Members (if applicable)</h1> <br/><br/> </div> <br/> <div class="standard"> <h2>Name and Roles of Group Members</h2><br/> <h2>團體成員姓名及崗位</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Member_Name_Role__c}" label="" styleClass="textarea"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >Photo of Artist : max 3 attachments</h2><br/> <apex:outputText styleClass="reddot" value="*"/> <br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputFile value="{!objAttachment.body}" fileName="{!objAttachment.name}" required="false" id="photo"/><br/></apex:panelGroup> <apex:inputFile value="{!objAttachment2.body}" fileName="{!objAttachment2.name}" required="false" /><br/> <apex:inputFile value="{!objAttachment3.body}" fileName="{!objAttachment3.name}" required="false" /> <br/><br/> </div> <br/> <div class="standard"> <h2>Website</h2><outputtext/><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Website__c}" label="" styleClass="url" id="web"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >Facebook</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.Facebook__c}" label="" styleClass="url" id="facebook"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >SoundCloud</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.SoundCloud__c}" label="" styleClass="url" id="soundcloud"/><br/> <br/> </div> <br/> <div class="standard"> <h2 >YouTube</h2><apex:outputText styleClass="reddot" value=""/><br/> <apex:inputField value="{!artist.YouTube__c}" label="" styleClass="url" id="youtube"/> <br/> </div> <br/><br/> <div class="standard"> <h2>Technical Rider : max 1 attachment</h2><br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputFile value="{!objAttachmentt.body}" fileName="{!objAttachmentt.name}" /><br/> </div> <br/> <div class="standard"> <h2>Stage Plot : max 1 attachment</h2> <br/> <apex:outputText styleClass="reddot" value=""/><br/> <apex:inputFile value="{!objAttachments.body}" fileName="{!objAttachments.name}" required="false" /><br/><br/> </div> <br/> <div class="heading"> <h1>Contact Information</h1> <br/><br/> </div> <br/> <div class="standard"> <h2>Contact Person</h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Contact_Person__c}" label="" id="contactperson"/> <br/> </apex:panelGroup> </div> <br/> <div class="standard"> <h2 >Contact No.</h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Contact_Number__c}" label="" id="contactno"/> <br/> </apex:panelGroup> </div> <br/> <div class="standard"> <h2>Email</h2><apex:outputText styleClass="reddot" value="*"/><br/> <apex:panelGroup styleClass="col02 requiredInput" layout="block"> <apex:panelGroup styleClass="requiredBlock" layout="block"/> <apex:inputField value="{!artist.Email__c}" label="" id="email"/> <br/> </apex:panelGroup> </div> <br/> <br/> <div> <apex:commandButton action="{!save}" value="Save"/> </div> <script> var addclass = 'color'; var $cols = $('.standard').click(function(e) { $cols.removeClass(addclass); $(this).addClass(addclass); }); </script> </apex:pageBlock> </apex:form> <apex:pageMessages /> </apex:page>
Thanks for your help.
- Alex Wong 4
- August 15, 2016
- Like
- 0
Red bar of the input field
In my page, there are some field are required the users to insert. However, I cannot use the required="true" method in the apex:inputfield. Because this will lead to a standard error message, which cannot shows with the custom error message at the same time. Thus, I remove all the checking in the system and setup checking in the apex code, to generate a custom error message. Is there any althernative to show the red bar in order to alert the users? Thanks.
- Alex Wong 4
- August 12, 2016
- Like
- 0
Is there a way to check phone number format?
If I try the phone format in the field, it can provide a phone format.However, even I type in character, the system still accept it. If I use the number format, it can restrict users only to type number. However, the outlook of data will become a number format with this sign (","). How can I solve this problem? Thank you.
- Alex Wong 4
- August 12, 2016
- Like
- 0
Is it possible to show standard and custom error message at the same time?
I want to know that is there a method to show the standard error message and custom error message at the same time? Also, in my script, there are several custom error message. Is it possilbe to show them at the same time?
Here is my code:
Thank you for your help.
Here is my code:
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; Boolean isValidUrl = true; if(artist.Id == null){ if(artist.Website__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Website__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Website URL.')); isValidUrl = false; } } if(artist.Facebook__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Facebook__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Facebook URL.')); isValidUrl = false; } } if(artist.SoundCloud__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.SoundCloud__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Soundcloud URL.')); isValidUrl = false; } } if(artist.YouTube__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.YouTube__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Youtube URL.')); isValidUrl = false; } } if(isValidUrl){ insert artist; }else{ return null; } } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; List<String> splitStrList = objAttachment.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachment.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo1'+'.' + fileExtension; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; List<String> splitStrList = objAttachment2.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachment2.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo2'+'.' + fileExtension; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; List<String> splitStrList = objAttachment3.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachment3.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo3'+'.' + fileExtension; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; List<String> splitStrList = objAttachmentt.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'.' + fileExtension; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; List<String> splitStrList = objAttachments.Name.Split('\\.'); String fileExtension = splitStrList[1]; objAttachments.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Stage'+'.' + fileExtension; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; attachmentList = null; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
Thank you for your help.
- Alex Wong 4
- August 11, 2016
- Like
- 0
How to rename the attachments in custom objects?
In my application, I create a form for public to fill in thier information. There questions of all require public to insert attachment. The default name of the attachment are the name decidie by public, but it is hard for administraion. Thus, I want to rename it in a meaningful way:
(RecordID)_(UserName)_(DateOfCreate)_(Q).(Format)
RecordID is the name of the record of custom object.
UserName is the data insert by users in the field "Artist_English_Name__c"
DateOfCreate is the date of creating the record of custom object.
Q is the question that the attachment belongs to.
Format is the type of attachment indicated, as I need them for the name conversion in data export.
Because I want to trace back the attachment ie owned by who and which question.
At this stage, I only achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical_field2.png") by this code:
But I want to achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical.png").
The whole code for reference:
Thank you.
(RecordID)_(UserName)_(DateOfCreate)_(Q).(Format)
RecordID is the name of the record of custom object.
UserName is the data insert by users in the field "Artist_English_Name__c"
DateOfCreate is the date of creating the record of custom object.
Q is the question that the attachment belongs to.
Format is the type of attachment indicated, as I need them for the name conversion in data export.
Because I want to trace back the attachment ie owned by who and which question.
At this stage, I only achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical_field2.png") by this code:
objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'_'+objAttachmentt.Name;
But I want to achieve this ("a002800000i5q8UAAQ_Alex_2016-08-03_Technical.png").
The whole code for reference:
public class extattachfile { Public attachment objAttachment{get;set;} Public attachment objAttachment2{get; set;} Public attachment objAttachment3{get; set;} Public attachment objAttachmentt{get; set;} Public attachment objAttachments{get; set;} Public Artist__c artist{get; set;} Public extattachfile(apexpages.standardcontroller stdCon) { objAttachment = new Attachment(); objAttachment2 = new Attachment(); objAttachment3 = new Attachment(); objAttachmentt = new Attachment(); objAttachments = new Attachment(); artist= new Artist__c (); } public PageReference save() { Boolean checkAttachment = false; Boolean isValidUrl = true; if(artist.Id == null){ if(artist.Website__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Website__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Website URL.')); isValidUrl = false; } } if(artist.Facebook__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.Facebook__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Facebook URL.')); isValidUrl = false; } } if(artist.SoundCloud__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.SoundCloud__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Soundcloud URL.')); isValidUrl = false; } } if(artist.YouTube__c != null){ Pattern emailPattern = Pattern.compile('^((http|https)://)??(www[.])??([a-zA-Z0-9]|-)+?([.][a-zA-Z0-9(-|/|=|?)??]+?)+?$'); Boolean isMatch = emailPattern.matcher(artist.YouTube__c).matches(); if(!isMatch){ objAttachment.Body = null; objAttachment2.Body = null; objAttachment3.Body = null; objAttachmentt.Body = null; objAttachments.Body = null; ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please provide a valid Youtube URL.')); isValidUrl = false; } } if(isValidUrl){ insert artist; }else{ return null; } } List<Attachment> attachmentList = new List<Attachment>(); if(objAttachment.Body != null){ objAttachment.ParentId = artist.id; objAttachment.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo1'+'_'+objAttachment.Name; attachmentList.add(objAttachment); checkAttachment = true; } if(objAttachment2.Body != null){ objAttachment2.ParentId = artist.id; objAttachment2.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo2'+'_'+objAttachment2.Name; attachmentList.add(objAttachment2); checkAttachment = true; } if(objAttachment3.Body != null){ objAttachment3.ParentId = artist.id; objAttachment3.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Photo3'+'_'+objAttachment3.Name; attachmentList.add(objAttachment3); checkAttachment = true; } List<Attachment> attachmentListother = new List<Attachment>(); if(objAttachmentt.Body != null){ objAttachmentt.ParentId = artist.id; objAttachmentt.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Technical'+'_'+objAttachmentt.Name; attachmentList.add(objAttachmentt); } if(objAttachments.Body != null){ objAttachments.ParentId = artist.id; objAttachments.Name = artist.Id+'_'+artist.Artist_Group_Name_English__c+'_'+String.valueOf(system.today())+'_Stage'+'_'+objAttachments.Name; attachmentList.add(objAttachments); } Insert attachmentListother; if(attachmentList.size() > 0 && checkAttachment){ insert attachmentList; attachmentList = null; // if successfully inserted new contact, then displays the thank you page. return Page.ack; }else{ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Please attach at least one photo attachment.')); return null; } } }
Thank you.
- Alex Wong 4
- August 04, 2016
- Like
- 1
How to write a trigger for renaming attachments in custom objects?
I am quite new for salesofrce and I want to write a trigger to modify attachments name after user inserting the attachments. For my situation, my page is form for public input their information. It includes 3 question that requires users to insert attachments. One question can allow users to upload 1-3 attachmetns, and the other two require only 1. Since I want to classify them from the their name, I want a trigger to rename the attachments after insert. Thank you for your great effort.
- Alex Wong 4
- August 02, 2016
- Like
- 0