• james1986
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 13
    Replies

hi,

I have a apex class that runs every night to update aggregate fields on Accounts. It works fine, but I added a new peice of functionality that is not working.

 

I've added a field called "grandmother sponsor" (I am working with an NGO doing work in southern africa) to accounts. Everynight when my class runs, I want to pull up all accounts that have a child object called monthly_gift__c with a child object called Monthly_Gift_Allocations__c that is linked to a program account called grandmother support.

 

I know my query works. I know I have active grandmother sponsors. But when I run my test classes the bold/italic/underlined peice of code (below) never runs.

 

 

Would anyone mind having a look over the code below and tell me what I need to do get all accounts with a child object that has a grandchild object? Snippets of my code are below.

 

 

 

 

 

List<Monthly_Gift_Allocations__c> gsponsors = new List<Monthly_Gift_Allocations__c>();
for (Monthly_Gift_Allocations__c gsponsorquery: [SELECT Monthly_Gift__r.Account__r.id from Monthly_Gift_Allocations__c where (Monthly_Gift__r.end_date__c = NULL OR Monthly_Gift__r.end_date__c > :system.today()) and (amount__c >= 20 and stream__r.name = '2 - Grandmother Support')])       
        {
            id myid = (id)gsponsorquery.get('id');
            isactive_grannysponsor.put(myid, TRUE);
          
        }

 

......

 

      List<Account> accountstoupdate = new List<Account>();
        for (Account a: [SELECT Total_transactions__c, granny_sponsor__c, last_nonmonthly__c, First_Transaction__c, Last_Transaction__c, Number_of_transactions__c, isactive_monthly__c, ID FROM Account])
        {

      if (isactive_grannysponsor.get(a.ID) != NULL)
            {
                a.granny_sponsor__c = TRUE;
            }
            else if (isactive_grannysponsor.get(a.ID) ==NULL)
            {
                a.granny_sponsor__c = FALSE;
            }

}

hi,

I have a bunch of objects and code in my sandbox. I've written test methods have have 100% coverage on my code, and everything seems fine.

 

There's just one problem. When I goto deploy, I run into a bunch of errors. Most of the errors have to do with dependancies: not being able to deploy a child object because there is no master object for it to look for, not being able to deploy master objects because there are no child objects to base roll-up summaries on, not being able to deploy formulas because the fields they reference are not installed yet.

 

Any idea how I should proceed? Having to re-create all my objects in the production environemnt to get around these dependancies seems like a pretty aweful prospect.

 

thanks

James

hi, I'm hoping someone can point me in the right direction.
I have a visual force page that passes 2 parameters to an APEX class. It seems to work fine, but before I deploy it need to develop a test class.
I am stuck at 31% code coverage. It looks like my parameters are NOT being passed and so I can't get past line 24 (below). I tried assigning values to "firstselect" and "lastselect" (see lines 95 and 96) but I get the following error:
Error: Compile Error: Method does not exist or incorrect signature: [updatepledges].firstselect(String) at line 95 column 8
I'm hoping someone could have a look at my test class and let me know how I should go about passing these parameters. Thanks in advance
public class updatepledges {
 
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    private Deposit__c depbatch {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}
    public String firstselect {get; set;}
    public String lastselect {get; set;}
    public String batch_paytype {get; set;}
       
