• Oliver Jones Rajkumar
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 11
    Replies
Hi All,

    Is it possible to build a SOQL query to retrieve/show the count of closed and open opportunities under each accounts? I would to execute this code in the query editor in developer console.

Help and Thanks. 
Hi All,

I have the following code that checks duplicate for email and phone for contact records. For instance, R1 contact record can have phone, email as "123","a@abc.com" and R2 contact record can have "123","b@abc.com". Error thrown only when BOTH EMAIL, PHONE matches existing records.
This works for single record insert/update, but when bulk insert through data import wizard if I insert 10 records with same email,phone values, 9 records are inserted with duplicate values, with error on the 10th record. 

Need help.
Thanks.

-----------------------------

trigger ContactTrigger_AT on Contact (before insert, before update)
{
    Set<String> setEmail = new set<String>();
    Set<String> setPhone = new set<String>();
    Set<String> setExistingEmail = new set<String>();
    Set<String> setExistingPhone = new set<String>();
    
    for(Contact con : Trigger.new)
    {
        setEmail.add(con.email);
        setPhone.add(con.Phone);
    }
    for(Contact con : [SELECT Phone,Email FROM contact WHERE email in : setEmail AND phone in : setPhone])
    {
        setExistingEmail.add(con.email);
        setExistingPhone.add(con.Phone);
    }
       if(Trigger.isInsert||Trigger.isUpdate)
    for(Contact a:trigger.new)
     {
        if(setExistingEmail.contains(a.email) && setExistingPhone.contains(a.Phone))
        {
            a.adderror('This Phone and email already exists');
        }
    }

}
Hi All, 

I have the following code. I want a bulkified version for it. This trigger updates Opprtunity_Email__c custom field on Account with a recently inserted email from Opportunity_Email__c custom field in Opportunity.

trigger opportunityEmailonAccount_AT on Opportunity (after insert) {
    for(Opportunity opp : Trigger.new){
        Set<ID> accids = new Set<ID>();
        accids.add(opp.AccountId);
        Account acc = [Select Id,Name,Opportunity_Email__c From Account where Id in : accids];
        if(opp.Opportunity_Email__c != null && accids != null ) {
            acc.Opportunity_Email__c = opp.Opportunity_Email__c;
        }
        update acc;
    }
}
Hi All,

I'm a begginer in Apex Triggers. The following is a trigger I used but its not working. My Trigger should not allow ANY USERS to delete the record if the record creater (User) becomes INACTIVE. This trigger never allowed me to delete a record eventhough the User is active. Help n Thanks.

trigger  preventdelete  on  Loan__c (before delete){
    for(Loan__c  loan:Trigger.old){
          if(loan.CreatedBy.IsActive == FALSE ){
         loan.addError('You cant delete this record since it is created by an inactive user');
       }
     }
   }
Hi All,

I need some help regarding the usage of External IDs during data import wizards for insert, update, upsert etc,. Thanks.
Hi All,

I have the following code that checks duplicate for email and phone for contact records. For instance, R1 contact record can have phone, email as "123","a@abc.com" and R2 contact record can have "123","b@abc.com". Error thrown only when BOTH EMAIL, PHONE matches existing records.
This works for single record insert/update, but when bulk insert through data import wizard if I insert 10 records with same email,phone values, 9 records are inserted with duplicate values, with error on the 10th record. 

Need help.
Thanks.

-----------------------------

trigger ContactTrigger_AT on Contact (before insert, before update)
{
    Set<String> setEmail = new set<String>();
    Set<String> setPhone = new set<String>();
    Set<String> setExistingEmail = new set<String>();
    Set<String> setExistingPhone = new set<String>();
    
    for(Contact con : Trigger.new)
    {
        setEmail.add(con.email);
        setPhone.add(con.Phone);
    }
    for(Contact con : [SELECT Phone,Email FROM contact WHERE email in : setEmail AND phone in : setPhone])
    {
        setExistingEmail.add(con.email);
        setExistingPhone.add(con.Phone);
    }
       if(Trigger.isInsert||Trigger.isUpdate)
    for(Contact a:trigger.new)
     {
        if(setExistingEmail.contains(a.email) && setExistingPhone.contains(a.Phone))
        {
            a.adderror('This Phone and email already exists');
        }
    }

}
Hi All, 

I have the following code. I want a bulkified version for it. This trigger updates Opprtunity_Email__c custom field on Account with a recently inserted email from Opportunity_Email__c custom field in Opportunity.

trigger opportunityEmailonAccount_AT on Opportunity (after insert) {
    for(Opportunity opp : Trigger.new){
        Set<ID> accids = new Set<ID>();
        accids.add(opp.AccountId);
        Account acc = [Select Id,Name,Opportunity_Email__c From Account where Id in : accids];
        if(opp.Opportunity_Email__c != null && accids != null ) {
            acc.Opportunity_Email__c = opp.Opportunity_Email__c;
        }
        update acc;
    }
}
Hi All,

I'm a begginer in Apex Triggers. The following is a trigger I used but its not working. My Trigger should not allow ANY USERS to delete the record if the record creater (User) becomes INACTIVE. This trigger never allowed me to delete a record eventhough the User is active. Help n Thanks.

trigger  preventdelete  on  Loan__c (before delete){
    for(Loan__c  loan:Trigger.old){
          if(loan.CreatedBy.IsActive == FALSE ){
         loan.addError('You cant delete this record since it is created by an inactive user');
       }
     }
   }
Hi All,

I need some help regarding the usage of External IDs during data import wizards for insert, update, upsert etc,. Thanks.