• niven sf
  • NEWBIE
  • 25 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 24
    Replies
Hi All ,
I am facing issue to write test class of below trigger please help .

trigger UpdateRelatedUser on InContactData__c (before insert, after update ,before update) {
    set<Id> userid=new set<Id>();
     for(user u:[select id from user where Map_With_Incontact__c=true])
     {
         userid.add(u.id);
     }
      User Ult=[select id,InContact_AgentID__c from user where id in:userid];
     for(IncontactData__c ic:trigger.new)
     {
         if(trigger.isInsert || Trigger.isBefore)
         {
             
         if(ic.Agent_ID__c==ult.InContact_AgentID__c)
         {
           ic.Related_User__c=ult.id;  
         }
     }
     }
     
}
We have person accounts enabled in our org. We have business accounts with a custom picklist field called Business Account Type with the values "Headquarters" or "Branch Office". If "Branch Office" is selected, a validation rule triggers on save that will require a value in a custom text field called Branch ID (Branch_ID__c). On person account is the same Branch ID field and if it is populated, a custom lookup field to account called Company (Company__c) should auto-poulate with the account name.

I have tried using the process automation tools; flow and process builder but was unable to get them to work. I think an apex trigger is required to resolve this issue. I have even tried to write the trigger myself but I have very little experience with triggers. Here is what I have so far which I don't think is anything close to what I need:
 
trigger updateCompanyLookup on Account (after insert) {
    List<Id> accountIdList = new List<Id>();
    Map<Id,Id> accNameMap = new Map<Id,Id>();
    for (Account pa : Trigger.new) {
        accountIdList.add(pa.Id);
    }
    for(Account ba : [SELECT Branch_ID__c FROM Account WHERE id in :accountIdList]) {
        accNameMap.put(ba.Id,ba.Branch_ID__c);
    }
    
    for(Account pa : Trigger.new) {
        if(accNameMap.containsKey(pa.Id))
            pa.Company__c = accNameMap.get(pa.Id);
    }
}

 
I am new to Apex and need help with creating an Apex trigger to update an unrelated record in another object. Our Salesforce instance is being used for both Sales teams tracking in addition to tracking customer's utilization of our services. When a customer signs up for our service, we create an account (with the account type of customer), contact and insert data into several other custom objects. When the account is created, I need to grab the account name (an email address) and then search contacts (other than the one related to the newly created account) and update a checkbox to true 
Any help I can get will be greatly apprecated.

Dan

Would someone be able to help me write a trigger so that when an account address and phone number change, the address and phone number on all contacts change?  In my perfect world, the phone number would only change on the contact IF before the update they were the same number.  Since I am not a code writer other than when I have to be, I am not sure that is even possible.

 

 

Thanks!

  • August 23, 2012
  • Like
  • 0