• raysfdc1988
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 25
    Replies
Account-->Contact-->Attendance_Record

Here How to get account id in SOQL ...Pl help
 I tried like this but getting Error
select id from account where id in:(select id,AccountId from Contact where id in:(SELECT Contact__c FROM Attendance_Record__c))
Hi,
I want to write a schedur apex code which will automaticaly creates opportunity record.
In detail: I have 5 accounts records now i want create 5 opportunity records on perticular date of every month(11/18/2014).

Please help to write code for this.

thanks

 
Hi All,
I want to auto populate the contact address fileds(Area Name, City n all) by just entering ZipCode

Ex: If i enter Zipcode As :591317 then i want to auto populate following fields..
Mailing City    
Mailing State/Province    
Mailing Zip/Postal Code    
Mailing Country

Some Solution: I thought of creating a custom object to store this info and write a trigger to populate these values..

But Please suggest any other best ideas, like goodle api integration or free apps in apexachage or any other best solutions...
It shold be free ..
 
I need write schedulable apex for following prob..

I have contacts and Accounts standard object and one custom object attendance

Now for account-X there are two contact roles ->p and q-->

and Attendence is child object of contacts--

So for contact-->P -there are two attendence records wit status(data)-->1.payable and 2.Nonpayble


So for contact-->q there are two attendence records wit status(data)-->1.payable and 2.Nonpayble

Now I need write apex code to create a opportunity for this account X-
And I want add products to this opportunity

But I have already two products-Payable and Non payable with standard price

So for this opportunity i need to add this products accourding to the attendence records count of contact..

Ex:For X account opportunity---> there will be 4 produts(2-payable n 2-non payable)

Now I need apex code which will automaticaly create this opportunity and add products to it according to the contact attendence record.

and I want run this code once in a month..using scedule apex;

I think this very difficult , I am tring it from a weak...

Please help me to write this code..Even any reffence will also help me lot..
I have parent object called-->student
and Child object called -->attendence
and in parent object filed called-->Current_month_attendence_count 
and date field -->in child object
Now  every time Attendence record is created for perticular student then  Current_month_attendence_count increased by one
This can be achiveble by using a Rollup Summary field 
But I want Count the total no attendence record of perticular student only for Current Month..
We cant add a Rollup Filter like Date Equals THIS MONTH

So i need to update Current_month_attendence_count field when Date__C (field in child object attedance) is Equals to THIS MONTH

I think this can be achivieble by Trigger...
Pl suggest me wit best solutions...thanks


Now i want update field Current_month_attendence_count filed in parent object..
trigger expenses on Expense_Payouts__c (after insert,after update) 
{

list<string> departmentnames= new list<string>();
Decimal amount;
for(Expense_Payouts__c ep:trigger.new)
{

departmentnames.add(ep.department__c);

amount=ep.Amount__c;
               
}


list<Employee__c> employee = [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from
				 Employee__c where Department_Cost_Center__c IN:departmentnames];
system.debug('employeeeee.......'+employee);

decimal divAmount;
if(employee.size()!=null)
{
divAmount=amount/employee.size();
}

system.debug('test.......'+divAmount);
system.debug('test222222.......'+amount);

for(Employee__c e:employee )
{
if(e.Department_Cost_Center__c !='Others' && divAmount!=null)
{
e.Expense__c=((e.expense__C==null)?0:e.expense__C)+divAmount;
}

}
update employee;

}

//////////////////trigger 2///////////////////////////

trigger otherdepartment on Expense_Payouts__c (after insert, after update) {

list<employee__c> employ= [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from Employee__c];
decimal amount;

for(Expense_Payouts__c e:trigger.new)
{
if(e.department__c=='Others')
{
amount=e.Amount__c;
}

}
Decimal diamount;
if(employ.size()!=null && amount!=null)
{
diamount=amount/employ.size();
}

for(employee__c e:employ)
{
if(diamount!=null){
e.Company_Expenses__c=((e.Company_Expenses__c==null)?0:e.Company_Expenses__c)+diamount;
}
}
update employ;

}
I Wrote two triggers on a same object..Now i am trying to merge them but cant able to merge both functionality in one trigger..
Please help by ur thoughts...
Thanks..........
In contact object i have field called MyExpenses(hidden field). This field is populated from CompanyExpenses/no.of.contacts

There two contacts now, So for each contact myExpeness is $100...companyExpensesis $200(constant)

Now if i create another new  contact then Myexpenses filed should be 200/3..

So i need to write trigger to update this hidden field when i create any new contact..

Please help to write this trigger

Thanks
<apex:page controller="BookRoom" docType="html-5.0" >

<apex:form >

