• ch ranjith
  • NEWBIE
  • 150 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 19
    Replies
Hi

May someone please help, I have an object called the rebate that has a lookup relationship to the account object. I want when a field is updated on the account object a field should also be updated on the rebate object but I am having a problem with this trigger.

trigger updateStartDate on Rebates__c (after insert, after update,before update){

Set<Id> accountIds = new Set<Id>();
   
    for(Rebates__c reb :trigger.new){
        accountIds.add(reb.Company__c);
}

    Map <ID,Account> updateAccounts = new Map<ID,Account>([Select id, Date_Installed__c from Account where id IN: AccountIds]);{
                                                 
for(Rebates__c reb :trigger.new){
accountIds.add(reb.Company__c);

       if(reb.From_Install_Date__c == true && updateAccounts.get(reb.Company__c).Date_Installed__c != null){

    if(reb.Product__c == '1t200000024Dtm')

{
                reb.Start_Date__c = reb.First_Day_of_the_Month__c;
   
    accountIds.update(reb);

}

else
{

   reb.Start_Date__c = reb.Install_Date__c;
    accountIds.update(reb);

       }
           try
              
           {
               update accountIds;
           }
           catch (system.DmlException e)
           {
               system.debug (e);
           }

   }
}
}
}
  • August 19, 2014
  • Like
  • 0
<apex:page standardController="account" recordSetVar="items">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!items}" var="vartodisplay">
<apex:column value="{!vartodisplay.name}"/>
<apex:column value="{!vartodisplay.industry}"/>
<apex:column value="{!vartodisplay.rating}"/>
<apex:column value="{!vartodisplay.website}"/>
<apex:column value="{!vartodisplay.phone}"/>
<apex:column value="{!vartodisplay.parentid}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
trigger realtime2 on Contact (before insert)
  {

     map<id,string> map1=new map<id,string>();
     list<contact> conlist=new list<contact>();
      list<contact> conlist1=new list<contact>();
if(trigger.isbefore)
    {
    for (Contact con:trigger.new)
     {
       map1.put(con.id,con.phone);
       conlist.add(con);
     }
      for(contact con:conlist)
      {        
       con.mobilephone=map1.get(con.id);
       conlist1.add(con);
     }
    
  update conlist1;
   }
  }
<apex:page showheader="false" sidebar="false">
<apex:iframe src="https://ap1.salesforce.com/01Z90000000MLn7" scrolling="true" height="1588px" width="100%" />
</apex:page>
trigger master on parent__c (after delete)
{
  set<id> set1=new set<id>();
  list<child__C> chdellist=new list<child__C>();
  for(parent__c p:trigger.old)
  {
   set1.add(p.id);
  }
  list<child__c> chlist=[select id,name,ref_parent__c from child__c where ref_parent__c in:set1];
  system.debug(chlist);
  for(parent__c p:trigger.old)
  {
  for(child__C c:chlist)
  {
  if(p.id==c.ref_parent__c)
     system.debug(p.name+'  '+c.name);
  {
   chdellist.add(c);
  }
  }
  }
  delete chdellist;
  }
trigger dubplicatewithoutgov on student__c (before insert)
{
   list<string> stlist=new list<string>();
   for(student__C st:trigger.old)
   {
    stlist.add(st.name);
   }
   for(student__C st:trigger.new)
   {
   for(integer i=0;i<stlist.size();i++)
   {
    if(st.name==stlist[i])
    {
     st.adderror('cant not add dupicate record');
     }
   }
}  
}
global class batchstudent implements Database.Batchable<sobject>
{
global final String Query;
global batchstudent(String q)
{
Query=q;
}

global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC,List<student__C> scope)
{
List <student__C> lstAccount = new list<student__C>();
for(Sobject s : scope)
{
student__C a = (student__C)s;
a.status__c='updated from batch apex';
system.debug(a);
}
update scope;
}

global void finish(Database.BatchableContext BC)
{
asyncapexjob a=[select id,status,numberoferrors,jobitemsprocessed,totaljobitems
                 from asyncapexjob where id=:bc.getjobid()];
            
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ranjith.imp@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed '+a.totaljobitems+'batches with'+a.numberoferrors+'failures');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

developer console:
id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from student__c'));
global class batchstudent implements Database.Batchable<sobject>
{
global final String Query;
global batchstudent(String q)
{
Query=q;
}

global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC,List<account> scope)
{
List <student__C> lstAccount = new list<student__C>();
for(Sobject s : scope)
{
student__C a = (student__C)s;
a.status__c='updated from batch apex';
system.debug(a);
lstAccount.add(a);
}
update lstAccount;
}

global void finish(Database.BatchableContext BC)
{
asyncapexjob a=[select id,status,numberoferrors,jobitemsprocessed,totaljobitems
                 from asyncapexjob where id=:bc.getjobid()];
              
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ranjith.imp@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed '+a.totaljobitems+'batches with'+a.numberoferrors+'failures');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Developer console :  id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from student__c'));
I have contact_update_fiels__c field in account when update or insert record in account the field value should be copied to all related contacts field update_from_account__c its not updating with below code 

