You need to sign in to do that
Don't have an account?

How to display error Message
Hi
I have created a class for file uploading.its working fine me now.but i want to put restriction like that if attachement then save otherwise it will display error message...How to achieve this
I have created a class for file uploading.its working fine me now.but i want to put restriction like that if attachement then save otherwise it will display error message...How to achieve this
public class FormCurriculumController { public Purchase_Order__c curriculum {get; set;} public Boolean privacy {get; set;} public Boolean saved {get; set;} public String styleClass {get; set;} public Transient Blob resume {get; set;} public String contentType {get; set;} public String fileName {get; set;} public boolean showC1RecordType {get;set;} public boolean showC2RecordType {get;set;} private Id c1RecordTypeId; private Id c2RecordTypeId; //ublic FormCurriculumController () { //curriculum = new Purchase_Order__c(); //saved = false; //} public FormCurriculumController(ApexPages.StandardController controller) { c1RecordTypeId = Schema.SObjectType.Purchase_Order__c.getRecordTypeInfosByName().get('C1').getRecordTypeId(); c2RecordTypeId = Schema.SObjectType.Purchase_Order__c.getRecordTypeInfosByName().get('C2').getRecordTypeId(); curriculum= new Purchase_Order__c(); curriculum= (Purchase_Order__c)controller.getRecord(); String isButtonClicked = Apexpages.currentPage().getParameters().get('setDefaultValues'); if(isButtonClicked == 'true'){ setDefaultValues(); } showC1RecordType = false; showC2RecordType = false; if(curriculum.RecordTypeId == c1RecordTypeId){ showC1RecordType = true; showC2RecordType = false; } else if(curriculum.RecordTypeId == c2RecordTypeId){ showC1RecordType = false; showC2RecordType = true; } } public void setDefaultValues(){ String quoteId = Apexpages.currentPage().getParameters().get('quoteId'); Quote__c quote = [Select o.id, o.name, o.Quantity_formula__c, o.Opportunity_Product_Detail__r.Opportunity__c, o.Opportunity__c, o.Record_type_name__c,o.Company_Name__c,Opportunity_Product_Detail__r.Opportunity__r.Account__c from Quote__c o WHERE O.id=:quoteId]; //system.assert(false,quote); curriculum.Opportunity__c = quote.Opportunity_Product_Detail__r.Opportunity__c; curriculum.Quote__c = quote.id; curriculum.Company__c = quote.Opportunity_Product_Detail__r.Opportunity__r.Account__c; if(quote.Record_type_name__c == 'C1'){ curriculum.RecordTypeId = c1RecordTypeId; } else { curriculum.RecordTypeId = c2RecordTypeId; } } public PageReference save() { try { if (!privacy) { ApexPages.Message reqMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please upload recent Purchase Order before saving the record'); ApexPages.addMessage(reqMsg); return null; } if( ! Test.isRunningTest() ) { insert(curriculum); } if (resume != null) { Attachment attach = new Attachment(); attach.Body = resume; attach.Name = fileName; attach.ContentType= contentType; attach.ParentId = curriculum.id; try { insert(attach); return new PageReference('/'+curriculum.id); } catch (Exception ex) { ApexPages.addMessages(ex); return null; } } update curriculum; saved = true; } catch(Exception ex) { ApexPages.addMessages(ex); } return null; } }
<apex:pageMessages/>
on the page and the message will display. You have to choose Serverity properly because it will display different kind of alert view
new ApexPages.Message(ApexPages.Severity.FATAL, 'my error msg');