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
neshnesh 

give your knowledge here-Create a New Record on Custom Object when field on Standard Object changes-

Hi

    Create a New Record on Custom Object when field on Standard Object (OPPORTUNITY)changes.

when opportunity object field changes (opp.record_type__c=='One timedonations' &&  opp.StageName=='pledged' && opp.Probability==100).its automatically create a New Record on Custom Object -name :One timedonations'.when i update opp object that also update on corresponding record on onetimedonation custom object. please correct my code.

 

 

trigger createonedonationrecord on Opportunity ( after insert,AFTER UPDATE)
{
  Opportunity opp=Trigger.new[0];
 
    if( opp.record_type__c=='One timedonations' &&  opp.StageName=='pledged' && opp.Probability==decimal.valueof(100) && OPP.npe03__Recurring_Donation__c==NULL)
    {         
    
              OneTimedonation__c  td1=new OneTimedonation__c();
              
              integer tds1=[select count() from OneTimedonation__c where Is_one_time_donation_created__c=false];
              if(tds1 ==0)
              {
              //td1=[select id,Organization__c,amount__c,Donation_Types__c from OneTimedonation__c where Is_one_time_donation_created__c=false];
              td1.Is_one_time_donation_created__c=True;
              td1.amount__c =opp.Amount;
              td1.Organization__c=opp.Accountid;
              td1.Campaign__c=opp.Campaignid;
              td1.Donation_Types__c=opp.Donation_type__c;
             // tdl.onetimedonationdone__c=true;
              insert td1;
              }
         if(trigger.isupdate)
            {
           
               // OneTimedonation__c  td1=new OneTimedonation__c();
              integer cntac1 =[select count() from OneTimedonation__c where Organization__c=:opp.Accountid];
              system.debug('count'+cntac1);
              if(cntac1 ==1)
              {
              td1=[select id,Organization__c from OneTimedonation__c where Organization__c=:opp.Accountid];
              td1.amount__c =opp.Amount;
              td1.Organization__c=opp.Accountid;
              td1.Campaign__c=opp.Campaignid;
              td1.Donation_Types__c=opp.Donation_type__c;
              update td1;
            
              }
           }
          
          
     }
 }

Ashish_SFDCAshish_SFDC
Hi Nesh, 

See the below link, 

https://developer.salesforce.com/forums/ForumsMain?id=906F000000094CBIAY

Regards,
Ashish