function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
@GM@GM 

why Message is not displaying ??

trigger ToDisplayMessage on NEWOPTION__c (after insert) {
    List<NEWOPTION__c> ls=Trigger.new;
    for(NEWOPTION__c nw:ls)
    {
        if(nw.Opt__c == 'yes')
        {
            if(nw.Primary_interest__c != null && nw.Secondary_interest__c !=null)
            {
                if(ApexPages.currentPage() != null)
                {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.info,'I like '+nw.Primary_interest__c+' specifically ‘+nw.Secondary_interest__c'));
                }
            }
        }
     }
}

 

RockzRockz

Hi..

 

try below code :

 

trigger ToDisplayMessage on NEWOPTION__c (after insert) {
    List<NEWOPTION__c> ls=Trigger.new;
    for(NEWOPTION__c nw:ls)
    {
        if(nw.Opt__c == 'yes')
        {
            if(nw.Primary_interest__c != null && nw.Secondary_interest__c !=null)
            { 
                    nw.addError('I like '+nw.Primary_interest__c+' specifically ‘+nw.Secondary_interest__c');
                
            }
        }
     }
}

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them.

 

Thnaks,

Cool Sfdc

 

tggagnetggagne

The way to handle this is to use addError() in your trigger, and an exception handler in your controller.

 

Instead consider:

 

if (nw.Primary_interest__c != null && nw.Secondary_interest__c !=null)
    nw.addError(
        String.Format(
            'I like {0} specifically {1}',
            new string[] {
                nw.Primary_Interest__c,
                nw.Secondary_Interest__c
            }
        )
try {
    // your dml operation
}
catch (System.DmlException dex) {
    if(ApexPages.currentPage() != null)
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.info, dex.getDMLMessage();
}

The bottom code chunk is in your controller.

 

You will want to check-out 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_SObject_instance_methods.htm for information on addError() and

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_exception_methods.htm for a list of all the special methods you can call on DML exceptions.

 

sunny522sunny522
U can display error message with addError() .
trigger testing2 on Account (after insert,after update) {

for (Account newOpp : Trigger.new) {

newOpp .addError('ok');


}
}

for more details visit the blog
http://salesforceglobe4u.blogspot.in/2013/12/how-to-display-error-message-from.html