• Muhammad.Bilal
  • NEWBIE
  • 0 Points
  • Member since 2016
  • IT Manager

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hi,
We want to create a composite unique value comprises two fields
1. Email
2. data_access(true/false)
The system should allow entry if one of the value in these 2 fields is unique but we cannot allow both values together to have a duplicate record.

The trigger below works absolutely fine when inserting/updating new record but when I try to merge 2 records, the system generates an error and won't allow merging unless I choose the data_access value to be false always.


trigger DuplicateEmailsInContacts on Contact (before insert, before update) {
   Integer EmailCount = 0;
    FOR(Contact c: Trigger.New){
        IF(c.Email !='' && c.Email != NULL && c.Data__c==True){
            EmailCount = [SELECT count() FROM Contact WHERE EMAIL =:c.Email AND Data_Access__c=:True];
            IF(EmailCount > 0){
                c.Email.addError('A user with the same email already exits for data access, please either use a differnet email or uncheck Data Access');
            }
        }
    }
}

Any help is highly appreciated

Thanks,

Muhammad
Hi,
We want to create a composite unique value comprises two fields
1. Email
2. data_access(true/false)
The system should allow entry if one of the value in these 2 fields is unique but we cannot allow both values together to have a duplicate record.

The trigger below works absolutely fine when inserting/updating new record but when I try to merge 2 records, the system generates an error and won't allow merging unless I choose the data_access value to be false always.


trigger DuplicateEmailsInContacts on Contact (before insert, before update) {
   Integer EmailCount = 0;
    FOR(Contact c: Trigger.New){
        IF(c.Email !='' && c.Email != NULL && c.Data__c==True){
            EmailCount = [SELECT count() FROM Contact WHERE EMAIL =:c.Email AND Data_Access__c=:True];
            IF(EmailCount > 0){
                c.Email.addError('A user with the same email already exits for data access, please either use a differnet email or uncheck Data Access');
            }
        }
    }
}

Any help is highly appreciated

Thanks,

Muhammad

Within an if statement I want to print a line break to the screen. However, there seems to be no easy way to do this in any forums thus far. I found a few answers, but none of them seem to work within the TRUE argument in my IF conditional statement. Here is a snippet of my code:
{! IF (relatedTo.Budget_In_Stream_Video__c != null, "In-Stream Video", null)}
{! IF (relatedTo.Budget_Interactive_InStream_Video__c != null, "Interactive In-Stream Video", null)}

Outputs

I have tried \n, <br/>, and many others with little or no success. BR() only gives this output:
In-Stream Video_BR_ENCODED_Interactive In-Stream Video

 

Someone please tell me I'm crazy and this isn't that hard and doesn't require some crazy hack...