<apex:pageBlock  >
<apex:pageMessages id="msg"></apex:pageMessages>
////////This Is Picklist field/////////////////
<apex:outputtext ><b>Room No</b></apex:outputtext>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:inputField value="{!dx.Room__c}" rendered="true" required="true"></apex:inputField>
<br></br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<apex:outputText escape="true"><b>Date</b></apex:outputText>
<apex:inputfield value="{!dummyroom.Date__c}" required="true" rendered="true" /></br>
<apex:outputtext ><b>Client Name</b></apex:outputtext>
<apex:inputfield value="{!dx.Contact__c}" required="true"  label="Client Name" />
<br/>
<apex:commandButton value="Check Availability" action="{!CheckAvailability}" rendered="true"/>
<br/>
</apex:pageBlock>
/////////////////////////////////////////////////////////////////////////

<apex:pageBlock rendered="{!ShowpageBlockFlag}">
<apex:dataTable value="{!BookingSlots}" var="bs" id="thetable" columnClasses="col1,col2,col3,col4" width="60%">
<apex:column value="{!bs.event.subject}"/>
<apex:column value="{!bs.event.startdatetime}"/>
<apex:column value="{!bs.event.enddatetime}"/>
<apex:column ><apex:inputCheckbox value="{!bs.checkbox}" required="true"/></apex:column>
</apex:dataTable>
<br/><br/><br/>

<apex:commandButton value="Book the slot" action="{!Savedetails}" rerender="msg,ol"/>
<apex:commandButton value="Cancel" action="{!Cancel}" rerender="msg,pl"/>
</apex:pageBlock>

 

</apex:form>
</apex:page>
I want Rerender the first pageblock after item from picklist is changed...


Hi All,

Lemme expalne in detail..
There two  objects called Case(Master parent) and Logsheet(child)

Say there are 3 cases...
caseA
CaseB
CaseC

now i should create only one child record for each parent case record..
Means.. for caseA , only one logsheet1(record of Logsheet)
              
Means for one CASE ID i should not create multiple Logsheet records,...
Please hlep to to write a trigger to avoid this duplication....

                    
                  
<apex:page controller="wrapper_controller" showHeader="false">

   
        <apex:iframe src="https://cs6.salesforce.com/01ZN0000000I2b9"  title="graphj"/>
    <apex:form >
    
    <br/>
          <br/>
          <br/>
    <apex:commandButton value="To Sell"/>
    
        <apex:pageblock >
         <apex:pageblocktable value="{!inventorywrapperret}" var="p">
          <apex:column value="{!p.object_inventory.name}" />
          <apex:column value="{!p.object_inventory.Product__c}"/>
          <apex:column value="{!p.object_inventory.Expected_Date_of_Delivery__c}"/>
          <apex:column value="{!p.object_inventory.Discount_Percentage__c}"/>
          <apex:column value="{!p.object_inventory.Quantity__c}"/>
          
          </apex:pageblocktable>
          
          <br/>
          <br/>
          <br/>
  
          
          <apex:commandButton value="To Avoid"/>

       //////different table of same oject//////////////
  <apex:pageblocktable value="{!inventorywrapperret}" var="p">
                   <apex:column value="{!p.object_inventory.name}" />
          <apex:column value="{!p.object_inventory.Product__c}"/>
          <apex:column value="{!p.object_inventory.Expected_time_Delivery_Month__c}"/>
          
          <apex:column value="{!p.object_inventory.Discount_Percentage__c}"/>
          <apex:column value="{!p.object_inventory.Quantity__c}"/>
          
          </apex:pageblocktable>


                  <apex:commandButton value="Purchase Orders"/>
          <apex:pageblocktable value="{!purchasewrapperret}" var="con">
          <apex:column value="{!con.object_purchase.name}" />
          <apex:column value="{!con.object_purchase.Product__c}"/>
           <apex:column value="{!con.object_purchase.Buyerp__c}"/>
            <apex:column value="{!con.object_purchase.Quantity__c}"/>
            <apex:column value="{!con.object_purchase.Order_Amount__c}"/>
            <apex:column value="{!con.object_purchase.Discount_Amount__c}"/>
            <apex:column value="{!con.object_purchase.Received_Amount__c}"/>
            <apex:column value="{!con.object_purchase.Open_Amount__c}"/>
            
             <apex:column value="{!con.object_purchase.Order_Status__c}"/>
          </apex:pageblocktable>
        
          </apex:pageblock>
          
           
        
    </apex:form>