    public updatepledges(ApexPages.StandardController controller)
    {
        //initialize the stanrdard controller
        this.controller = controller;

        // load the current record
        depbatch = (Deposit__c)controller.getRecord();
    }
    public PageReference runpledges() 
    {
// THE NEXT LINE IS #24. I CANT GET ANY COVERAGE BEYOND THIS POINT, I THINK BECAUSE IM NOT PROPERLY PASSING THE PARAMETER
        integer firstdate = integer.valueof(firstselect);
        integer lastdate = integer.valueof(lastselect); 
        depbatch = [select PaymentType__c from Deposit__c where Id = :depbatch.Id];
        batch_paytype = String.Valueof(depbatch.get(Deposit__c.PaymentType__c));
        List<Donation__c> donations = new List<Donation__c>();
        Map<ID,Donation__c> mgDonationMap = new Map<ID,Donation__c>();
        for (Monthly_Gift__c mg: [SELECT Id, Account__c, Contact__c, PaymentType__c FROM Monthly_Gift__c WHERE PaymentType__c = :batch_paytype AND Day_of_Month__c >= :firstdate AND Day_of_Month__c <= :lastdate])
        {
            //Create a donation and populate it. then add it to the list
            Donation__c d = new Donation__c();
            d.Account__c = mg.Account__c;
            d.Contact__c = mg.Contact__c;
            d.Payment_Type__c = mg.PaymentType__c;
            d.Deposit_Batch__c = depbatch.Id;
            donations.add(d);
            //add the id of the monthly donation and the new dontation to a map to be used for the allocations
            mgDonationMap.put(mg.id,d);
        }
        insert donations;

        
        
        List<Allocation__c> allocations = new List<Allocation__c>();
        for(Monthly_Gift_Allocations__C mga: [SELECT Amount__c, Monthly_Gift__c, Program__c, Stream__c FROM Monthly_Gift_Allocations__c WHERE Monthly_Gift__r.Day_of_Month__c >= :firstdate AND Monthly_Gift__r.Day_of_Month__c <= :lastdate AND Monthly_Gift__r.PaymentType__c = :depbatch.PaymentType__c])
        {  
            Allocation__c a = new Allocation__c();
            a.Amount__c = mga.Amount__c;
            //This is the line that is important. 
            //associate the allocation to the correct Donation 
            //by finding the monthly gift in the map which the monthly gift allocation is tied to
            a.Transaction__c = mgDonationMap.get(mga.Monthly_Gift__c).Id;
            a.Program__c = mga.Program__c;
            a.Stream__c = mga.Stream__c;
            allocations.add(a);
        }
        insert allocations;
        return new PageReference('/a0a/o');

    }
    static testMethod void createbatches()
    {
        list<Deposit__c> batch = new List<Deposit__c>{}; 
        for(Integer i = 0; i < 5; i++)
        {
            Deposit__c b = new Deposit__c(DepositDate__c = date.today(), Deposit_Items__c = 2, DepositTotal__c = 77.5, PaymentType__c = 'EFT');
            batch.add(b);
        }
        for(Integer i = 0; i < 5; i++)
        {
            Deposit__c b = new Deposit__c(DepositDate__c = date.today(), Deposit_Items__c = 2, DepositTotal__c = 77.5, PaymentType__c = 'Canada Helps');
            batch.add(b);
        }
        test.startTest();
        insert batch;
        test.stopTest();
    }

    static testMethod void testcontroller()
    {
        Deposit__c mybatch = [SELECT Name, DepositDate__c, Deposit_Items__c, DepositTotal__c, PaymentType__c FROM Deposit__c LIMIT 1];

        PageReference pageRef = Page.pledges; 
        Test.setCurrentPage(pageref);
        updatepledges controller = new updatepledges(new ApexPages.StandardController(mybatch)); 
        
 
        String nextPage = controller.runpledges().getUrl();
        
        System.assertEquals('/apex/failure?error=noParam', nextPage);
        ApexPages.currentPage().getParameters().put('ID', mybatch.ID); 
// HERE ARE LINES 95 & 96. I HAVE COMMENTED THEM OUT SO I CAN SAVE MY CLASS- BUT AS A RESULT CANNOT PROCEED PAST LINE 24
      //  controller.firstselect('1');
      //  controller.lastselect('15');
    
        controller = new updatepledges(new ApexPages.StandardController(mybatch));

        nextPage = controller.runpledges().getUrl();
        

}
}

hi,