trigger rt on Account (after insert,after update)
{
set<id> set1=new set<id>();
  list<contact> conlistnew=new list<contact>();
  for(account acc:trigger.new)
  {
    set1.add(acc.id);
  } 
  list<contact> conlist=[select id,name,accountid from contact where accountid in:set1];
 
  for(account tempacc:trigger.new)
  {
  for(contact tempcon:conlist)
  {
   if(tempacc.id==tempcon.id)
   {
   tempacc.contact_update_fiels__c=tempcon.update_from_account__c;
   conlistnew.add(tempcon);
   }
  }
  }
  update conlistnew;
}
trigger realtime1 on Contact (after insert)
{
set<id> set1=new set<id>();
list<account> aclist=new list<account>();
list<account> acnewlist=new list<account>();
list<Account> listac=new list<account>();
for(contact con:trigger.new)
   {
    set1.add(con.accountid);
   }
  acnewlist=[select id,name,billingaddress
                from account where id in:set1];
  for(contact con:trigger.new)
  {
    for(integer i=0;i<acnewlist.size();i++)
    {
     if(con.accountid==acnewlist[i].id)
     {
      con.account.sales_rep__c=con.department;
      aclist.add(con.account);
     }
   }
  }
update aclist;
}
<apex:page id="thepage">
<script>
function changefont(input,textid)
{
if(input.checked)
{
document.getelementbyid(textid).style.fontsize="100px";
}
else
{
document.getelementbyid(textid).style.fontweight="normal";
}
}
</script>
<apex:outputPanel layout="block">
<label for="checkbox">click</label>
<input id="checkbox" type="checkbox" onclick="changefont(this,'{!$component.thepanel}');"/>
</apex:outputpanel>
<apex:outputPanel id="thepanel" layout="block">change my font</apex:outputPanel>
</apex:page>
Hi

May someone please help, I have an object called the rebate that has a lookup relationship to the account object. I want when a field is updated on the account object a field should also be updated on the rebate object but I am having a problem with this trigger.

trigger updateStartDate on Rebates__c (after insert, after update,before update){

Set<Id> accountIds = new Set<Id>();
   
    for(Rebates__c reb :trigger.new){
        accountIds.add(reb.Company__c);
}

    Map <ID,Account> updateAccounts = new Map<ID,Account>([Select id, Date_Installed__c from Account where id IN: AccountIds]);{
                                                 
for(Rebates__c reb :trigger.new){
accountIds.add(reb.Company__c);

       if(reb.From_Install_Date__c == true && updateAccounts.get(reb.Company__c).Date_Installed__c != null){

    if(reb.Product__c == '1t200000024Dtm')

{
                reb.Start_Date__c = reb.First_Day_of_the_Month__c;
   
    accountIds.update(reb);

}

else
{

   reb.Start_Date__c = reb.Install_Date__c;
    accountIds.update(reb);

       }
           try
              
           {
               update accountIds;
           }
           catch (system.DmlException e)
           {
               system.debug (e);
           }

   }
}
}
}
  • August 19, 2014
  • Like
  • 0
<apex:page showheader="false" sidebar="false">
<apex:iframe src="https://ap1.salesforce.com/01Z90000000MLn7" scrolling="true" height="1588px" width="100%" />
</apex:page>
trigger master on parent__c (after delete)
{
  set<id> set1=new set<id>();
  list<child__C> chdellist=new list<child__C>();
  for(parent__c p:trigger.old)
  {
   set1.add(p.id);
  }
  list<child__c> chlist=[select id,name,ref_parent__c from child__c where ref_parent__c in:set1];
  system.debug(chlist);
  for(parent__c p:trigger.old)
  {
  for(child__C c:chlist)
  {
  if(p.id==c.ref_parent__c)
     system.debug(p.name+'  '+c.name);
  {
   chdellist.add(c);
  }
  }
  }
  delete chdellist;
  }
trigger dubplicatewithoutgov on student__c (before insert)
{
   list<string> stlist=new list<string>();
   for(student__C st:trigger.old)
   {
    stlist.add(st.name);
   }
   for(student__C st:trigger.new)
   {
   for(integer i=0;i<stlist.size();i++)
   {
    if(st.name==stlist[i])
    {
     st.adderror('cant not add dupicate record');
     }
   }
}  
}
global class batchstudent implements Database.Batchable<sobject>
{
global final String Query;
global batchstudent(String q)
{
Query=q;
}

global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC,List<account> scope)
{
List <student__C> lstAccount = new list<student__C>();
for(Sobject s : scope)
{
student__C a = (student__C)s;
a.status__c='updated from batch apex';
system.debug(a);
lstAccount.add(a);
}
update lstAccount;
}

global void finish(Database.BatchableContext BC)
{
asyncapexjob a=[select id,status,numberoferrors,jobitemsprocessed,totaljobitems
                 from asyncapexjob where id=:bc.getjobid()];
              
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'ranjith.imp@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed '+a.totaljobitems+'batches with'+a.numberoferrors+'failures');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Developer console :  id batchinstanceid = database.executeBatch(new deleteAccounts('select Id from student__c'));
rigger vig2 on join_object__c (after insert)
{
list<join_object__c> jcnewlist=new list<join_object__c>();
for(join_object__c jc:trigger.new)
{
  list<join_object__c> jclist=[select id,name,Account__r.name from join_object__c];
   jc.billing_adress__c=jc.Account__r.name;
   jcnewlist.add(jc);


error


Record is read-only: Trigger.vig2: line 7, column 1