</apex:page>
public with sharing class wrapper_controller {

public list<wrapperclass> wrapperelement_for_inventory{get;set;}
public list<wrapperclass> wrapperelement_for_purchase{get;set;}
public list<wrapperclass> wrapperelement_for_avoid{get;set;}

//list<Inventory_Management__c> object1 = [select id,name,Product__c,Expected_Date_of_Delivery__c,Quantity__c,Discount_Percentage__c,Expected_time_Delivery_Month__c from Inventory_Management__c  limit 10];

list<Purchase_Order__c> object2 = [select id,name ,Buyerp__c,Discount_Amount__c,Open_Amount__c,Order_Amount__c,Order_Status__c,
            Price_Book__c,Product__c,Quantity__c,Received_Amount__c,Supplier__c,Warehouse__c from Purchase_Order__c limit 10];




public list<wrapperclass> getinventorywrapperret(){
    
    wrapperelement_for_inventory= new list<wrapperclass>();
   
    for(Inventory_Management__c obj1: [select id,name,Product__c,Expected_Date_of_Delivery__c,Quantity__c,Discount_Percentage__c,Expected_time_Delivery_Month__c from Inventory_Management__c where Expected_Date_of_Delivery__c<6  limit 10])
    {
    if(obj1.Expected_Date_of_Delivery__c<10){
    
    wrapperelement_for_inventory.add(new wrapperclass(obj1));
    }
    
    return wrapperelement_for_inventory;
    }

//////////Here i want create a another table wrapperelement_for_avoid which holds the values //////////////   if(obj1.Expected_Date_of_Delivery__c>10)




public list<wrapperclass> getpurchasewrapperret(){
    wrapperelement_for_purchase= new list<wrapperclass>();
    for(Purchase_Order__c obj2: object2){
    wrapperelement_for_purchase.add(new wrapperclass(obj2));
    }
    return wrapperelement_for_purchase;
    }


public class wrapperclass{
    public Inventory_Management__c object_inventory{get;set;}
    public Purchase_Order__c object_purchase{get;set;}

    public wrapperclass(Inventory_Management__c obj1){
    this.object_inventory = (obj1);
    this.object_inventory.Product__c =(obj1.Product__c);
    this.object_inventory.Expected_Date_of_Delivery__c= (obj1.Expected_Date_of_Delivery__c);
    this.object_inventory.Expected_time_Delivery_Month__c =(obj1.Expected_time_Delivery_Month__c );
    this.object_inventory.Quantity__c=(obj1.Quantity__c);
    this.object_inventory.Discount_Percentage__c=(obj1.Discount_Percentage__c);
    }

    public wrapperclass(Purchase_Order__c obj2){
        this.object_purchase = (obj2);
        this.object_purchase.Product__c = (obj2.Product__c);
        this.object_purchase.Buyerp__c= (obj2.Buyerp__c);
        this.object_purchase.Quantity__c= (obj2.Quantity__c);
        this.object_purchase.Order_Amount__c= (obj2.Order_Amount__c);
        this.object_purchase.Discount_Amount__c= (obj2.Discount_Amount__c);
        this.object_purchase.Received_Amount__c= (obj2.Received_Amount__c);
        //this.object_purchase.Open_Amount__c= (obj2.Open_Amount__c);

        }
    }
}

Here i want ceate another table of object Inventory_Management__c with different conditon....How to call that in visualforce page...Pl help
trigger Attachmentant on Student_Profile__c (before insert, after insert,after update) {

if(trigger.isupdate)
{

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
 
if(stoprecurssion.runonce()){

// when courcse_program name is updated, Create a new record of Referral Points///////

if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
//////// Get the id and emailid of Referral from student_Profile //////////
Student_Profile__c referedpersonid=[select id ,Student_Profile__c.email__c from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];

rp.Member__c=referedpersonid.id;
rp.Refered_Person__c =s.id;
rp.Referred_by_Email__c=s.UserName__c;

referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}          
}

Hi,

Here I need to create a child record when only s.Course_Program__c  is changed but now its creating a child record every time when other fields are updated.
I need to creat a new child record only when s.Course_Program__c is updated... Pl help me to sortout this..
Thanks
trigger AttachmentandReferralpoints on Student_Profile__c (before insert, after insert,after update) {


if(trigger.isupdate){

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.points__c=50;
Student_Profile__c referedpersonid=[select id from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];
rp.Refered_Person__c =referedpersonid.id;
referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}
}

hi guys....!!
I think its becouse of recusrsive trigger, but unable solve..
Please help me to bulkify this trigger or solve the prob..
if(trigger.isupdate){
list<Referral_Points__c> referral=new list<Referral_Points__c>();
list<Student_Profile__c> studentlist= new list<Student_Profile__c >();
for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.Refered_Person__c= [select id from Student_Profile__c where Student_Profile__c.UserName__c=:Student_Profile__c.Referred_By_email__c];//////line 143
referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}

Please help
sceneria is as follow:
In cantact i have field called referred by email(contact emailid of other ).
I have created child object of contact as referral points.

Now i have create child record once referred by email field is updated.
but chalenge is i am getting emailId of referred contact, so i neet to get the contact name of that emailId  and then i should give points to him(reating childrecord).
<apex:page standardController="Deliverables__c" recordSetVar="Deliverables" tabstyle="Deliverables__c" sidebar="false">
  <apex:pageBlock >
    <apex:form >
     <apex:dataTable value="{!Deliverables}" var="o" id="scoringTable" cellpadding="4" width="100%">
                        <apex:column >
                        <apex:facet name="header">Owner Id</apex:facet>
                           <apex:outputLink value="apex/delverydetails/!{o.id}">{!o.Name}</apex:outputLink>
                        </apex:column>
                        </apex:dataTable>
    
       
    </apex:form>
  </apex:pageBlock>
</apex:page>

Here i want display deliverabledetailpage ofter clicking on list of records.
devliverable is master object of deliverabledetails object....Pl help me write a controller
Hi getting above error:Compile Error: Expression cannot be assigned at line -1 column -1

I am understanding what is this error and how debug it??
Is there any need od change in code,,Please help me

trigger AttachmentandReferralpoints on Student_Profile__c (before insert, after insert,after update) {
if(trigger.isupdate)
{
  list<string> preferredcoursenames=new list<string>();
      list<string> preferredtimeslot=new list<string>();

     for(student_profile__c studentprofile:trigger.new)
     {
       preferredcoursenames.add(studentprofile.Prefered_Course__c);
        preferredtimeslot.add(studentprofile.Preferred_Course_Start_Date__c);
      }
      list<string> timeslots=new list<string>();
       for(string splitvals:preferredtimeslot)
      {
       list<string> s=splitvals.split(',');
       timeslots.add(s[0]);
     
       }
       map<string,id> courseNameIdMap=new map<string,id>();
   for(Course_Program__c programs:[select id ,name, Type_of_Program__c,Month__c from
                                     Course_Program__c where Type_of_Program__c in :preferredcoursenames and month__c=:timeslots])
    {
       courseNameIdMap.put(programs.Type_of_Program__c ,programs.id);
  
    }
    list<Course_Program__c> CourseProgram = new list<Course_Program__c>();
  
     for(student_profile__c updatingstudentprofile:trigger.new)
     {
       ///preferredcoursenames.add(studentprofile.Prefered_Course__c);
       if(courseNameIdMap.containskey(updatingstudentprofile.Prefered_Course__c))
       {
       updatingstudentprofile.Course_Program__c=courseNameIdMap.get(updatingstudentprofile.Prefered_Course__c);
       }
       else
        {
         Course_Program__c newprogram =new Course_Program__c();
         Course_Program__c.name=updatingstudentprofile.Course_Name__c;
         Course_Program__c.Type_of_Program__c=updatingstudentprofile.Prefered_Course__c;
         Course_Program__c.month__c=updatingstudentprofile.Preferred_Course_Start_Date__c;
       
         CourseProgram.add(newprogram);
        }
        }
     if(!CourseProgram.isempty())
     insert CourseProgram ;   
}
}


trigger pudatename on BuyAirtime__c (before insert, before update) {
for(BuyAirtime__c  ba: trigger.new)
{
user us =[select id,name from user where id=:ba.Mentor__c];

ba.Name = us.name +' '+ ((ba.Buy_Airtime_Date__c).day()+'/'+(ba.Buy_Airtime_Date__c).month()+'/'+(ba.Buy_Airtime_Date__c).year());
}
}

As trigger is working fine but to bulkify this trigger i want to write the soql query  out of for loop..pl help me
want to update a autonumber field from a another custom formula field of sam object..
here name is autonumer field and Program_Name__c is formula field.. when i create a record i need to update name field by Program_Name__c field...
pl help me

trigger updatename on Course_Program__c (after insert, after update) {

for(Course_Program__c cp: trigger.new)
{
if(cp.Program_Name__c != null)
{
cp.name=cp.Program_Name__c;

}
}
}

getting error:Field is not writeable: Course_Program__c.Name at line 7 column 1
trigger createcontact on student_profile__c (after insert) { 
    List<contact> listcontact = new List<contact>();
  for (Student_Profile__c oStudent : trigger.new) {      
contact oContact = new contact();
   oContact.AccountId = oStudent.Current_Institution__c;
   oContact.firstName = oStudent.First_Name__c;
    oContact.LastName =oStudent.Last_Name__c;
    oContact.Attendance_Points__c = oStudent.Attendance_Points__c;
    oContact.Birthday__c = oStudent.Birthday__c;
    oContact.City__c = oStudent.City__c;
    oContact.Country__c = oStudent.Country__c;
    oContact.Course_Program__c = oStudent.Course_Program__c;
    oContact.Course_Name__c = oStudent.Course_Name__c;
    oContact.Course_No__c = oStudent.Course_No__c;
 
    oContact.imageURL__c = oStudent.imageURL__c;
    oContact.Institution_Name__c = oStudent.Institution_Name__c;
  
   oContact.Student_ID__c=ostudent.Student_ID__c;
    oContact.Mentor_Points__c = oStudent.Mentor_Points__c;
    oContact.Mentor_Points_2__c = oStudent.Mentor_Points_2__c;



        listcontact.add(oContact);
    }

    if (listcontact.isEmpty() == false) {
        Database.insert(listcontact);
    }

here student.Student_ID__c is unique  custom ffield,  Now i can insert a record in a contact but I cant update it.. Means if i make any changes in custom object record then it not poulating in contact object record,,,

Please help me to update a contact records on change a change of custom record. ,,
//class...//
public with sharing class Campaignmembermassupdate {


public list<campaignmember> allCampaignMembers{get;set;}
public list<listWrapper> allDisplayedCampainmembers{get;set;}
public list<listWrapper> UpdatingList{get;set;} 
public list<campaignmember> updatingCampaignMember{get;set;}
public boolean firsttable{get;set;}
public boolean secondtable{get;set;}
public string datatable{get;set;}
public campaign filterdate{get;set;}
public Id CampaignId{get;set;}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  public boolean selectallrows{get;set;}
public string Status{get;set;}
public string modeofcorrespondance{get;set;}
public string Attendance{get;set;}
public string RSVP{get;set;}
public string Thanked{get;set;}
  public string FoodPreference{get;set;}
public string  TravelArrangements{get;set;}
public string  SpecialRequirements{get;set;}
public boolean CreateOpportunity{get;set;}

//////////////////////////////filtering fields to get////////////////////////////////////////////////////////
public string filter1{get;set;}
public string filter2{get;set;}
public string filter3{get;set;}
public string filter4{get;set;}
public string filter5{get;set;}
public string filter6{get;set;}
public string filter7{get;set;}
public string filter8{get;set;}
public string filter9{get;set;}
public string filter10{get;set;}
public string filter11{get;set;}
public string filter12{get;set;}
public string filter13{get;set;}
public string filter14{get;set;}
public string filter15{get;set;}

public pagereference go()
    {
    firsttable=true;
    secondtable=false;
   
    updatinglist=new list<listwrapper>();
     updatinglist.clear();
string query='select id, status,contact.name,Mode_of_Correspondence__c,preferred_mode_of_contact__c,Create_Opportunity__c,RSVP__c,Attendance__c,Thanked__c,food_Preference__C,Travel_Arrangements__C,Special_Requirements__c from campaignmember where campaignid='+'\''+CampaignId+'\'';  

    if(filter1!=''&&filter3!=''&&filter6==''&&filter9==''&&filter12==''&&filter15=='')
     {

             string temp=filter2.replace('1',filter1);
              string temp2=temp.replace('2',filter3);
               system.debug('this is to test test classes  '+temp2);
             system.debug('temp1 '+temp+' temp2 '+temp2);
             for(campaignmember sortedlist:database.query(query+temp2))
                  {
                  listwrapper slist=new listwrapper();
                    slist.CMember=sortedlist;
                    slist.selectitem=false;
                   updatinglist.add(slist);         
                  }
           
    }
    if(filter1!=''&&filter3!=''&&filter4!=''&&filter6!=''&&filter9==''&&filter12==''&&filter15=='')
    {
                string temp=filter2.replace('1',filter1);
                string temp2=temp.replace('2',filter3);
                string temp3=filter5.replace('1',filter4);
                string temp4=temp3.replace('2',filter6);
             for(campaignmember sortedlist:database.query(query+temp2+temp4))
                  {
                  listwrapper slist=new listwrapper();
                    slist.CMember=sortedlist;
                    slist.selectitem=false;
                   updatinglist.add(slist);         
                  }
    }
     if(filter1!=''&&filter3!=''&&filter4!=''&&filter6!=''&&filter7!=''&&filter9!=''&&filter12==''&&filter15=='')
    {
                 string temp=filter2.replace('1',filter1);
                string temp2=temp.replace('2',filter3);
                string temp3=filter5.replace('1',filter4);
                string temp4=temp3.replace('2',filter6);
                string temp5=filter8.replace('1',filter7);
                string temp6=temp5.replace('2',filter9);
   
    system.debug('for 3');
     for(campaignmember sortedlist:database.query(query+temp2+temp4+temp6))
                  {
                  listwrapper slist=new listwrapper();
                    slist.CMember=sortedlist;
                    slist.selectitem=false;
                   updatinglist.add(slist);         
                  }
     
    }
      if(filter1!=''&&filter3!=''&&filter4!=''&&filter6!=''&&filter7!=''&&filter9!=''&&filter12!=''&&filter15=='')
    {
             string temp=filter2.replace('1',filter1);
                string temp2=temp.replace('2',filter3);
                string temp3=filter5.replace('1',filter4);
                string temp4=temp3.replace('2',filter6);
                string temp5=filter8.replace('1',filter7);
                string temp6=temp5.replace('2',filter9);
                string temp7=filter11.replace('1',filter10);
                string temp8=temp7.replace('2',filter12);
   
    system.debug('for 4');
     for(campaignmember sortedlist:database.query(query+temp2+temp4+temp6+temp8))
                  {
                  listwrapper slist=new listwrapper();
                    slist.CMember=sortedlist;
                    slist.selectitem=false;
                   updatinglist.add(slist);         
                  }
     
    }
      if(filter1!=''&&filter3!=''&&filter4!=''&&filter6!=''&&filter7!=''&&filter9!=''&&filter12!=''&&filter15!='')
    {
        string temp=filter2.replace('1',filter1);
                string temp2=temp.replace('2',filter3);
                string temp3=filter5.replace('1',filter4);
                string temp4=temp3.replace('2',filter6);
                string temp5=filter8.replace('1',filter7);
                string temp6=temp5.replace('2',filter9);
                string temp7=filter11.replace('1',filter10);
                string temp8=temp7.replace('2',filter12);
                 string temp9=filter14.replace('1',filter13);
                string temp10=temp9.replace('2',filter15);

   
    system.debug('for 5');
            for(campaignmember sortedlist:database.query(query+temp2+temp4+temp6+temp8+temp10))
                  {
                  listwrapper slist=new listwrapper();
                    slist.CMember=sortedlist;
                    slist.selectitem=false;
                   updatinglist.add(slist);         
                  }
     
    }
    return null;
   
    }
    /////////////////////////////////////////////////////////////////////////////////////
    public pagereference allcampaignmembers()
    {
     firsttable=true;
        updatinglist=new list<listwrapper>();
     for(listwrapper listwrapper:allDisplayedCampainmembers)
     {
       updatinglist.add(listwrapper);
     }
      return null;
    }
    /////////////////////////////////////////////////////////////////////////////////////////
    public pagereference selectallitems()
    {
    system.debug('action support');
        
     for(listwrapper lw:updatinglist)
     {
     if(selectallrows)
     {
       lw.selectitem=true;
     }
      else
      {
       lw.selectitem=false;
       }
     
     }
    
      return null;
    }
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   public pagereference Updateall()
    {
    system.debug(status+attendance+thanked);
      list<campaignmember> Updateitnow=new list<campaignmember>();
    firsttable=true;
    secondtable=false;
    updatingCampaignMember=new list<campaignmember>();
   
    for(listwrapper lw:updatinglist)
    {
    if(lw.selectitem)
    updatingCampaignMember.add(lw.cmember);
    }
   system.debug('updating lists   '+ updatingcampaignmember.size());
    for(campaignmember cM:updatingCampaignMember)
    {
      if(status!='none')
      {
      system.debug('status check  ');
      cm.status=status;
      }
      if(modeofcorrespondance!='none')
      {
      system.debug('moc check  ');
      cm.Mode_of_Correspondence__c=modeofcorrespondance;
      }
      if(attendance!='none')
      {
      system.debug('att check  ');
      cm.Attendance__c=attendance;
      }
      if(thanked!='none')
      {
      cm.Thanked__c=thanked;
      }
      if(RSVP!='none')
      {
      cm.RSVP__C=rsvp;
      }
       if(Foodpreference!=''||Foodpreference!=' ')
      {
      cm.Food_Preference__C=FoodPreference;
      }
      if(TravelArrangements!=''||TravelArrangements!=' ')
      {
      cm.Travel_Arrangements__c=TravelArrangements;
      }
      if(SpecialRequirements!=''||SpecialRequirements!=' ')
      {
      cm.Special_Requirements__c=SpecialRequirements;
      }
       Updateitnow.add(cm);
    }
   if(Updateitnow.size()>0)
   {
   system.debug('update call check');
   update updateitnow;
   }
  Status=null;
modeofcorrespondance=null;
Attendance=null;
RSVP=null;
Thanked=null;
  FoodPreference=null;
TravelArrangements=null;
  SpecialRequirements=null;
    return null;
    }
      

         //////////////////////////wrapper class for display campaign members//////////////////////////////////////////   
     public class listwrapper
     {
     public campaignmember CMember{get;set;}
     public Boolean selectitem{get;set;}
    
     }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public Campaignmembermassupdate(ApexPages.StandardController controller) {

    allDisplayedCampainmembers=new list<listWrapper>();
   
     campaignid=controller.getrecord().id;
  for(campaignmember allCampaignMembers:[select id, status,contact.name,Mode_of_Correspondence__c,Create_Opportunity__c ,preferred_mode_of_contact__c,RSVP__c,Attendance__c,Food_Preference__c ,travel_Arrangements__c,Special_Requirements__c,
                                         Thanked__c from campaignmember where campaignid=:controller.getrecord().id])
                  {
                  listwrapper w=new listwrapper();
                  w.CMember=allcampaignmembers;
                 
                  allDisplayedCampainmembers.add(w);
                 
                  }

    }
}

///test class is//
@istest(seealldata=true)
public class testforMassUpdate
{
    static testmethod void massupdatetest()
    {
    account a=new account();
    a.name='test account';
    insert a;
    contact con=new contact();
    con.lastname='test name';
    con.account=a;
    insert con;
   
     campaign c=new campaign();
     c.name='testcampaign';
     insert c;
    
     campaignmember cm=new campaignmember();
     cm.status='sent';
     cm.Attendance__c='attended';
     cm.Mode_of_Correspondence__c='phone';
     cm.campaignid=c.id;
     cm.contactid=con.id;
     insert cm;
    
       ApexPages.StandardController sc = new ApexPages.standardController(c);
       Campaignmembermassupdate cmu=new Campaignmembermassupdate(sc);
     system.assertequals(cmu.campaignid,c.id);
        cmu.filter1='status';
        cmu.filter2=' and 1=2';
        cmu.filter3='sent';
        cmu.filter4='';
        cmu.filter6='';
        cmu.filter7='';
        cmu.filter9='';
        cmu.go();
        system.assertequals(cmu.updatinglist.size(),0);
      
       system.assertequals(cmu.campaignid,c.id);
      cmu.allcampaignmembers();
      system.assertequals(cmu.updatinglist.size(),1);
      cmu.selectallrows=true;
      cmu.selectallitems();
    
      cmu.Status='Responded';
       cmu.Updateall();
       campaignmember cmb=[select id ,status from campaignmember where id=:cm.id];
       system.assertequals(cmb.status,'Responded');
      
     
    }
trigger expenses on Expense_Payouts__c (after insert,after update) 
{

list<string> departmentnames= new list<string>();
Decimal amount;
for(Expense_Payouts__c ep:trigger.new)
{

departmentnames.add(ep.department__c);

amount=ep.Amount__c;
               
}


list<Employee__c> employee = [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from
				 Employee__c where Department_Cost_Center__c IN:departmentnames];
system.debug('employeeeee.......'+employee);

decimal divAmount;
if(employee.size()!=null)
{
divAmount=amount/employee.size();
}

system.debug('test.......'+divAmount);
system.debug('test222222.......'+amount);

for(Employee__c e:employee )
{
if(e.Department_Cost_Center__c !='Others' && divAmount!=null)
{
e.Expense__c=((e.expense__C==null)?0:e.expense__C)+divAmount;
}

}
update employee;

}

//////////////////trigger 2///////////////////////////

trigger otherdepartment on Expense_Payouts__c (after insert, after update) {

list<employee__c> employ= [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from Employee__c];
decimal amount;

for(Expense_Payouts__c e:trigger.new)
{
if(e.department__c=='Others')
{
amount=e.Amount__c;
}

}
Decimal diamount;
if(employ.size()!=null && amount!=null)
{
diamount=amount/employ.size();
}

for(employee__c e:employ)
{
if(diamount!=null){
e.Company_Expenses__c=((e.Company_Expenses__c==null)?0:e.Company_Expenses__c)+diamount;
}
}
update employ;

}
I Wrote two triggers on a same object..Now i am trying to merge them but cant able to merge both functionality in one trigger..
Please help by ur thoughts...
Thanks..........
Hi,
I want to write a schedur apex code which will automaticaly creates opportunity record.
In detail: I have 5 accounts records now i want create 5 opportunity records on perticular date of every month(11/18/2014).

Please help to write code for this.

thanks

 
I have parent object called-->student
and Child object called -->attendence
and in parent object filed called-->Current_month_attendence_count 
and date field -->in child object
Now  every time Attendence record is created for perticular student then  Current_month_attendence_count increased by one
This can be achiveble by using a Rollup Summary field 
But I want Count the total no attendence record of perticular student only for Current Month..
We cant add a Rollup Filter like Date Equals THIS MONTH

So i need to update Current_month_attendence_count field when Date__C (field in child object attedance) is Equals to THIS MONTH

I think this can be achivieble by Trigger...
Pl suggest me wit best solutions...thanks


Now i want update field Current_month_attendence_count filed in parent object..
trigger expenses on Expense_Payouts__c (after insert,after update) 
{

list<string> departmentnames= new list<string>();
Decimal amount;
for(Expense_Payouts__c ep:trigger.new)
{

departmentnames.add(ep.department__c);

amount=ep.Amount__c;
               
}


list<Employee__c> employee = [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from
				 Employee__c where Department_Cost_Center__c IN:departmentnames];
system.debug('employeeeee.......'+employee);

decimal divAmount;
if(employee.size()!=null)
{
divAmount=amount/employee.size();
}

system.debug('test.......'+divAmount);
system.debug('test222222.......'+amount);

for(Employee__c e:employee )
{
if(e.Department_Cost_Center__c !='Others' && divAmount!=null)
{
e.Expense__c=((e.expense__C==null)?0:e.expense__C)+divAmount;
}

}
update employee;

}

//////////////////trigger 2///////////////////////////

trigger otherdepartment on Expense_Payouts__c (after insert, after update) {

list<employee__c> employ= [select id,name,Expense__c,Company_Expenses__c,Department_Cost_Center__c from Employee__c];
decimal amount;

for(Expense_Payouts__c e:trigger.new)
{
if(e.department__c=='Others')
{
amount=e.Amount__c;
}

}
Decimal diamount;
if(employ.size()!=null && amount!=null)
{
diamount=amount/employ.size();
}

for(employee__c e:employ)
{
if(diamount!=null){
e.Company_Expenses__c=((e.Company_Expenses__c==null)?0:e.Company_Expenses__c)+diamount;
}
}
update employ;

}
I Wrote two triggers on a same object..Now i am trying to merge them but cant able to merge both functionality in one trigger..
Please help by ur thoughts...
Thanks..........
In contact object i have field called MyExpenses(hidden field). This field is populated from CompanyExpenses/no.of.contacts

There two contacts now, So for each contact myExpeness is $100...companyExpensesis $200(constant)

Now if i create another new  contact then Myexpenses filed should be 200/3..

So i need to write trigger to update this hidden field when i create any new contact..

Please help to write this trigger

Thanks
Hi All,

Lemme expalne in detail..
There two  objects called Case(Master parent) and Logsheet(child)

Say there are 3 cases...
caseA
CaseB
CaseC

now i should create only one child record for each parent case record..
Means.. for caseA , only one logsheet1(record of Logsheet)
              
Means for one CASE ID i should not create multiple Logsheet records,...
Please hlep to to write a trigger to avoid this duplication....

                    
                  
trigger Attachmentant on Student_Profile__c (before insert, after insert,after update) {

if(trigger.isupdate)
{

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
 
if(stoprecurssion.runonce()){

// when courcse_program name is updated, Create a new record of Referral Points///////

if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
//////// Get the id and emailid of Referral from student_Profile //////////
Student_Profile__c referedpersonid=[select id ,Student_Profile__c.email__c from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];

rp.Member__c=referedpersonid.id;
rp.Refered_Person__c =s.id;
rp.Referred_by_Email__c=s.UserName__c;

referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}          
}

Hi,

Here I need to create a child record when only s.Course_Program__c  is changed but now its creating a child record every time when other fields are updated.
I need to creat a new child record only when s.Course_Program__c is updated... Pl help me to sortout this..
Thanks
trigger AttachmentandReferralpoints on Student_Profile__c (before insert, after insert,after update) {


if(trigger.isupdate){

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.points__c=50;
Student_Profile__c referedpersonid=[select id from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];
rp.Refered_Person__c =referedpersonid.id;
referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}
}

hi guys....!!
I think its becouse of recusrsive trigger, but unable solve..
Please help me to bulkify this trigger or solve the prob..
if(trigger.isupdate){
list<Referral_Points__c> referral=new list<Referral_Points__c>();
list<Student_Profile__c> studentlist= new list<Student_Profile__c >();
for(Student_Profile__c s: trigger.new){
if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
rp.Member__c=s.id;
rp.Refered_Person__c= [select id from Student_Profile__c where Student_Profile__c.UserName__c=:Student_Profile__c.Referred_By_email__c];//////line 143
referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}

Please help
<apex:page standardController="Deliverables__c" recordSetVar="Deliverables" tabstyle="Deliverables__c" sidebar="false">
  <apex:pageBlock >
    <apex:form >
     <apex:dataTable value="{!Deliverables}" var="o" id="scoringTable" cellpadding="4" width="100%">
                        <apex:column >
                        <apex:facet name="header">Owner Id</apex:facet>
                           <apex:outputLink value="apex/delverydetails/!{o.id}">{!o.Name}</apex:outputLink>
                        </apex:column>
                        </apex:dataTable>
    
       
    </apex:form>
  </apex:pageBlock>
</apex:page>

Here i want display deliverabledetailpage ofter clicking on list of records.
devliverable is master object of deliverabledetails object....Pl help me write a controller


trigger pudatename on BuyAirtime__c (before insert, before update) {
for(BuyAirtime__c  ba: trigger.new)
{
user us =[select id,name from user where id=:ba.Mentor__c];

ba.Name = us.name +' '+ ((ba.Buy_Airtime_Date__c).day()+'/'+(ba.Buy_Airtime_Date__c).month()+'/'+(ba.Buy_Airtime_Date__c).year());
}
}

As trigger is working fine but to bulkify this trigger i want to write the soql query  out of for loop..pl help me
want to update a autonumber field from a another custom formula field of sam object..
here name is autonumer field and Program_Name__c is formula field.. when i create a record i need to update name field by Program_Name__c field...
pl help me

trigger updatename on Course_Program__c (after insert, after update) {

for(Course_Program__c cp: trigger.new)
{
if(cp.Program_Name__c != null)
{
cp.name=cp.Program_Name__c;

}
}
}

getting error:Field is not writeable: Course_Program__c.Name at line 7 column 1