I am trying to insert data into a parent table based on an aggregate query (table is called receipt__c). I will need to add the results to a map, because I am going to add data to a child table later.

 

When I run the SOQL query that retreives the aggregate result, I also get a record called concat_donor__c. I want that value in my map because I will need it when I add the child records (concat_donor__c will determine which receipt__c records each child record should be associated with).

 

The line of code "receiptmap.put(ar.get('Transaction__r.concat_donor__c'), r);"

results in: "Error: Compile Error: Incompatible key type Object for MAP<String,receipt__c> at line 33 column 9".

 

How should I be doing this? If anyone could point me in the right direct I'd really appreciate it.

 

--------------------------

    List<receipt__c> receipts = new List<receipt__c>();
    Map<String, receipt__c> receiptmap = new Map<String, receipt__c>();
    List<aggregateResult> aloc = [SELECT sum(receiptable__c)tot, Transaction__r.concat_donor__c from Allocation__C WHERE receiptable__c > 0 AND Transaction__c not in (select transaction__c from Donation_Receipt_Link__c) group by Transaction__r.concat_donor__c];
    for (AggregateResult ar : aloc)
    {
        receipt__c r = new receipt__c();
        r.Amount__c = (Decimal) ar.get('tot');
        receipts.add(r);
        receiptmap.put(ar.get('Transaction__r.concat_donor__c'), r);

    }
    insert receipts;

hi everyone,

this is really simple.. yet i am lost!

 

I want to pass 2 values from 2 different selectLists in VF to an Apex class. I've found all kinds of stuff online about populating a selectList with data from an Apex class... but nothing about passing a parameter from VF to Apex.

 

My VF code is below. Once I have the 2 variables in Apex, I will use them in my SOQL WHERE clause.

 

thanks in advance!

 

-----------------

<apex:page standardController="Deposit__c" extensions="updatepledges">
<apex:form >  
First Date to include:
<apex:selectList id="first" size="1" >
            <apex:selectoption itemLabel="First of month" itemValue="1"></apex:selectoption>
            <apex:selectoption itemLabel="Second of month" itemValue="2"></apex:selectoption>
            <apex:selectoption itemLabel="Third of month" itemValue="3"></apex:selectoption>
            <apex:selectoption itemLabel="Fourth of month" itemValue="4"></apex:selectoption>
  // ... the list continues like this...
            <apex:selectoption itemLabel="Thirty first of month" itemValue="31"></apex:selectoption>
</apex:selectList>  


Last date to include:
<apex:selectList id="last" size="1" >
            <apex:selectoption itemLabel="First of month" itemValue="1"></apex:selectoption>
            <apex:selectoption itemLabel="Second of month" itemValue="2"></apex:selectoption>
            <apex:selectoption itemLabel="Third of month" itemValue="3"></apex:selectoption>
            <apex:selectoption itemLabel="Fourth of month" itemValue="4"></apex:selectoption>
  // ... the list continues like this...
            <apex:selectoption itemLabel="Thirty first of month" itemValue="31"></apex:selectoption>
</apex:selectList>
<apex:commandButton action="{!runpledges}" value="Submit" />

</apex:form>   
<apex:pageMessages />
</apex:page>

I'm trying automate the entry of recurring monthly donations for a non-profit. The process involves an object called monthly_gift__c (where I want to copy from) and an object called donation__c (where I want to copy to).

 

I keep gettinging Error: Compile Error: Incompatible element type SOBJECT:Monthly_Gift__c for collection of SOBJECT:Donation__c at line 22 column 9, and I assume its because the columns in the 2 table don't line up perfectly.

 

I'm not sure how to modify the list/collection before inserting, or if that is even the best method to use here.

 

Any help would be much appreciated,

James

 

public class updatepledges
{


    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
       
