function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rmranjith8881.3927046400771116E12rmranjith8881.3927046400771116E12 

Trigger

Hi Everyone,

I have two custom fields(below) on opportunity where Record Type="Rec1"
Donor_nme__c(Text)
Donor_Mobile__c(phone).
I want to update these fields from contact.

Can any one help me out?

Thanks in advance?

ezdhanhussainezdhanhussain
This post May help You

http://salesforce.stackexchange.com/questions/16886/trigger-based-on-record-type-to-show-the-result-as
rmranjith8881.3927046400771116E12rmranjith8881.3927046400771116E12
Thanks for your reply ezdhanhussain,
now i made a trigger like this:

trigger updateContactinfo on Opportunity (before insert,before update) {
        set<id> AccountIDSet = new set<id>();
        map<id,contact> AccountContactMap = new map<id,contact>();
        List<Opportunity> lstOppToUpdate=new List<Opportunity>();
        RecordType rt = [SELECT Id,Name FROM RecordType WHERE Name = 'Feast Donor' Limit 1];
       
        for(Opportunity opp1:Trigger.new){
            if(opp1.RecordtypeId==rt.Id){
                    AccountIDSet.add(opp1.id);

                   //opp1.RecordType = [select Id from RecordType where Name = 'Feast Doner' and SobjectType = 'Opportunity '];
             }
         }
         List<contact> TempLst = [select id,name,phone,Account.Name from contact where Id in : AccountIDSet];
        for(Contact TempContactObj : TempLst)
        {
            AccountContactMap.put(TempContactObj.id, TempContactObj);
       
        }
                  
               for(Opportunity opp: [Select AccountId, Donor_Nme__c, Donor_Mobile__c from Opportunity where AccountId IN: AccountContactMap.KeySet()]){
                    opp.Donor_Nme__c=AccountContactMap.get(opp.Id).Name;
                    opp.Donor_Mobile__c=AccountContactMap.get(opp.Id).phone;
                    lstOppToUpdate.add(opp);
                }
                                   update lstOppToUpdate;
}

It is saved fine,but when i create new opportunity or editing existing Opportunity it won't update the donor name and donor mobile no from contact.

Can you help me out?

Thanks in advance.