• Sujith Nair
  • NEWBIE
  • 24 Points
  • Member since 2014
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
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:
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.
How does one test loading an opportunity record page?

There is an action that fires when the opportunity page is loaded (via a visualforce page).  I know the controller extension and action work because its been proven via the UI.  Just not sure to how properly write a unit test to load the page, and thus trigger the action to run.
  • August 11, 2016
  • Like
  • 0
Hi,

How to create case from Facebook??

Thanks,
 
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:
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.