        public updatepledges(ApexPages.StandardController controller)
        {
            //initialize the stanrdard controller
            this.controller = controller;
            
   

 


    List<Donation__c> donations = new List<Donation__c>();
    for (Monthly_Gift__c mg: [SELECT Account__c, Contact__c, PaymentType__c FROM Monthly_Gift__c])
// the last line is causing the error. how can i extrract from donation__c and insert into Monthly_Gift__c??? 

{

        Monthly_Gift__c Newmg = mg.clone(false);
        donations.add(Newmg);
    }
    insert donations;

 

 

// the same problem will presumably come up again in the next few lines of code, where i insert detail records

    List<Allocation__c> allocations = new List<Allocation__c>();
    for (Donation__c currdon : donations)  
    {
        for(Monthly_Gift_Allocations__C mga: [SELECT Amount__c, Monthly_Gift__c, Program__c, Stream__c FROM Monthly_Gift_Allocations__c])
        {  
            Monthly_Gift_Allocations__c Newmga = mga.clone(false);
            allocations.add(Newmga);
        }
    }
    insert allocations;

}
}

I'm new to salesforce.com, and looking for some guidance.

 

I need a way to insert a master record, and then its related detail records.

 

I initially though of using the following pseudo-code:

do

     insert master record

     do

           insert detail record and set foriegn key = recently inserted master record

      loop until end of detail records

loop until end of master records

 

This won't work because I will exceed governor limits. Any adivce on how best to proceed?

hi everyone,

i work for an ngo and am tasked with moving our access database over to salesforce.

 

we have alot of recurring monthly gifts, and it would be a waste of time to enter them manually. in access, i use a bit of visual basic & sql to automate this. i am at a total loss for how to do this in salesforce... the more i read the more confused i get. in addition each pledge/donation is allocated among several funds (one gift, many allocations, one allocation, many funds - basically a many-to-many relationship). each time the values from the pledge object are added to the donation object, the corresponded pledge allocations must be added to the allocations object.

 

here is the basic algorith (without INSERT statements):

 

get firstdate variable from datepicker1

get lastdate variable from datepicker2

get paymetmethod from picklist

 

select all pledges where paymentmethod = picklist AND date >=firstdate AND date <=lastdate

 

do

      create new donation record with values from current pledge record

       select all pledges where pledge_allocation.pledgeID = current pledgeID

       do

                  create new allocation record with value from current pledge allocation record and ID from donation record just created

                  goto next pledge allocation record

        loop until end of file (or end of array selected)

 

         goto next pledge record

loop until end of file (or end of array selected)

 

 

 

this seems really basic... but i am at a total loss!

 

One option that will not work is triggering the creation of new oppourtunities after one has been updated. there are a number of reasons why i dont want to use the oppourtunities object, and i also don't want to clutter the end user's view with 25 future-dated pledges.

 

 

any help would be much appreciated!

James

hi,

I have a apex class that runs every night to update aggregate fields on Accounts. It works fine, but I added a new peice of functionality that is not working.

 

I've added a field called "grandmother sponsor" (I am working with an NGO doing work in southern africa) to accounts. Everynight when my class runs, I want to pull up all accounts that have a child object called monthly_gift__c with a child object called Monthly_Gift_Allocations__c that is linked to a program account called grandmother support.

 

I know my query works. I know I have active grandmother sponsors. But when I run my test classes the bold/italic/underlined peice of code (below) never runs.

 

 

Would anyone mind having a look over the code below and tell me what I need to do get all accounts with a child object that has a grandchild object? Snippets of my code are below.

 

 

 

 

 

List<Monthly_Gift_Allocations__c> gsponsors = new List<Monthly_Gift_Allocations__c>();
for (Monthly_Gift_Allocations__c gsponsorquery: [SELECT Monthly_Gift__r.Account__r.id from Monthly_Gift_Allocations__c where (Monthly_Gift__r.end_date__c = NULL OR Monthly_Gift__r.end_date__c > :system.today()) and (amount__c >= 20 and stream__r.name = '2 - Grandmother Support')])       
        {
            id myid = (id)gsponsorquery.get('id');
            isactive_grannysponsor.put(myid, TRUE);
          
        }

 

