+ Start a Discussion
Soundar Raj PonpandiSoundar Raj Ponpandi 

Error message display in vf page

Hi , 

I am trying to display a error message in vf page based on below condition.

1. Case assignment is related list in case . 
2. There is one picklist field in case assignment object.values are primary, secondary and other.
3. We can create a record with primary at only one time. 
4. It should be showing error message whenever trying to create a record with primary again.

can anyone please advise me ... how can I achieve this working flow ...

Best Answer chosen by Soundar Raj Ponpandi
Soundar Raj PonpandiSoundar Raj Ponpandi
Hi EveryOne,

I achieved by myself (Using Trigger) . Please refer the below simplest code.


trigger PrimaryAssociateType on Case_Associate__c (Before Insert) {
    Set<Id> caseId = New Set<Id>();
    Map<Id,Id> casAsTpe  = New Map<Id,Id>(); 
    For(Case_Associate__c  ca : Trigger.New){
        If(ca.Case_Number__c != Null){
            System.debug('Case Number | ' + CaseId);
    IF(CaseId.size() > 0){
        //Case cs = [Select id,(Select id,name,Case_Number__c from Case_Associate__c Where Case_Number__c =:CaseId) CaseNumber from Case];
        List<Case_Associate__c> cas = [Select id,name,Case_Number__c,Associate_Type__c from Case_Associate__c Where Case_Number__c =:CaseId AND Associate_Type__c = 'Primary'];
    	System.debug('Case Associate Type With Primary |' + cas);
        System.debug('Size Of Primary | ' + cas.Size());
        IF(cas.Size() > 0){
            for(Case_Associate__c  cas1 : Trigger.New){
               cas1.addError('Primary Associate Type was Already Created. So Please Choose "Secondary" or "Other" ');

           /* ApexPages.addMessage(New ApexPages.message(ApexPages.Severity.ERROR, 'Primary Associate Type was Already Created'));
            System.debug('Error Message | ' + New ApexPages.message(ApexPages.Severity.ERROR, 'Primary Associate Type was Already Created'));*/