• ransa
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hi,


I am facing a problem in my trigger class. I am using Trigger Helper class for all my business logic. Here in this example, my "businessRule1" method validate the record, add error for invalid case then perform the business logic. The "businessRule2" is independent from "businessRule1" and should call only if record is not containing any error.

One way is to implement this is "businessRule1" should return some flag "result" that every thing is OK or not.

Here I just want to know :

1. Do we have any other alternative way for this?
2. Any helper method exists like.. "hasError", "isError" on object (i checked but didn't find anything related to this on SObject)
3. What if I want to get all error messages here?
4. We can use "ApexPages" helper methods in our custom controller class but what about normal Apex classes or Triggers?

trigger MyTrigger on Test__c (before update) {
    TestHelper.businessRule1(Trigger.new);
    
    boolean hasError = false;
    // hasError = ApexPages.hasMessages();
    
    if(!hasError) {
         TestHelper.businessRule2(Trigger.new);
    }
}

---------------------------
public class TestHelper{
    public static void businessRule1(List<Test__c> newList){
        if(true){ // failed in some business condition
            newList.get(0).addError('Test Error');
//          newList.get(0).name.addError('Test Error on field');
        }
    }
    
    
    public static void businessRule2(List<Test__c> newList){
        // perform some other business logic here
    }
}

 Thanks in advance.

  • February 01, 2012
  • Like
  • 0

Hi,

 

We have a requirement where User can also search for Contact using "Email" fields in lookup.

 

For example :

1. Open a Case

2. Click on the Contact's Lookup icon
3. Search for the contact using email address as criteria

 

For this, I can't go with custom "lookup filter" page as I have to use it in standard Case Page Layout. I also tried with "Lookup Filter" and "Search Filter Fields" but didn't get any success .

 

Thanks in advance

  • December 09, 2011
  • Like
  • 0

Hi,


I am facing a problem in my trigger class. I am using Trigger Helper class for all my business logic. Here in this example, my "businessRule1" method validate the record, add error for invalid case then perform the business logic. The "businessRule2" is independent from "businessRule1" and should call only if record is not containing any error.

One way is to implement this is "businessRule1" should return some flag "result" that every thing is OK or not.

Here I just want to know :

1. Do we have any other alternative way for this?
2. Any helper method exists like.. "hasError", "isError" on object (i checked but didn't find anything related to this on SObject)
3. What if I want to get all error messages here?
4. We can use "ApexPages" helper methods in our custom controller class but what about normal Apex classes or Triggers?

trigger MyTrigger on Test__c (before update) {
    TestHelper.businessRule1(Trigger.new);
    
    boolean hasError = false;
    // hasError = ApexPages.hasMessages();
    
    if(!hasError) {
         TestHelper.businessRule2(Trigger.new);
    }
}

---------------------------
public class TestHelper{
    public static void businessRule1(List<Test__c> newList){
        if(true){ // failed in some business condition
            newList.get(0).addError('Test Error');
//          newList.get(0).name.addError('Test Error on field');
        }
    }
    
    
    public static void businessRule2(List<Test__c> newList){
        // perform some other business logic here
    }
}

 Thanks in advance.

  • February 01, 2012
  • Like
  • 0