......

 

      List<Account> accountstoupdate = new List<Account>();
        for (Account a: [SELECT Total_transactions__c, granny_sponsor__c, last_nonmonthly__c, First_Transaction__c, Last_Transaction__c, Number_of_transactions__c, isactive_monthly__c, ID FROM Account])
        {

      if (isactive_grannysponsor.get(a.ID) != NULL)
            {
                a.granny_sponsor__c = TRUE;
            }
            else if (isactive_grannysponsor.get(a.ID) ==NULL)
            {
                a.granny_sponsor__c = FALSE;
            }

}

hi,

I have a bunch of objects and code in my sandbox. I've written test methods have have 100% coverage on my code, and everything seems fine.

 

There's just one problem. When I goto deploy, I run into a bunch of errors. Most of the errors have to do with dependancies: not being able to deploy a child object because there is no master object for it to look for, not being able to deploy master objects because there are no child objects to base roll-up summaries on, not being able to deploy formulas because the fields they reference are not installed yet.

 

Any idea how I should proceed? Having to re-create all my objects in the production environemnt to get around these dependancies seems like a pretty aweful prospect.

 

thanks

James

hi, I'm hoping someone can point me in the right direction.
I have a visual force page that passes 2 parameters to an APEX class. It seems to work fine, but before I deploy it need to develop a test class.
I am stuck at 31% code coverage. It looks like my parameters are NOT being passed and so I can't get past line 24 (below). I tried assigning values to "firstselect" and "lastselect" (see lines 95 and 96) but I get the following error:
Error: Compile Error: Method does not exist or incorrect signature: [updatepledges].firstselect(String) at line 95 column 8
I'm hoping someone could have a look at my test class and let me know how I should go about passing these parameters. Thanks in advance
public class updatepledges {
 
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    private Deposit__c depbatch {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}
    public String firstselect {get; set;}
    public String lastselect {get; set;}
    public String batch_paytype {get; set;}
       
    public updatepledges(ApexPages.StandardController controller)
    {
        //initialize the stanrdard controller
        this.controller = controller;

        // load the current record
        depbatch = (Deposit__c)controller.getRecord();
    }
    public PageReference runpledges() 
    {
// THE NEXT LINE IS #24. I CANT GET ANY COVERAGE BEYOND THIS POINT, I THINK BECAUSE IM NOT PROPERLY PASSING THE PARAMETER
        integer firstdate = integer.valueof(firstselect);
        integer lastdate = integer.valueof(lastselect); 
        depbatch = [select PaymentType__c from Deposit__c where Id = :depbatch.Id];
        batch_paytype = String.Valueof(depbatch.get(Deposit__c.PaymentType__c));
        List<Donation__c> donations = new List<Donation__c>();
        Map<ID,Donation__c> mgDonationMap = new Map<ID,Donation__c>();
        for (Monthly_Gift__c mg: [SELECT Id, Account__c, Contact__c, PaymentType__c FROM Monthly_Gift__c WHERE PaymentType__c = :batch_paytype AND Day_of_Month__c >= :firstdate AND Day_of_Month__c <= :lastdate])
        {
            //Create a donation and populate it. then add it to the list
            Donation__c d = new Donation__c();
            d.Account__c = mg.Account__c;
            d.Contact__c = mg.Contact__c;
            d.Payment_Type__c = mg.PaymentType__c;
            d.Deposit_Batch__c = depbatch.Id;
            donations.add(d);
            //add the id of the monthly donation and the new dontation to a map to be used for the allocations
            mgDonationMap.put(mg.id,d);
        }
        insert donations;

        
        
        List<Allocation__c> allocations = new List<Allocation__c>();
        for(Monthly_Gift_Allocations__C mga: [SELECT Amount__c, Monthly_Gift__c, Program__c, Stream__c FROM Monthly_Gift_Allocations__c WHERE Monthly_Gift__r.Day_of_Month__c >= :firstdate AND Monthly_Gift__r.Day_of_Month__c <= :lastdate AND Monthly_Gift__r.PaymentType__c = :depbatch.PaymentType__c])
        {  
            Allocation__c a = new Allocation__c();
            a.Amount__c = mga.Amount__c;
            //This is the line that is important. 
            //associate the allocation to the correct Donation 
            //by finding the monthly gift in the map which the monthly gift allocation is tied to
            a.Transaction__c = mgDonationMap.get(mga.Monthly_Gift__c).Id;
            a.Program__c = mga.Program__c;
            a.Stream__c = mga.Stream__c;
            allocations.add(a);
        }
        insert allocations;
        return new PageReference('/a0a/o');

    }
    static testMethod void createbatches()
    {
        list<Deposit__c> batch = new List<Deposit__c>{}; 
        for(Integer i = 0; i < 5; i++)
        {
            Deposit__c b = new Deposit__c(DepositDate__c = date.today(), Deposit_Items__c = 2, DepositTotal__c = 77.5, PaymentType__c = 'EFT');
            batch.add(b);
        }
        for(Integer i = 0; i < 5; i++)
        {
            Deposit__c b = new Deposit__c(DepositDate__c = date.today(), Deposit_Items__c = 2, DepositTotal__c = 77.5, PaymentType__c = 'Canada Helps');
            batch.add(b);
        }
        test.startTest();
        insert batch;
        test.stopTest();
    }

    static testMethod void testcontroller()
    {
        Deposit__c mybatch = [SELECT Name, DepositDate__c, Deposit_Items__c, DepositTotal__c, PaymentType__c FROM Deposit__c LIMIT 1];

        PageReference pageRef = Page.pledges; 
        Test.setCurrentPage(pageref);
        updatepledges controller = new updatepledges(new ApexPages.StandardController(mybatch)); 
        
 
        String nextPage = controller.runpledges().getUrl();
        
        System.assertEquals('/apex/failure?error=noParam', nextPage);
        ApexPages.currentPage().getParameters().put('ID', mybatch.ID); 
// HERE ARE LINES 95 & 96. I HAVE COMMENTED THEM OUT SO I CAN SAVE MY CLASS- BUT AS A RESULT CANNOT PROCEED PAST LINE 24
      //  controller.firstselect('1');
      //  controller.lastselect('15');
    
        controller = new updatepledges(new ApexPages.StandardController(mybatch));

        nextPage = controller.runpledges().getUrl();
        

}
}

hi,

I am trying to insert data into a parent table based on an aggregate query (table is called receipt__c). I will need to add the results to a map, because I am going to add data to a child table later.

 

When I run the SOQL query that retreives the aggregate result, I also get a record called concat_donor__c. I want that value in my map because I will need it when I add the child records (concat_donor__c will determine which receipt__c records each child record should be associated with).

 

The line of code "receiptmap.put(ar.get('Transaction__r.concat_donor__c'), r);"

results in: "Error: Compile Error: Incompatible key type Object for MAP<String,receipt__c> at line 33 column 9".

 

How should I be doing this? If anyone could point me in the right direct I'd really appreciate it.

 

--------------------------

    List<receipt__c> receipts = new List<receipt__c>();
    Map<String, receipt__c> receiptmap = new Map<String, receipt__c>();
    List<aggregateResult> aloc = [SELECT sum(receiptable__c)tot, Transaction__r.concat_donor__c from Allocation__C WHERE receiptable__c > 0 AND Transaction__c not in (select transaction__c from Donation_Receipt_Link__c) group by Transaction__r.concat_donor__c];
    for (AggregateResult ar : aloc)
    {
        receipt__c r = new receipt__c();
        r.Amount__c = (Decimal) ar.get('tot');
        receipts.add(r);
        receiptmap.put(ar.get('Transaction__r.concat_donor__c'), r);

    }
    insert receipts;

hi everyone,

this is really simple.. yet i am lost!

 

I want to pass 2 values from 2 different selectLists in VF to an Apex class. I've found all kinds of stuff online about populating a selectList with data from an Apex class... but nothing about passing a parameter from VF to Apex.

 

My VF code is below. Once I have the 2 variables in Apex, I will use them in my SOQL WHERE clause.

 

thanks in advance!

 

-----------------

<apex:page standardController="Deposit__c" extensions="updatepledges">
<apex:form >  
First Date to include:
<apex:selectList id="first" size="1" >
            <apex:selectoption itemLabel="First of month" itemValue="1"></apex:selectoption>
            <apex:selectoption itemLabel="Second of month" itemValue="2"></apex:selectoption>
            <apex:selectoption itemLabel="Third of month" itemValue="3"></apex:selectoption>
            <apex:selectoption itemLabel="Fourth of month" itemValue="4"></apex:selectoption>
  // ... the list continues like this...
            <apex:selectoption itemLabel="Thirty first of month" itemValue="31"></apex:selectoption>
</apex:selectList>  


Last date to include:
<apex:selectList id="last" size="1" >
            <apex:selectoption itemLabel="First of month" itemValue="1"></apex:selectoption>
            <apex:selectoption itemLabel="Second of month" itemValue="2"></apex:selectoption>
            <apex:selectoption itemLabel="Third of month" itemValue="3"></apex:selectoption>
            <apex:selectoption itemLabel="Fourth of month" itemValue="4"></apex:selectoption>
  // ... the list continues like this...
            <apex:selectoption itemLabel="Thirty first of month" itemValue="31"></apex:selectoption>
</apex:selectList>
<apex:commandButton action="{!runpledges}" value="Submit" />

</apex:form>   
<apex:pageMessages />
</apex:page>

I'm trying automate the entry of recurring monthly donations for a non-profit. The process involves an object called monthly_gift__c (where I want to copy from) and an object called donation__c (where I want to copy to).

 

I keep gettinging Error: Compile Error: Incompatible element type SOBJECT:Monthly_Gift__c for collection of SOBJECT:Donation__c at line 22 column 9, and I assume its because the columns in the 2 table don't line up perfectly.

 

I'm not sure how to modify the list/collection before inserting, or if that is even the best method to use here.

 

Any help would be much appreciated,

James

 

public class updatepledges
{


    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
       
        public updatepledges(ApexPages.StandardController controller)
        {
            //initialize the stanrdard controller
            this.controller = controller;
            
   

 


    List<Donation__c> donations = new List<Donation__c>();
    for (Monthly_Gift__c mg: [SELECT Account__c, Contact__c, PaymentType__c FROM Monthly_Gift__c])
// the last line is causing the error. how can i extrract from donation__c and insert into Monthly_Gift__c??? 

{

        Monthly_Gift__c Newmg = mg.clone(false);
        donations.add(Newmg);
    }
    insert donations;

 

 

// the same problem will presumably come up again in the next few lines of code, where i insert detail records

    List<Allocation__c> allocations = new List<Allocation__c>();
    for (Donation__c currdon : donations)  
    {
        for(Monthly_Gift_Allocations__C mga: [SELECT Amount__c, Monthly_Gift__c, Program__c, Stream__c FROM Monthly_Gift_Allocations__c])
        {  
            Monthly_Gift_Allocations__c Newmga = mga.clone(false);
            allocations.add(Newmga);
        }
    }
    insert allocations;

}
}

I'm new to salesforce.com, and looking for some guidance.

 

I need a way to insert a master record, and then its related detail records.

 

I initially though of using the following pseudo-code:

do

     insert master record

     do

           insert detail record and set foriegn key = recently inserted master record

      loop until end of detail records

loop until end of master records

 

This won't work because I will exceed governor limits. Any adivce on how best to proceed?