• Parmeshwar Bhore 1010011
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 7
    Replies
Avoid dupalication Trgigger for Befor insert && Befor Update for email field , but in befor update when you update only email field with again same email  then get error. dont show the error for others field updation.as like phone,title etc. 
public class ContactNameUpdate {
    // Method to handle the contact inserts.
    public static void newContactCreated(List<Account> accList){
        List<Contact> conList = new List<Contact>();
        for(Account acc : accList) {
              Contact con = new Contact(AccountId = acc.Id);
              List<String> nameStr = acc.Name.split(' ');
              if(nameStr.size()>0)
                 con.LastName = nameStr[0];
              if(nameStr.size()>1)
                  con.FirstName = nameStr[1];
                  
            con.Email = 'info@websitedomain.tld';
            con.Only_Default_Contact__c = TRUE;
            conList.add(con);
        }
        insert conList;        
    }
    public static void updateCheckboxOnAccount(List<Contact> contactList){
        Set<Id> accountIds = new Set<Id>();
        for(Contact con : contactList) {
             accountIds.add(con.AccountId);
        }
        
        List<Account> updatedAccounts = new List<Account>();
        for(AggregateResult ar : [select count(id) , AccountId from Contact where AccountId IN :accountIds group by AccountId having count(id)  >1 ]){
            updatedAccounts.add(new Account(Id = (Id)ar.get('AccountId'), Only_Default_Contact__c=false));    
        }
        
        if(!updatedAccounts.isEmpty())
            update updatedAccounts;
    }
}
Write a trigger for befor delete on Note Object And Test class for that Trigger. give any solution.
I have the requirement to disable  users access (users within a custom Profile) from being able to update their own profile .
For that have to write a trigger to restrict the user to access/not update his own profile.
User-added imageIts not visiable for  login user means login user cant see its own personal information. If he want change/edit in personal information then he contact with Admin . How can I restrict that.Help me.
1.Write a trigger to prevent duplicate Account creation with same name, , email and phone.
2.When lead is getting created add ''DR'' prefix to all leads names.
3.Write test class for both triggers
 
public class ContactNameUpdate {
    // Method to handle the contact inserts.
    public static void newContactCreated(List<Account> accList){
        List<Contact> conList = new List<Contact>();
        for(Account acc : accList) {
              Contact con = new Contact(AccountId = acc.Id);
              List<String> nameStr = acc.Name.split(' ');
              if(nameStr.size()>0)
                 con.LastName = nameStr[0];
              if(nameStr.size()>1)
                  con.FirstName = nameStr[1];
                  
            con.Email = 'info@websitedomain.tld';
            con.Only_Default_Contact__c = TRUE;
            conList.add(con);
        }
        insert conList;        
    }
    public static void updateCheckboxOnAccount(List<Contact> contactList){
        Set<Id> accountIds = new Set<Id>();
        for(Contact con : contactList) {
             accountIds.add(con.AccountId);
        }
        
        List<Account> updatedAccounts = new List<Account>();
        for(AggregateResult ar : [select count(id) , AccountId from Contact where AccountId IN :accountIds group by AccountId having count(id)  >1 ]){
            updatedAccounts.add(new Account(Id = (Id)ar.get('AccountId'), Only_Default_Contact__c=false));    
        }
        
        if(!updatedAccounts.isEmpty())
            update updatedAccounts;
    }
}
User-added imageIts not visiable for  login user means login user cant see its own personal information. If he want change/edit in personal information then he contact with Admin . How can I restrict that.Help me.
1.Write a trigger to prevent duplicate Account creation with same name, , email and phone.
2.When lead is getting created add ''DR'' prefix to all leads names.
3.Write test class for both triggers