You need to sign in to do that
Don't have an account?
Alex Wong 4
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.
All Answers
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageMessages.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messages.htm
Here is the background for my page. It is a form to fill in information, and also attachment. Some of the essential information and attachment are
required to fill in. However, if I input none of the field and attachment, it will only show the standard error message first, but I want to show all. Only when I input all the field with standard error message, and the attachment field is blank, the custom error message finally shows.
Here is my page code for your reference: