• RelaxItsJustCode
  • NEWBIE
  • 175 Points
  • Member since 2012

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 87
    Questions
  • 90
    Replies
It seems I need to take the opportunity owner and the extra opportunitysplit user and insert them both at the same time in the test code but I cannot seem to workaround this to create a opportunitysplit in test code.

Please advise what does it take apex test code wise to create a opportunitysplit 50/50 between two users on an opportunity?

Kudos given to anyone that has a winning answer.

Thank you,
Steve
It seems I need to take the opportunity owner and the extra opportunitysplit user and insert them both at the same time in the test code but I cannot seem to workaround this to create a opportunitysplit in test code.

Please advise what does it take apex test code wise to create a opportunitysplit 50/50 between two users on an opportunity?

Kudos given to anyone that has a winning answer.

Thank you,
Steve
I have two partner community users that belong to the same partner, have exactly the same profile and role, and one partner user can see all of the activity history on a case, while the other Partner community user can only see a subset of the activity history on the same case.  Kudos given if you have a way around this.  Please help?
I am having issues writing test code for the following code.  

Public Class CashMatchingFunctions
{
    Public static void UpdateAccountingInfo(Map<Id,c2g__codaCashMatchingHistory__c> oldMap, Map<Id,c2g__codaCashMatchingHistory__c> newMap)
    {
   
        List<Id> cmh_ids = new List<Id>();
        List<Id> cmh2_ids = new List<Id>();
        List<Id> tli_ids = new List<Id>();    
        List<Id> trn_ids = new List<Id>();    
 
        List<Id> SI_ids = new List<Id>();
        List<String> SI_Numbers = new List<String>();
        List<Id> Oppty_ids = new List<Id>();
       
        String SalesInvoiceNumber;
        Double HomeValue;
        Date MatchingDate;
        String OpportunityId;
        String TransactionType;
        String TransactionId;
        String TransactionIdUpdated;
        //Transaction_Type_Formula__c  Sales_Invoice_Number__c
       
        for(c2g__codaCashMatchingHistory__c c : newMap.Values())
        {
            if(c.CMH_Formula__c == 'Invoice' && c.Opportunity__c == null)
            {
                 cmh_ids.add(c.Id);
                 SI_Numbers.add(c.Sales_Invoice_Number__c);   
                 trn_ids.add(c.Transaction_Id__c);
                
            }
        }
       
    
         String SalesInvoiceNumber1;
         String TransactionIdProcess;
         String cmhid;
         String cmhform;
         for (c2g__codaTransaction__c t :[select id from c2g__codaTransaction__c where id in :trn_ids])
         {
             
              
           
               
               
                for(c2g__codaCashMatchingHistory__c cc2 :[select id, c2g__MatchingDate__c, CMH_Formula__c, Sales_Invoice_Number__c, Opportunity__c, c2g__HomeValue__c from c2g__codaCashMatchingHistory__c where Opportunity__c = '' and id = : cmh_ids])               
                {
                    c2g__codaCashMatchingHistory__c cc = [select id, c2g__MatchingDate__c, CMH_Formula__c, Sales_Invoice_Number__c, Opportunity__c, c2g__HomeValue__c from c2g__codaCashMatchingHistory__c where Opportunity__c = '' and Sales_Invoice_Number__c = : cc2.Sales_Invoice_Number__c];
                    HomeValue = cc.c2g__HomeValue__c;
                    MatchingDate = cc.c2g__MatchingDate__c;
                    cmhid = cc.id;
                    cmhform = cc.cmh_formula__c;
                    SalesInvoiceNumber1 = cc.Sales_Invoice_Number__c;
                }
                if(cmhform == 'Invoice')
                {
                List<Accounting__c> AccountingRecordsToInsert = new List<Accounting__c>();
                Accounting__c newAccountingInfo= new Accounting__c();

                c2g__codaInvoice__c tt = [select id, Name, c2g__Opportunity__c from c2g__codaInvoice__c where name = : SalesInvoiceNumber1];
                SalesInvoiceNumber1 = tt.Name;
               
                OpportunityId = tt.c2g__Opportunity__c;

                newAccountingInfo.Opportunity__c = OpportunityId;
                newAccountingInfo.Amount__c = HomeValue;
               
                newAccountingInfo.Date__c = MatchingDate;
     
                AccountingRecordsToInsert.add(newAccountingInfo);
                              
                if(AccountingRecordsToInsert.size() > 0)
                {
                newAccountingInfo.Invoice_Number__c = SalesInvoiceNumber1;
                newAccountingInfo.RecordTypeId =  ServiceClass.getRecordTypesNameMap('Accounting__c').get('Paid').Id;
                newAccountingInfo.Type__c = 'Paid';
                    Insert(AccountingRecordsToInsert);
                }     
                List<c2g__codaCashMatchingHistory__c> CMH_RecordsToUpdate = new List<c2g__codaCashMatchingHistory__c>();
       
                            for(c2g__codaCashMatchingHistory__c cmh2 :[Select id, Opportunity__c from c2g__codaCashMatchingHistory__c where Id in :cmh_ids])
                            {
                                if(cmhid == cmh2.id)
                                {
                                cmh2.Opportunity__c = OpportunityId;
                                CMH_RecordsToUpdate.add(cmh2);
                                }
                            }
                            if(CMH_RecordsToUpdate.size() > 0)
                            {
                                Update CMH_RecordsToUpdate;
                            } }

         }
       
                
            
       
    }
------------------------------------------------------- Here is the test code 

@isTest
private class PostAndMatchAction_Test{
    static final boolean softFail = false; //if true tests will fail softly - that is they will not be marked as failed but may not contribute full code coverage
    @isTest(seeAllData=true)
    static void invoiceTest(){
    String AccountId;
    String InvoiceId;
    String CashEntryId;
    String CashEntryLineItemsId;
        try{


    String CurrentUser;
    CurrentUser = UserInfo.getUserId();

    Account a1 = new Account(recordtypeid = ServiceClass.getRecordTypesNameMap('Account').get('Default').Id,Name = 'Test Acct', Industry = 'Federal',c2g__CODAAccountsReceivableControl__c = 'a1X7000000125BnEAI' );
    insert a1;

    AccountId = a1.id;

    Opportunity o1 = new Opportunity(Bill_To_Account__c = a1.id, Payment_Terms2__c= '100% Shipping',Payment_Terms__c= 'net 30', Amount = 10.00, NextStep = 'Quote',Name = 'Test Oppty', AccountId = a1.id, recordtypeid =     ServiceClass.getRecordTypesNameMap  ('Opportunity').get('Sales Quote (FL)').Id, Type = 'New Business', StageName = 'Quote', CloseDate = date.today());
     insert o1;

    OpportunityLineItem OLI = new OpportunityLineItem(totalPrice = 1.00, PriceBookEntryId = '01u70000001VydaAAC',OpportunityId = o1.id, Quantity = 50);
        insert OLI;   

User u1 = [SELECT Id FROM User WHERE Alias='APSFin'];
     System.RunAs(u1){
    o1.recordtypeid = ServiceClass.getRecordTypesNameMap('Opportunity').get('Closed Won').Id;
        o1.StageName = 'Closed Won';

                update o1;}

       
            c2g__codaInvoice__c newInvoice = new c2g__codaInvoice__c(
                c2g__Account__c = a1.id,
    c2g__Opportunity__c = o1.id,
                c2g__InvoiceDate__c = Date.today()
               
            );
            insert newInvoice;
           InvoiceId = newInvoice.id;
            List<c2g__codaInvoiceLineItem__c> newInvoiceLines = new List<c2g__codaInvoiceLineItem__c>{
                new c2g__codaInvoiceLineItem__c(
                    c2g__Invoice__c = newInvoice.id,
                    c2g__Product__c = '01t70000000oPMAAA2'
                )
            };
            insert newInvoiceLines;
           
            //Post it!
            update new c2g__codaInvoice__c(id = newInvoice.id,c2g__InvoiceStatus__c = 'Complete');
              system.assert(true,'WIN');         
        }catch(Exception e){
            if(softFail)
                System.debug(LoggingLevel.Error,'Soft fail enabled. Test marked as passed but it really failed with '+e.getMessage());
            else
                throw e;
        }
        try{
        string Bank_Account_id = 'a0y70000001qykc';
        c2g__codaCashEntry__c cashEntry = new c2g__codaCashEntry__c();
        cashEntry.c2g__BankAccount__c = BANK_ACCOUNT_ID;
        List<c2g__codacashentrylineitem__c> cashEntryLineItems = new List<c2g__codacashentrylineitem__c>();
        c2g__codaCashEntryLineItem__c cashEntryLineItem = new c2g__codaCashEntryLineItem__c();
        cashEntryLineItem.c2g__Account__c = AccountId;
cashEntryLineItem.c2g__CashEntryValue__c = 1.00;
cashEntryLineItems.add(cashEntryLineItem);
//Execute DML to insert Cash Entry
insert cashEntry;
CashEntryId = cashEntry.id;
for(c2g__codaCashEntryLineItem__c cashEntryLineItem2 : cashEntryLineItems)
{
    cashEntryLineItem2.c2g__CashEntry__c = cashEntry.Id;
}
insert cashEntryLineItems;
List<c2g__codaCashEntryLineItem__c> CashEntryLineItemsIds = new List<c2g__codaCashEntryLineItem__c>();
//CashEntryLineItemsIds.add(cashEntryLineItems.id);
   
//////////////////////////////////////////////////////////////////////////////
List<string> documentRefs = new List<string>();
documentRefs.add([select Id, Name from c2g__codaInvoice__c
where Id = :InvoiceId].Name);
documentRefs.add([select Id, Name from c2g__codaCashEntry__c
where Id = :CashEntryId].Name);
List<c2g__codatransactionlineitem__c> transactionLinesToMatch = [
    select
        Id,
        c2g__AccountValue__c
    from c2g__codaTransactionLineItem__c
    where
        c2g__Transaction__r.c2g__DocumentNumber__c in :documentRefs and
        c2g__LineType__c = 'Account'
];


c2g.CODAAPICommon_6_0.Context context = new c2g.CODAAPICommon_6_0.Context();
c2g.CODAAPICashMatchingTypes_6_0.Configuration configuration = new c2g.CODAAPICashMatchingTypes_6_0.Configuration();
configuration.Account = c2g.CODAAPICommon.getRef(AccountId, null);

configuration.MatchingCurrencyMode = c2g.CODAAPICashMatchingTypes_6_0.enumMatchingCurrencyMode.Account;
configuration.MatchingDate = System.today();
configuration.MatchingPeriod = c2g.CODAAPICommon.getRef('a28700000004ZLa', null);
List<c2g.codaapicashmatchingtypes_6_0.item> items = new List<c2g.codaapicashmatchingtypes_6_0.item>();
for (c2g__codaTransactionLineItem__c transactionLine : transactionLinesToMatch)
{
    c2g.CODAAPICashMatchingTypes_6_0.Item item = new c2g.CODAAPICashMatchingTypes_6_0.Item();
    item.TransactionLineItem = c2g.CODAAPICommon.getRef(transactionLine.Id, null);
    item.Paid = 1.00;
    item.Discount = 0; // No discount in this example
    item.WriteOff = 0;  // No write off in this example
    items.add(item);
}

c2g.CODAAPICashMatchingTypes_6_0.analysis analisysInfo = new c2g.CODAAPICashMatchingTypes_6_0.analysis();
// analisysInfo.DiscountGLA = ...
// analisysInfo.DiscountDimension1..4 = ...
// analisysInfo.WriteOffGLA = ...
// analisysInfo.WriteOffDimension1..4 = ...
// analisysInfo.CurrencyWriteOffGLA = ...
// analisysInfo.CurrencyWriteOffDimension1..4 = ...
c2g.CODAAPICommon.Reference matchReference = c2g.CODAAPICashMatching_6_0.Match(context, configuration, items, analisysInfo);
       system.assert(true,'WIN');         
     //
     system.assert(TRUE,'No Error');
            }
       catch( exception e )
            {
            
            }
  
   
   
   
    }
}

Please help if you can.  So far I hate FFDC''s API.

Thank you,
S

I'm working on a very old Salesforce instance that has been open until recently.

I have deleted every sharing rule in the enterprise wide sharing setting section.

I have adjusted every security profile in the system.

I have reworked every role in the heirarchy in the system.

But I am having huge issues eliminating the manually shared records to close the gap.

I need help using the dataloader or some other approach to eliminate the records that have been manually shared to groups like "All internal users" at the record level?

Please help me if you can I will give kudos to anyone that can get me across the finish line.

Thank you,
S
I'm working on a very old Salesforce instance that has been open until recently.

I have deleted every sharing rule in the enterprise wide sharing setting section.

I have adjusted every security profile in the system.

I have reworked every role in the heirarchy in the system.

But I am having huge issues eliminating the manually shared records to close the gap.

I need help using the dataloader or some other approach to eliminate the records that have been manually shared to groups like "All internal users" at the record level?

Please help me if you can I will give kudos to anyone that can get me across the finish line.

Thank you,
S
The code below has been slightly simplified for the sake of this post.  What I have incountered is that when I need to load more than 5 or 6 contracts each with multiple contract line items if I do a straight copy it loads well in bulk, but when I try to tie in the pricebookentry table (given the pricebook2id is a constant) to get the latest list price on a product I blow up the SOQL gov.

What I need is a way of tying in the Pricebookentry table without blowing up the SOQL governer.  Please help I will give kudos if you can help me resolve this issue.

Here is the code:

Trigger ContractTriggerCreatContractAndOLIs on Contract (after update)
{

    map<id, contract>  originalToCloneMap = new map<id, contract>(); 
    
    List<Contract> ContractsToClone = [Select id, Parent_Contract__c, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, 
            DateFinal__c,PrevNumberOfDays__c,
            PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c,
            SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate,
            Contract_End_Date__c, Case__c, RecordTypeId 
            from Contract where Status = 'Maintenance Paid' and Test_Contract_Clone__c = TRUE and Processed_Renewal_Contract__c = False and Id in :Trigger.newMap.keySet()];
    
    List<Contract> ContractsToInsert = new List<Contract>();
    Contract newContract = new Contract();
        
    List<Contract> ContractsToUpdate = new List<Contract>();
        
    for(Contract c: ContractsToClone)
    {
        c.Processed_Renewal_Contract__c = TRUE;
        ContractsToUpdate.add(c);
        
        cParentId = c.id;
        
        NewContract = new Contract();
         
        StartDate = c.StartDate;
        PrevStartDate = c.StartDate;
        PrevEndDate = c.Contract_End_Date__c;
        EndDate = c.Contract_End_Date__c;
        OriginalCase = c.Original_Case__c;
        MaintTermMisMatch = c.Maintenance_out_of_sync__c;
    
        PrevNumberOfDays = PrevStartDate.DaysBetween(PrevEndDate)+1;
      
        newContract.PrevNumberOfDays__c = PrevNumberOfDays;
        newContract.PrevStartDate__c = PrevStartDate;
        newContract.PrevEndDate__c = PrevEndDate;
        newContract.PrevNumberOfLeapYearDays__c = PrevNumberOfLeapYearDays;
    
        newContract.Months_between_start_and_end__c = c.StartDate.monthsBetween((c.Contract_End_Date__c +1));
              
        Integer count = 0;
               
               
        NumberOfDays = StartDate.DaysBetween(EndDate)+1;
        newContract.NewlyCreatedNumDays__c = NumberOfDays;
        NumberOfLeapYearDays = 0;
        Date CurrentDay;
        newContract.Contract_End_Date__c = c.Contract_End_Date__c.addDays((NumberOfDays));
        newContract.RecordTypeId = ServiceClass.getRecordTypesNameMap('Contract').get('Maintenance Contract').Id;
                
        newContract.SpecialTerms = c.SpecialTerms;
        newContract.Override_Total_Price__c = c.Override_Total_Price__c;
        newContract.Total_Maintenance_Price__c = c.Total_Maintenance_Price__c;
    
        newContract.StartDate = c.Contract_End_Date__c + 1;
        newContract.Attn_To__c = c.Attn_To__c;
        
        newContract.Original_Case__c = OriginalCase;
        newContract.Maintenance_out_of_sync__c = c.Maintenance_out_of_sync__c;
   
        NewContract.Status = 'Pending';
        NewContract.Accountid = c.AccountId;
        NewContract.RecordTypeId = c.RecordTypeId;
        NewContract.Parent_Contract__c = cParentId;
            
        originaltoCloneMap.put(c.id, NewContract);
        ContractsToInsert.add(NewContract);
    }
    
    Update ContractsToUpdate;
    Insert ContractsToInsert;
    
 
     
       Contract_Line_Item__c newCLI = new Contract_Line_Item__c();    
       
       List<Contract_Line_Item__c> CLIsToInsert = new List<Contract_Line_Item__c>();
 
       for(Contract_Line_Item__c cc :[Select Contract_Line_Item_Status__c, Contract__c, List_Price__c, Product_LU__c, Quantity__c, Account__c from Contract_Line_Item__c where Contract__c in :originalToCloneMap.keyset()])
        {
        
            newCLI = new Contract_Line_Item__c();
           
           newCLI.Contract__c = originaltoCloneMap.get(cc.Contract__c).id;
           newCLI.Contract_Line_Item_Status__c = 'Pending';
           newCLI.Product_LU__c = '01t7000000170yy';
           
          // PriceBookEntry cccc = [Select Id, UnitPrice from PriceBookEntry where Pricebook2Id = '01s3000000004T2' and Product2Id = : cc.Product_Lu__c Limit 1];
          // newCLI.List_Price__c = cccc.UnitPrice;
           newCLI.List_Price__c = cc.List_Price__c;
           newCLI.Product_LU__c = cc.Product_Lu__c;
           newCLI.Quantity__c = cc.Quantity__c;
           newCLI.Account__c = cc.Account__c;
           newCLI.Contract_Line_Item_Origin__c = 'Contract Clone Follow Up Contract';
                      if(cc.Contract_Line_Item_Status__c == 'Do Not Renew')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Do Not Renew';
                    }       
                    if(cc.Contract_Line_Item_Status__c == 'Cancelled')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Cancelled';
                    }  
            CLIsToInsert.add(newCLI);
            
        }   
         insert CLIsToInsert;    
}

Thank you,
S
I have the standard object Contract and a custom object that has a master detail relationship with called Contract_Line_Item__c.  I need to be able to load this code with a larger than 1 batch size.  My problem is I am used to using SOQL heavily, now I am trying to learn the more efficient approach that allows for bulk loading.

The problem I have is that I haven't been able to figure out how to load the child records due to the need of knowing the newly created parent id's.

Here is the code, please help me out if you can.  Thank you,

Trigger ContractTriggerCreatContractAndOLIs on Contract (after update)
{

    Date StartDate;
    Date EndDate;
    String cAccountid;
    String cContractId;
    String cParentId;
   
    List<Contract> ContractsToClone = [Select id, Parent_Contract__c, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, DateFinal__c,PrevNumberOfDays__c,
            PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c,
            SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate,
            Contract_End_Date__c, Case__c, RecordTypeId
            from Contract where Test_Contract_Clone__c = TRUE and Processed_Renewal_Contract__c = False and Id in :Trigger.newMap.keySet()];

   
    List<Contract> ContractsToInsert = new List<Contract>();
    Contract newContract = new Contract();

    for(Contract c: ContractsToClone)
    {
        NewContract = new Contract();
        NewContract.StartDate = Date.Today();
        NewContract.Contract_End_Date__c = Date.Today();
        NewContract.Status = 'Pending';
        NewContract.Accountid = c.AccountId;
        NewContract.RecordTypeId = c.RecordTypeId;
        NewContract.Parent_Contract__c = c.id;
        ContractsToInsert.add(NewContract);
    }
   
    Insert ContractsToInsert;
   
   
    
   List<Contract_Line_Item__c> CLIs = [Select Account__c, Contract__c, Product_LU__c, Quantity__c from Contract_Line_Item__c where Contract__c in :ContractsToInsert];

}
Here is the code.

Public Class ContractFunctionsCloneContractAndOLIs
{

Public static void CloneMaintContractAndLineItems(Map<Id,Contract> oldMap, Map<Id,Contract> newMap)
      {
        List<Id> ContractToClone = new List<Id>();
        List<Id> ContractLineItemsToClone = new List<Id>();
       
        Date StartDate;
        Date EndDate;


       
      
        Integer NumberOfDays = 0;
        Integer NumberOfMonths = 0;
        Integer NumberOfYears = 0;
        Double YearTerm = 0;
        Integer NumberOfLeapYearDays = 0;
        Integer TermsByMonth = 0;
        Integer Prevcount =0;
       
        Boolean MaintTermMisMatch;
       
        String OriginalCase;
       
        Date CurrentDay;
        Date PrevCurrentDay;      

        Integer PrevNumberOfDays =0;
        Date PrevStartDate;
        Date PrevEndDate;
       
        Integer CNT = 0;
       
        Integer PrevNumberOfLeapYearDays =0;      
      
             
        for(Contract c : newMap.Values())
        {
            ContractToClone.add(c.Id);
               CNT = CNT +1;
        }

        
        for(Contract_Line_Item__c CLI :[Select id from Contract_Line_Item__c where Contract__c in :ContractToClone])
        {
            ContractLineItemsToClone.add(CLI.id);
        }
      
       Contract newContract = new Contract();
         List<Contract> ContractsToInsert1 = new List<Contract>();
         SET<Contract> ContractsToInsertSET = new SET<Contract>();
         List<Contract> ContractsToInsert = new List<Contract>();
         
        if(ContractToClone.size() > 0 && ContractLineItemsToClone.size() > 0)
        {
            for(Contract c : [Select id, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, DateFinal__c,PrevNumberOfDays__c,
            PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c,
            SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate,
            Contract_End_Date__c, Case__c, RecordTypeId from Contract where Id in :ContractToClone ])
            {


             

      
             StartDate = c.StartDate;
            PrevStartDate = c.StartDate;
            PrevEndDate = c.Contract_End_Date__c;
            EndDate = c.Contract_End_Date__c;
            OriginalCase = c.Original_Case__c;
            MaintTermMisMatch = c.Maintenance_out_of_sync__c;

        PrevNumberOfDays = PrevStartDate.DaysBetween(PrevEndDate)+1;
       


        while (Prevcount < (PrevNumberOfDays))
        {
            if(PrevStartDate.Month() == 2 && PrevStartDate.Day() == 29)
                        {
                        PrevNumberOfLeapYearDays = PrevNumberOfLeapYearDays + 1;           
                        }
             PrevCurrentDay = PrevStartDate.addDays(Prevcount);

            if(PrevCurrentDay.Month() == 2 && PrevCurrentDay.Day() == 29)
                        {
                        PrevNumberOfLeapYearDays = PrevNumberOfLeapYearDays + 1;           
                        }
            Prevcount++;
        }

                
                newContract.SpecialTerms = c.SpecialTerms;
                newContract.Override_Total_Price__c = c.Override_Total_Price__c;
                newContract.Total_Maintenance_Price__c = c.Total_Maintenance_Price__c;
                newContract.Status = 'Pending';
                newContract.AccountId = c.AccountId;
                newContract.StartDate = c.Contract_End_Date__c + 1;
                newContract.Attn_To__c = c.Attn_To__c;
               // newContract.Case__c = c.Case__c;
               
                newContract.Original_Case__c = OriginalCase;
                newContract.Maintenance_out_of_sync__c = MaintTermMisMatch;
           
            
                 newContract.PrevNumberOfDays__c = PrevNumberOfDays;
                 newContract.PrevStartDate__c = PrevStartDate;
                 newContract.PrevEndDate__c = PrevEndDate;
                 newContract.PrevNumberOfLeapYearDays__c = PrevNumberOfLeapYearDays;
            


                newContract.Months_between_start_and_end__c = c.StartDate.monthsBetween((c.Contract_End_Date__c +1));
               
                Integer count = 0;
                
                
                 NumberOfDays = StartDate.DaysBetween(EndDate)+1;
       
          while (count < (NumberOfDays+1))
        {
            if(EndDate.Month() == 2 && EndDate.Day() == 29)
                        {
                        NumberOfLeapYearDays = NumberOfLeapYearDays + 1;           
                        }
             CurrentDay = EndDate.addDays(count);

            if(CurrentDay.Month() == 2 && CurrentDay.Day() == 29)
                        {
                        NumberOfLeapYearDays = NumberOfLeapYearDays + 1;           
                        }
            count++;
        }
     
           newContract.NumberOfLeapYearDays2__c = NumberOfLeapYearDays;    
           newContract.Count__c = count;
           newContract.PrevCount__c = Prevcount;
          
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
           if(NumberOfDays >= 365)
           {
               NumberOfDays = NumberOfDays + NumberOfLeapYearDays - PrevNumberOfLeapYearDays;
               newContract.NewNumberOfDays__c = NumberOfDays;
               newContract.NewlyCreatedNumDays__c = NumberOfDays - NumberOfLeapYearDays;
           }
       
           if(NumberOfDays < 365)
           {
               newContract.NewNumberOfDays__c = NumberOfDays;
               newContract.NewlyCreatedNumDays__c = NumberOfDays;
           }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////      - PrevNumberOfLeapYearDays     
          newContract.Contract_End_Date__c = c.Contract_End_Date__c.addDays((NumberOfDays));
                newContract.RecordTypeId = ServiceClass.getRecordTypesNameMap('Contract').get('Maintenance Contract').Id;
                newContract.Parent_Contract__c = c.id;
         
              ContractsToInsert1.add(newContract);
              
        
        for (Contract s : ContractsToInsert1) {
          if (ContractsToInsertSET.add(s)) {
            ContractsToInsert.add(s);
              }
        }}}


                 
        insert(ContractsToInsert);
       
         List<Contract_Line_Item__c> ContractLineItemsToInsert = new List<Contract_Line_Item__c>();
               
                String ContractId;
                String AccountId;
                String CaseId;
                String CLIStatus;
                           
            for(Contract insertedContracts : [Select Id, Case__c, AccountId from Contract where id in :ContractsToInsert])
            {
                ContractId = insertedContracts.id;
                AccountId = insertedContracts.AccountId;
                CaseId = insertedContracts.Case__c;
                CLIStatus = 'Pending';
               
               
               
                           
            for(Contract_Line_Item__c cc : [Select id, Maintenance_Sales_Price__c, Contract_Line_Item_Status__c, Product_LU__c, Quantity__c, List_Price__c from Contract_Line_Item__c where Id in :ContractLineItemsToClone])
                {
                    Contract_Line_Item__c newCLI = new Contract_Line_Item__c();
                   
                   
                    newCLI.Contract_Line_Item_Status__c = CLIStatus;
                    newCLI.Contract__c = ContractId;
                    //newCLI.Case_Id__c = CaseId;
                    newCLI.Account__c = AccountId;
                    newCLI.Contract_Line_Item_Origin__c = 'Contract Clone Follow Up Contract';
                    newCLI.Product_LU__c = cc.Product_LU__c;
                    newCLI.Quantity__c = cc.Quantity__c;
                    newCLI.List_Price__c = cc.List_Price__c;    
                    newCLI.Maintenance_Sales_Price__c = cc.Maintenance_Sales_Price__c;
                    if(cc.Contract_Line_Item_Status__c == 'Do Not Renew')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Do Not Renew';
                    }        
                    if(cc.Contract_Line_Item_Status__c == 'Cancelled')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Cancelled';
                    }        
                    ContractLineItemsToInsert.add(newCLI);
                }}
                insert(ContractLineItemsToInsert);
                //update(ContractLineItemsToInsert);  
           
       
       
          

      }}
Public Class ContractFunctionsCloneContractAndOLIs
{

Public static void CloneMaintContractAndLineItems(Map<Id,Contract> oldMap, Map<Id,Contract> newMap)
      {
        List<Id> ContractToClone = new List<Id>();
        List<Id> ContractLineItemsToClone = new List<Id>();
       
        Date StartDate;
        Date EndDate;


       
      
        Integer NumberOfDays = 0;
        Integer NumberOfMonths = 0;
        Integer NumberOfYears = 0;
        Double YearTerm = 0;
        Integer NumberOfLeapYearDays = 0;
        Integer TermsByMonth = 0;
        Integer Prevcount =0;
       
        Boolean MaintTermMisMatch;
       
        String OriginalCase;
       
        Date CurrentDay;
        Date PrevCurrentDay;      

        Integer PrevNumberOfDays =0;
        Date PrevStartDate;
        Date PrevEndDate;
       
        Integer PrevNumberOfLeapYearDays =0;      
      
             
        for(Contract c : newMap.Values())
        {
            ContractToClone.add(c.Id);
      
        }

        
        for(Contract_Line_Item__c CLI :[Select id from Contract_Line_Item__c where Contract__c in :ContractToClone])
        {
            ContractLineItemsToClone.add(CLI.id);
        }
      
       Contract newContract = new Contract();
       
        if(ContractToClone.size() > 0 && ContractLineItemsToClone.size() > 0)
        {
            for(Contract c : [Select id, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, DateFinal__c,PrevNumberOfDays__c, PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c, SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate, Contract_End_Date__c, Case__c, RecordTypeId from Contract where Id in :ContractToClone ])
            {

List<Contract> ContractsToInsert = new List<Contract>();
     

      
                newContract.Total_Maintenance_Price__c = c.Total_Maintenance_Price__c;
                newContract.Status = 'Pending';
                newContract.AccountId = c.AccountId;
                newContract.StartDate = c.Contract_End_Date__c + 1;
                newContract.RecordTypeId = ServiceClass.getRecordTypesNameMap('Contract').get('Maintenance Contract').Id;
                newContract.Parent_Contract__c = c.id;
               
                                            
                ContractsToInsert.add(newContract);
        insert(ContractsToInsert);  
       
         List<Contract_Line_Item__c> ContractLineItemsToInsert = new List<Contract_Line_Item__c>();
               
                String ContractId;
                String AccountId;
                String CaseId;
                String CLIStatus;
                           
            for(Contract insertedContracts : [Select Id, Case__c, AccountId from Contract where id in :ContractsToInsert])
            {
                ContractId = insertedContracts.id;
                AccountId = insertedContracts.AccountId;
                CaseId = insertedContracts.Case__c;
                CLIStatus = 'Pending';
               
               
               
                            }
            for(Contract_Line_Item__c cc : [Select id, Maintenance_Sales_Price__c, Contract_Line_Item_Status__c, Product_LU__c, Quantity__c, List_Price__c from Contract_Line_Item__c where Id in :ContractLineItemsToClone])
                {
                    Contract_Line_Item__c newCLI = new Contract_Line_Item__c();
                   
                   
                    newCLI.Contract_Line_Item_Status__c = CLIStatus;
                    newCLI.Contract__c = ContractId;
                    //newCLI.Case_Id__c = CaseId;
                    newCLI.Account__c = AccountId;
                    newCLI.Contract_Line_Item_Origin__c = 'Contract Clone Follow Up Contract';
                    newCLI.Product_LU__c = cc.Product_LU__c;
                    newCLI.Quantity__c = cc.Quantity__c;
                    newCLI.List_Price__c = cc.List_Price__c;    
                    newCLI.Maintenance_Sales_Price__c = cc.Maintenance_Sales_Price__c;
                    if(cc.Contract_Line_Item_Status__c == 'Do Not Renew')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Do Not Renew';
                    }        
                    if(cc.Contract_Line_Item_Status__c == 'Cancelled')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Cancelled';
                    }        
                    ContractLineItemsToInsert.add(newCLI);
                }
                insert(ContractLineItemsToInsert);
                update(ContractLineItemsToInsert);  
            }
       
       
          

      }}}
Is it necessary to have code coverage in your full sandbox before deploying via change set to production?  If not, please explain?  I will give kudos to whomever responds.

Thank you,
S
I have a system setup to allow contracts to create renewal contracts automatically.  The problem is that if the range contains a leap year my expiration date is off.

Ideally what I need is if we have a date range that co-terms a new contract with an existing one where the total term is 3 years six months and 5 days, and there is a leap year in the range how do I examine each year and determine if a leap year is in the range?

I will give kudos to anyone that can help me out or direct me to a resource that has a solution to this issue.

The following code compiles and then blows up on execution.  What I'm trying to do is filter out the lines that have a field Contract_Line_Item_Status__c = 'Do Not Renew'.

 

What ever I'm doing this VF page does not like the <apex:outputPanel tags.

 

Please let me know if you have any ideas on how to best resolve this.  Kudos to the person that helps me figure this one out.

 

<table border="1" style="border-color: #3B5E91" cellspacing="0" cellpadding="1" width="100%" id="table4">

<tr>
       <td bgcolor="#d7dee9" align="Left"><font face="Arial">Quantity</font></td>      
       <td bgcolor="#d7dee9" align="Center"><font face="Arial">APS Part No.</font></td>             
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Product(s) Covered</font></td>
</tr>
<tr>
    
       <apex:repeat value="{!Contract.Service_Contract_Line_Items__r}" var="line">
       <apex:outputPanel rendered="{!IF(line.Contract_Line_Item_Status__c = 'Do Not Renew',false,true)}">
       
          <tr>
             <td align="Right">{!(ROUND(line.Quantity__c,0))}</td>
             <td align="Center">{!line.APS_Part_Number__c}</td>

             <td align="Left">{!line.Product_LU__r.name}</td>
          </tr>
       </apex:outputPanel>
       </apex:repeat>  
    
</tr>
</table>

 

I have 2 loops that are causing some small problems.

 

In the code below you will note that I have two loops that hit the PriceBookEntry table (pbe1).  The first loop searches through out main production pricebook.  The second loop, loops through the PriceBookEntry table (pbe2) searching to find the productid in the standard pricebook.

 

The  PROBLEM:

 

When the first loop finds the productId I am looking for and grabs the listprice out of the main pricebook, it sometimes continues to loop through the second loop through the standard and then the update has two duplicate id's and blows to high hell and back.

 

Anyone that contributes will get kudos.

 

The person that gets me closest to the solution will get solution credit as well.

 

Here's the code:

 

public with sharing class MaintContractLineItemCreation 
{    
    Public static String ProductLineState = 'Not Found';
    Public static void ContractLineItemInsert(Map<Id,Contract_Line_Item__c> oldMap, Map<Id,Contract_Line_Item__c> newMap)
    {
    
    List<Id> CLIIds = new List<Id>();
    map<Id,String> CLIMap = new map <Id,String>(); 
    
    List<Id> Prodid = new List<Id>();
    
    List<id> PBE = new List<Id>();
    
    for (Contract_Line_Item__c c : newMap.Values())
    {   
        if(c.Product_LU__c != null)
        {      
             CLIIds.add(c.Id);
        }
    }
    
    for (Contract_Line_Item__c Prod : newMap.Values())
    {   
        if(Prod.Product_LU__c != null)
        {      
             Prodid.add(Prod.Product_LU__c);
        }
    }
    
    List<Contract_Line_Item__c> ContractLinesToUpdate = new List<Contract_Line_Item__c>();
    List<Contract_Line_Item__c> ContractLinesToUpdate1 = new List<Contract_Line_Item__c>();
    
    for(PriceBookEntry pbe1 :[Select id, UnitPrice, Pricebook2Id from PriceBookEntry where (Pricebook2id = '01s3000000001JS') and Product2id in :Prodid])
    
    {
                 
           
           for (Contract_Line_Item__c cli :[Select id, List_Price__c from Contract_Line_Item__c where id in :CLIIds])
           {
             ProductLineState = 'Not Found';
             if(pbe1.Pricebook2Id == '01s3000000001JS' && ProductLineState != 'Found' && pbe1.UnitPrice != null)
             {  
           
                cli.List_Price__c = pbe1.UnitPrice;
                ContractLinesToUpdate.add(cli);
                ProductLineState = 'Found'; 
                update(ContractLinesToUpdate);
             }
             }
    for(PriceBookEntry pbe2 :[Select id, UnitPrice, Pricebook2Id from PriceBookEntry where (Pricebook2id = '01s3000000004T2AAI') and Product2id in :Prodid])
    
    {
    for (Contract_Line_Item__c cli :[Select id, List_Price__c from Contract_Line_Item__c where List_Price__c = null and id in :CLIIds])
           {
             if(pbe2.Pricebook2Id == '01s3000000004T2AAI' && cli.List_Price__c == null &&  pbe1.UnitPrice != null)
                  {
                    cli.List_Price__c = pbe2.UnitPrice;
                    ContractLinesToUpdate.add(cli);
                    ProductLineState = 'Found'; 
                     update(ContractLinesToUpdate);
            }      }                 
           }  }
           
         }
        }

 Thank you,

Steve Laycock

Hi, I'm a bit new when it comes to visualforce and how to release them and their controllers to production.

 

Who ever provides me with a reference I can use to create mine I will definitely give kudos to all that help.

 

Thank you,
Steve Laycock

Hi, I'm a bit new when it comes to visualforce and how to release them and their controllers to production.  

 

Who ever provides me with a reference I can use to create mine I will definitely give kudos to all that help.

 

Thank you,

Steve Laycock

I have 2 loops that are causing some small problems.

 

In the code below you will note that I have two loops that hit the PriceBookEntry table (pbe1).  The first loop searches through out main production pricebook.  The second loop, loops through the PriceBookEntry table (pbe2) searching to find the productid in the standard pricebook.

 

The  PROBLEM:

 

When the first loop finds the productId I am looking for and grabs the listprice out of the main pricebook, it sometimes continues to loop through the second loop through the standard and then the update has two duplicate id's and blows to high hell and back.

 

Anyone that contributes will get kudos.

 

The person that gets me closest to the solution will get solution credit as well.

 

Here's the code:

 

public with sharing class MaintContractLineItemCreation 
{    
    Public static String ProductLineState = 'Not Found';
    Public static void ContractLineItemInsert(Map<Id,Contract_Line_Item__c> oldMap, Map<Id,Contract_Line_Item__c> newMap)
    {
    
    List<Id> CLIIds = new List<Id>();
    map<Id,String> CLIMap = new map <Id,String>(); 
    
    List<Id> Prodid = new List<Id>();
    
    List<id> PBE = new List<Id>();
    
    for (Contract_Line_Item__c c : newMap.Values())
    {   
        if(c.Product_LU__c != null)
        {      
             CLIIds.add(c.Id);
        }
    }
    
    for (Contract_Line_Item__c Prod : newMap.Values())
    {   
        if(Prod.Product_LU__c != null)
        {      
             Prodid.add(Prod.Product_LU__c);
        }
    }
    
    List<Contract_Line_Item__c> ContractLinesToUpdate = new List<Contract_Line_Item__c>();
    List<Contract_Line_Item__c> ContractLinesToUpdate1 = new List<Contract_Line_Item__c>();
    
    for(PriceBookEntry pbe1 :[Select id, UnitPrice, Pricebook2Id from PriceBookEntry where (Pricebook2id = '01s3000000001JS') and Product2id in :Prodid])
    
    {
                 
           
           for (Contract_Line_Item__c cli :[Select id, List_Price__c from Contract_Line_Item__c where id in :CLIIds])
           {
             ProductLineState = 'Not Found';
             if(pbe1.Pricebook2Id == '01s3000000001JS' && ProductLineState != 'Found' && pbe1.UnitPrice != null)
             {  
           
                cli.List_Price__c = pbe1.UnitPrice;
                ContractLinesToUpdate.add(cli);
                ProductLineState = 'Found'; 
                update(ContractLinesToUpdate);
             }
             }
    for(PriceBookEntry pbe2 :[Select id, UnitPrice, Pricebook2Id from PriceBookEntry where (Pricebook2id = '01s3000000004T2AAI') and Product2id in :Prodid])
    
    {
    for (Contract_Line_Item__c cli :[Select id, List_Price__c from Contract_Line_Item__c where List_Price__c = null and id in :CLIIds])
           {
             if(pbe2.Pricebook2Id == '01s3000000004T2AAI' && cli.List_Price__c == null &&  pbe1.UnitPrice != null)
                  {
                    cli.List_Price__c = pbe2.UnitPrice;
                    ContractLinesToUpdate.add(cli);
                    ProductLineState = 'Found'; 
                     update(ContractLinesToUpdate);
            }      }                 
           }  }
           
         }
        }

 Thank you,

Steve Laycock

The following code works as far as attaching a visualforce pdf and emailing it to who I want.  

 

What I need help with is that I would like to build a regular HTML email template and call it from my code.

 

Anyone that contributes will get kudos.

 

Here is the code:

 

 public PageReference emailPDF() {
 
     
    List<Contract> ContractToUpdate = new List<Contract>();
    
    for(Contract c : [Select Id, Invoice_Sent__c from Contract where Id =:ParentId])
    {
            c.Invoice_Sent__c = True;
            ContractToUpdate.add(c);
    }

    update ContractToUpdate;
    
 
     ToAddresses = new List <String>();
     ToAddresses.add(cc.Finance_Contact_Email__c);
     
     Subject = 'Hope this works';
     Body = 'This is a test';
 
 
     Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
     PageReference pdf = Page.ContractPDFCreation;
     pdf.getParameters().put('id',parentId); 
     pdf.setRedirect(true);
     
     Blob b; 

        b = pdf.getContent();

      
     Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
     efa.setFileName('Invoice.pdf');
     efa.setBody(b);
  
     email.setSubject( subject );
     email.setToAddresses( ToAddresses );
     email.setPlainTextBody( body );
     
     email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
     
     Messaging.SendEmailResult [] r = 
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
    
     return new PageReference('/'+parentId); 
}

 Thank you,

Steve Laycock

The following code works as far as attaching a visualforce pdf and emailing it to who I want.  

 

What I need help with is that I would like to build a regular HTML email template and call it from my code.

 

Anyone that contributes will get kudos.

 

Here is the code:

 

 public PageReference emailPDF() {
 
     
    List<Contract> ContractToUpdate = new List<Contract>();
    
    for(Contract c : [Select Id, Invoice_Sent__c from Contract where Id =:ParentId])
    {
            c.Invoice_Sent__c = True;
            ContractToUpdate.add(c);
    }

    update ContractToUpdate;
    
 
     ToAddresses = new List <String>();
     ToAddresses.add(cc.Finance_Contact_Email__c);
     
     Subject = 'Hope this works';
     Body = 'This is a test';
 
 
     Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
     PageReference pdf = Page.ContractPDFCreation;
     pdf.getParameters().put('id',parentId); 
     pdf.setRedirect(true);
     
     Blob b; 

        b = pdf.getContent();

      
     Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
     efa.setFileName('Invoice.pdf');
     efa.setBody(b);
  
     email.setSubject( subject );
     email.setToAddresses( ToAddresses );
     email.setPlainTextBody( body );
     
     email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
     
     Messaging.SendEmailResult [] r = 
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
    
     return new PageReference('/'+parentId); 
}

 Thank you,

Steve Laycock

 

 

I am working on a scenario to where a user can preview VF page and then save it to the Contract object in the notes and attachments section.

 

I'm using two visualforce pages and a class to do this.

 

The problem is that when I hardcode an actual Contract.id the whole thing works.  

 

But when I try to pass a parameter for the Contract.id the preview fails with the error: "Id value is not valid for the Contract standard controller".

 

This is the problem line of code:

 <iframe height="600px" id="Page" name="Maint Invoice" src="/apex/ContractPDFCreation?id=800S0000000rQfb" width="100%"></iframe>

 Below are the two VF pages and class.  Pleasse let me know what I can do to pass this parameter successfully???  I will give kudos and solution credit for the person who can get me through this.

 

The first VF page I call is called "PdfGeneratorTemplate".

 

This is how the first VF page is executed via a button:

https://cs1.salesforce.com/apex/PdfGeneratorTemplate?id={!Contract.Id}

 

Note the hardcoded Contract.id in the following code, this is what needs fixed:

<apex:page controller="PdfGeneratorController" >
   <apex:form >  

   <apex:pageBlock title="PDF Input">  

      <apex:pageBlockButtons >
        <apex:commandButton action="{!savePdf}" value="Save PDF"/>
       </apex:pageBlockButtons>
      <apex:pageMessages />

 <iframe height="600px" id="Page" name="Maint Invoice" src="/apex/ContractPDFCreation?id=800S0000000rQfb" width="100%"></iframe>

    </apex:pageBlock> 
  </apex:form>    

</apex:page>
               

 This is the main VF page that renders a pdf:

<apex:page standardController="Contract" showHeader="false" renderas="pdf">

<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.APSLogoContract)}' title="logo" />
    </td>
    
    <td  align="center" style="font-size:20px;"><font face="Arial">
    <b>INVOICE</b></font>
    <table border="1" cellspacing="0" cellpadding="1" width="100%"  id="table77">
        <tr>
            <td bgcolor="#d7dee9">
                <font face="Arial"  style="font-size:13px;">Date: </font>
            </td>    
            <td>
                <font face="Arial" style="font-size:13px;">
                    <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                        <apex:param value="{!contract.WF_Invoice_Date__c}" /> 
                    </apex:outputText>
                
                </font>
            </td>
        </tr>
        <tr>
            <td bgcolor="#d7dee9">
                <font face="Arial"  style="font-size:13px;">Due: </font>
            </td>    
            <td>
                <font face="Arial" style="font-size:13px;">Due Upon Receipt</font>
            </td>
        </tr>    
    </table>     
    </td>
    

    
</tr>


</table>

<br/>

<table border="0" cellspacing="0" cellpadding="1" width="100%" id="table2">
<tr>
       <td colspan="2" style="font-size:13px;">
           <font face="Arial">BarbaraG@aps.us <br/><br/></font>
       </td>
</tr>
<tr>
       <td style="font-size:13px;">          
           <font face="Arial">Bill To:<br/><br/>
                             {!Contract.Account.Name}<br/>  
                             {!Contract.Account.BillingStreet}<br/>
                             {!Contract.Account.BillingCity}. {!Contract.Account.BillingState} {!Contract.Account.BillingPostalCode} 
           </font>
        </td>
        
        <td width="20%"></td>
        
        <td style="font-size:13px;">
           <font face="Arial">Ship To:<br/><br/>
                              {!Contract.Account.Name}<br/>
                              {!Contract.Account.ShippingStreet}<br/>
                              {!Contract.Account.ShippingCity}. {!Contract.Account.BillingState} {!Contract.Account.ShippingPostalCode}
           </font>
        </td>
</tr>    
</table>
<br/><br/><br/>


<table border="1" cellspacing="0" cellpadding="1" width="85%" id="table15">
<tr>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Contract Number</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Product</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Term</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Invoice Amount</font></td>
</tr>
<tr>
        <td align="center"><font face="Arial">
             {!Contract.ContractNumber}
            </font>
        </td>
        <td align="center"><font face="Arial">
             Maintenance
            </font>
        </td>
        <td align="center"><font face="Arial">
          <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                <apex:param value="{!contract.startdate}" /> 
          </apex:outputText>-<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
              <apex:param value="{!Contract.Contract_End_Date__c}" />
          </apex:outputText>
            </font>
        </td>
        <td align="center"><font face="Arial">
            <apex:outputText value="{0,number,$#,###,###.00}">
    <apex:param value="{!Contract.Total_Maintenance_Price__c}" />
  </apex:outputText>

            </font>
        </td>
</tr>



</table>
<br/><br/>

<table border="1" style="border-color: #3B5E91" cellspacing="0" cellpadding="1" width="100%" id="table4">
<tr>
       <td bgcolor="#d7dee9" align="left"><font face="Arial">Product(s) Covered</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Quantity</font></td>      
</tr>
<tr>
       <apex:repeat value="{!Contract.Service_Contract_Line_Items__r}" var="line">
          <tr>
             <td align="left">{!line.Product_LU__r.name}</td>
             
             <td align="right">{!(ROUND(line.Quantity__c,0))}</td>
          </tr>
       </apex:repeat>  
</tr>
</table>
<br/><br/>

<table border="1" cellspacing="0" cellpadding="1" width="65%" id="table3">
<tr>
       <td bgcolor="#d7dee9" align="left"><font face="Arial">Please Note Our Remit To Address</font></td>
</tr>
<tr>
        <td><font face="Arial">
              Advanced Public Safety, Inc.<br/>
              PO Box 535208<br/>
              Atlanta, GA 30353-5208<br/><br/>
              Wire Instructions: Wells Fargo Bank<br/>
              ABA#: 121000248 Account #: 412-1360267

            </font>
        </td>

</tr>
</table>
<br/>


</apex:page>

 This is the class code:

public with sharing class PdfGeneratorController {

  String parentId = ApexPages.currentPage().getParameters().get('id');

  Contract c = [SELECT id, ContractNumber from Contract WHERE Id = :parentId];
  String ContractNumber = c.ContractNumber;

 public PageReference savePdf() {

    //PageReference pdf = Page.PdfGeneratorTemplate;
    PageReference pdf = Page.ContractPDFCreation;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',parentId);

    // create the new attachment
  Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = 'Invoice - ' + ContractNumber + '.pdf';  
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = parentId;
    insert attach; 


    // send the user to the account to view results
    return new PageReference('/'+parentId);
   
  }


}

 Please let me know how to pass the Contract.id into the first VF page properly so I can be done with this.

 

Thank you,

Steve Laycock

 

 

 

 

I'm working on a very old Salesforce instance that has been open until recently.

I have deleted every sharing rule in the enterprise wide sharing setting section.

I have adjusted every security profile in the system.

I have reworked every role in the heirarchy in the system.

But I am having huge issues eliminating the manually shared records to close the gap.

I need help using the dataloader or some other approach to eliminate the records that have been manually shared to groups like "All internal users" at the record level?

Please help me if you can I will give kudos to anyone that can get me across the finish line.

Thank you,
S
The code below has been slightly simplified for the sake of this post.  What I have incountered is that when I need to load more than 5 or 6 contracts each with multiple contract line items if I do a straight copy it loads well in bulk, but when I try to tie in the pricebookentry table (given the pricebook2id is a constant) to get the latest list price on a product I blow up the SOQL gov.

What I need is a way of tying in the Pricebookentry table without blowing up the SOQL governer.  Please help I will give kudos if you can help me resolve this issue.

Here is the code:

Trigger ContractTriggerCreatContractAndOLIs on Contract (after update)
{

    map<id, contract>  originalToCloneMap = new map<id, contract>(); 
    
    List<Contract> ContractsToClone = [Select id, Parent_Contract__c, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, 
            DateFinal__c,PrevNumberOfDays__c,
            PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c,
            SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate,
            Contract_End_Date__c, Case__c, RecordTypeId 
            from Contract where Status = 'Maintenance Paid' and Test_Contract_Clone__c = TRUE and Processed_Renewal_Contract__c = False and Id in :Trigger.newMap.keySet()];
    
    List<Contract> ContractsToInsert = new List<Contract>();
    Contract newContract = new Contract();
        
    List<Contract> ContractsToUpdate = new List<Contract>();
        
    for(Contract c: ContractsToClone)
    {
        c.Processed_Renewal_Contract__c = TRUE;
        ContractsToUpdate.add(c);
        
        cParentId = c.id;
        
        NewContract = new Contract();
         
        StartDate = c.StartDate;
        PrevStartDate = c.StartDate;
        PrevEndDate = c.Contract_End_Date__c;
        EndDate = c.Contract_End_Date__c;
        OriginalCase = c.Original_Case__c;
        MaintTermMisMatch = c.Maintenance_out_of_sync__c;
    
        PrevNumberOfDays = PrevStartDate.DaysBetween(PrevEndDate)+1;
      
        newContract.PrevNumberOfDays__c = PrevNumberOfDays;
        newContract.PrevStartDate__c = PrevStartDate;
        newContract.PrevEndDate__c = PrevEndDate;
        newContract.PrevNumberOfLeapYearDays__c = PrevNumberOfLeapYearDays;
    
        newContract.Months_between_start_and_end__c = c.StartDate.monthsBetween((c.Contract_End_Date__c +1));
              
        Integer count = 0;
               
               
        NumberOfDays = StartDate.DaysBetween(EndDate)+1;
        newContract.NewlyCreatedNumDays__c = NumberOfDays;
        NumberOfLeapYearDays = 0;
        Date CurrentDay;
        newContract.Contract_End_Date__c = c.Contract_End_Date__c.addDays((NumberOfDays));
        newContract.RecordTypeId = ServiceClass.getRecordTypesNameMap('Contract').get('Maintenance Contract').Id;
                
        newContract.SpecialTerms = c.SpecialTerms;
        newContract.Override_Total_Price__c = c.Override_Total_Price__c;
        newContract.Total_Maintenance_Price__c = c.Total_Maintenance_Price__c;
    
        newContract.StartDate = c.Contract_End_Date__c + 1;
        newContract.Attn_To__c = c.Attn_To__c;
        
        newContract.Original_Case__c = OriginalCase;
        newContract.Maintenance_out_of_sync__c = c.Maintenance_out_of_sync__c;
   
        NewContract.Status = 'Pending';
        NewContract.Accountid = c.AccountId;
        NewContract.RecordTypeId = c.RecordTypeId;
        NewContract.Parent_Contract__c = cParentId;
            
        originaltoCloneMap.put(c.id, NewContract);
        ContractsToInsert.add(NewContract);
    }
    
    Update ContractsToUpdate;
    Insert ContractsToInsert;
    
 
     
       Contract_Line_Item__c newCLI = new Contract_Line_Item__c();    
       
       List<Contract_Line_Item__c> CLIsToInsert = new List<Contract_Line_Item__c>();
 
       for(Contract_Line_Item__c cc :[Select Contract_Line_Item_Status__c, Contract__c, List_Price__c, Product_LU__c, Quantity__c, Account__c from Contract_Line_Item__c where Contract__c in :originalToCloneMap.keyset()])
        {
        
            newCLI = new Contract_Line_Item__c();
           
           newCLI.Contract__c = originaltoCloneMap.get(cc.Contract__c).id;
           newCLI.Contract_Line_Item_Status__c = 'Pending';
           newCLI.Product_LU__c = '01t7000000170yy';
           
          // PriceBookEntry cccc = [Select Id, UnitPrice from PriceBookEntry where Pricebook2Id = '01s3000000004T2' and Product2Id = : cc.Product_Lu__c Limit 1];
          // newCLI.List_Price__c = cccc.UnitPrice;
           newCLI.List_Price__c = cc.List_Price__c;
           newCLI.Product_LU__c = cc.Product_Lu__c;
           newCLI.Quantity__c = cc.Quantity__c;
           newCLI.Account__c = cc.Account__c;
           newCLI.Contract_Line_Item_Origin__c = 'Contract Clone Follow Up Contract';
                      if(cc.Contract_Line_Item_Status__c == 'Do Not Renew')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Do Not Renew';
                    }       
                    if(cc.Contract_Line_Item_Status__c == 'Cancelled')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Cancelled';
                    }  
            CLIsToInsert.add(newCLI);
            
        }   
         insert CLIsToInsert;    
}

Thank you,
S
I have the standard object Contract and a custom object that has a master detail relationship with called Contract_Line_Item__c.  I need to be able to load this code with a larger than 1 batch size.  My problem is I am used to using SOQL heavily, now I am trying to learn the more efficient approach that allows for bulk loading.

The problem I have is that I haven't been able to figure out how to load the child records due to the need of knowing the newly created parent id's.

Here is the code, please help me out if you can.  Thank you,

Trigger ContractTriggerCreatContractAndOLIs on Contract (after update)
{

    Date StartDate;
    Date EndDate;
    String cAccountid;
    String cContractId;
    String cParentId;
   
    List<Contract> ContractsToClone = [Select id, Parent_Contract__c, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, DateFinal__c,PrevNumberOfDays__c,
            PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c,
            SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate,
            Contract_End_Date__c, Case__c, RecordTypeId
            from Contract where Test_Contract_Clone__c = TRUE and Processed_Renewal_Contract__c = False and Id in :Trigger.newMap.keySet()];

   
    List<Contract> ContractsToInsert = new List<Contract>();
    Contract newContract = new Contract();

    for(Contract c: ContractsToClone)
    {
        NewContract = new Contract();
        NewContract.StartDate = Date.Today();
        NewContract.Contract_End_Date__c = Date.Today();
        NewContract.Status = 'Pending';
        NewContract.Accountid = c.AccountId;
        NewContract.RecordTypeId = c.RecordTypeId;
        NewContract.Parent_Contract__c = c.id;
        ContractsToInsert.add(NewContract);
    }
   
    Insert ContractsToInsert;
   
   
    
   List<Contract_Line_Item__c> CLIs = [Select Account__c, Contract__c, Product_LU__c, Quantity__c from Contract_Line_Item__c where Contract__c in :ContractsToInsert];

}
Public Class ContractFunctionsCloneContractAndOLIs
{

Public static void CloneMaintContractAndLineItems(Map<Id,Contract> oldMap, Map<Id,Contract> newMap)
      {
        List<Id> ContractToClone = new List<Id>();
        List<Id> ContractLineItemsToClone = new List<Id>();
       
        Date StartDate;
        Date EndDate;


       
      
        Integer NumberOfDays = 0;
        Integer NumberOfMonths = 0;
        Integer NumberOfYears = 0;
        Double YearTerm = 0;
        Integer NumberOfLeapYearDays = 0;
        Integer TermsByMonth = 0;
        Integer Prevcount =0;
       
        Boolean MaintTermMisMatch;
       
        String OriginalCase;
       
        Date CurrentDay;
        Date PrevCurrentDay;      

        Integer PrevNumberOfDays =0;
        Date PrevStartDate;
        Date PrevEndDate;
       
        Integer PrevNumberOfLeapYearDays =0;      
      
             
        for(Contract c : newMap.Values())
        {
            ContractToClone.add(c.Id);
      
        }

        
        for(Contract_Line_Item__c CLI :[Select id from Contract_Line_Item__c where Contract__c in :ContractToClone])
        {
            ContractLineItemsToClone.add(CLI.id);
        }
      
       Contract newContract = new Contract();
       
        if(ContractToClone.size() > 0 && ContractLineItemsToClone.size() > 0)
        {
            for(Contract c : [Select id, Status, Attn_To__c, Original_Case__c, Maintenance_out_of_sync__c, NewlyCreatedNumDays__c, DateFinal__c,PrevNumberOfDays__c, PrevStartDate__c, PrevEndDate__c, PrevNumberOfLeapYearDays__c, Term_In_Days__c, XNumberOfDays__c, AccountId, XNumberOfLeapYearDays__c, NumberOfLeapYearDays2__c, SpecialTerms, FEndDate__c, FCompareDayEndDate__c, Total_Maintenance_Price__c,Months_between_start_and_end__c,Override_Total_Price__c,StartDate, Contract_End_Date__c, Case__c, RecordTypeId from Contract where Id in :ContractToClone ])
            {

List<Contract> ContractsToInsert = new List<Contract>();
     

      
                newContract.Total_Maintenance_Price__c = c.Total_Maintenance_Price__c;
                newContract.Status = 'Pending';
                newContract.AccountId = c.AccountId;
                newContract.StartDate = c.Contract_End_Date__c + 1;
                newContract.RecordTypeId = ServiceClass.getRecordTypesNameMap('Contract').get('Maintenance Contract').Id;
                newContract.Parent_Contract__c = c.id;
               
                                            
                ContractsToInsert.add(newContract);
        insert(ContractsToInsert);  
       
         List<Contract_Line_Item__c> ContractLineItemsToInsert = new List<Contract_Line_Item__c>();
               
                String ContractId;
                String AccountId;
                String CaseId;
                String CLIStatus;
                           
            for(Contract insertedContracts : [Select Id, Case__c, AccountId from Contract where id in :ContractsToInsert])
            {
                ContractId = insertedContracts.id;
                AccountId = insertedContracts.AccountId;
                CaseId = insertedContracts.Case__c;
                CLIStatus = 'Pending';
               
               
               
                            }
            for(Contract_Line_Item__c cc : [Select id, Maintenance_Sales_Price__c, Contract_Line_Item_Status__c, Product_LU__c, Quantity__c, List_Price__c from Contract_Line_Item__c where Id in :ContractLineItemsToClone])
                {
                    Contract_Line_Item__c newCLI = new Contract_Line_Item__c();
                   
                   
                    newCLI.Contract_Line_Item_Status__c = CLIStatus;
                    newCLI.Contract__c = ContractId;
                    //newCLI.Case_Id__c = CaseId;
                    newCLI.Account__c = AccountId;
                    newCLI.Contract_Line_Item_Origin__c = 'Contract Clone Follow Up Contract';
                    newCLI.Product_LU__c = cc.Product_LU__c;
                    newCLI.Quantity__c = cc.Quantity__c;
                    newCLI.List_Price__c = cc.List_Price__c;    
                    newCLI.Maintenance_Sales_Price__c = cc.Maintenance_Sales_Price__c;
                    if(cc.Contract_Line_Item_Status__c == 'Do Not Renew')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Do Not Renew';
                    }        
                    if(cc.Contract_Line_Item_Status__c == 'Cancelled')
                    {
                         newCLI.Contract_Line_Item_Status__c = 'Cancelled';
                    }        
                    ContractLineItemsToInsert.add(newCLI);
                }
                insert(ContractLineItemsToInsert);
                update(ContractLineItemsToInsert);  
            }
       
       
          

      }}}

The following code compiles and then blows up on execution.  What I'm trying to do is filter out the lines that have a field Contract_Line_Item_Status__c = 'Do Not Renew'.

 

What ever I'm doing this VF page does not like the <apex:outputPanel tags.

 

Please let me know if you have any ideas on how to best resolve this.  Kudos to the person that helps me figure this one out.

 

<table border="1" style="border-color: #3B5E91" cellspacing="0" cellpadding="1" width="100%" id="table4">

<tr>
       <td bgcolor="#d7dee9" align="Left"><font face="Arial">Quantity</font></td>      
       <td bgcolor="#d7dee9" align="Center"><font face="Arial">APS Part No.</font></td>             
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Product(s) Covered</font></td>
</tr>
<tr>
    
       <apex:repeat value="{!Contract.Service_Contract_Line_Items__r}" var="line">
       <apex:outputPanel rendered="{!IF(line.Contract_Line_Item_Status__c = 'Do Not Renew',false,true)}">
       
          <tr>
             <td align="Right">{!(ROUND(line.Quantity__c,0))}</td>
             <td align="Center">{!line.APS_Part_Number__c}</td>

             <td align="Left">{!line.Product_LU__r.name}</td>
          </tr>
       </apex:outputPanel>
       </apex:repeat>  
    
</tr>
</table>

 

I have 2 loops that are causing some small problems.

 

In the code below you will note that I have two loops that hit the PriceBookEntry table (pbe1).  The first loop searches through out main production pricebook.  The second loop, loops through the PriceBookEntry table (pbe2) searching to find the productid in the standard pricebook.

 

The  PROBLEM:

 

When the first loop finds the productId I am looking for and grabs the listprice out of the main pricebook, it sometimes continues to loop through the second loop through the standard and then the update has two duplicate id's and blows to high hell and back.

 

Anyone that contributes will get kudos.

 

The person that gets me closest to the solution will get solution credit as well.

 

Here's the code:

 

public with sharing class MaintContractLineItemCreation 
{    
    Public static String ProductLineState = 'Not Found';
    Public static void ContractLineItemInsert(Map<Id,Contract_Line_Item__c> oldMap, Map<Id,Contract_Line_Item__c> newMap)
    {
    
    List<Id> CLIIds = new List<Id>();
    map<Id,String> CLIMap = new map <Id,String>(); 
    
    List<Id> Prodid = new List<Id>();
    
    List<id> PBE = new List<Id>();
    
    for (Contract_Line_Item__c c : newMap.Values())
    {   
        if(c.Product_LU__c != null)
        {      
             CLIIds.add(c.Id);
        }
    }
    
    for (Contract_Line_Item__c Prod : newMap.Values())
    {   
        if(Prod.Product_LU__c != null)
        {      
             Prodid.add(Prod.Product_LU__c);
        }
    }
    
    List<Contract_Line_Item__c> ContractLinesToUpdate = new List<Contract_Line_Item__c>();
    List<Contract_Line_Item__c> ContractLinesToUpdate1 = new List<Contract_Line_Item__c>();
    
    for(PriceBookEntry pbe1 :[Select id, UnitPrice, Pricebook2Id from PriceBookEntry where (Pricebook2id = '01s3000000001JS') and Product2id in :Prodid])
    
    {
                 
           
           for (Contract_Line_Item__c cli :[Select id, List_Price__c from Contract_Line_Item__c where id in :CLIIds])
           {
             ProductLineState = 'Not Found';
             if(pbe1.Pricebook2Id == '01s3000000001JS' && ProductLineState != 'Found' && pbe1.UnitPrice != null)
             {  
           
                cli.List_Price__c = pbe1.UnitPrice;
                ContractLinesToUpdate.add(cli);
                ProductLineState = 'Found'; 
                update(ContractLinesToUpdate);
             }
             }
    for(PriceBookEntry pbe2 :[Select id, UnitPrice, Pricebook2Id from PriceBookEntry where (Pricebook2id = '01s3000000004T2AAI') and Product2id in :Prodid])
    
    {
    for (Contract_Line_Item__c cli :[Select id, List_Price__c from Contract_Line_Item__c where List_Price__c = null and id in :CLIIds])
           {
             if(pbe2.Pricebook2Id == '01s3000000004T2AAI' && cli.List_Price__c == null &&  pbe1.UnitPrice != null)
                  {
                    cli.List_Price__c = pbe2.UnitPrice;
                    ContractLinesToUpdate.add(cli);
                    ProductLineState = 'Found'; 
                     update(ContractLinesToUpdate);
            }      }                 
           }  }
           
         }
        }

 Thank you,

Steve Laycock

I am working on a scenario to where a user can preview VF page and then save it to the Contract object in the notes and attachments section.

 

I'm using two visualforce pages and a class to do this.

 

The problem is that when I hardcode an actual Contract.id the whole thing works.  

 

But when I try to pass a parameter for the Contract.id the preview fails with the error: "Id value is not valid for the Contract standard controller".

 

This is the problem line of code:

 <iframe height="600px" id="Page" name="Maint Invoice" src="/apex/ContractPDFCreation?id=800S0000000rQfb" width="100%"></iframe>

 Below are the two VF pages and class.  Pleasse let me know what I can do to pass this parameter successfully???  I will give kudos and solution credit for the person who can get me through this.

 

The first VF page I call is called "PdfGeneratorTemplate".

 

This is how the first VF page is executed via a button:

https://cs1.salesforce.com/apex/PdfGeneratorTemplate?id={!Contract.Id}

 

Note the hardcoded Contract.id in the following code, this is what needs fixed:

<apex:page controller="PdfGeneratorController" >
   <apex:form >  

   <apex:pageBlock title="PDF Input">  

      <apex:pageBlockButtons >
        <apex:commandButton action="{!savePdf}" value="Save PDF"/>
       </apex:pageBlockButtons>
      <apex:pageMessages />

 <iframe height="600px" id="Page" name="Maint Invoice" src="/apex/ContractPDFCreation?id=800S0000000rQfb" width="100%"></iframe>

    </apex:pageBlock> 
  </apex:form>    

</apex:page>
               

 This is the main VF page that renders a pdf:

<apex:page standardController="Contract" showHeader="false" renderas="pdf">

<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td>
        <img src='{!URLFOR($Resource.APSLogoContract)}' title="logo" />
    </td>
    
    <td  align="center" style="font-size:20px;"><font face="Arial">
    <b>INVOICE</b></font>
    <table border="1" cellspacing="0" cellpadding="1" width="100%"  id="table77">
        <tr>
            <td bgcolor="#d7dee9">
                <font face="Arial"  style="font-size:13px;">Date: </font>
            </td>    
            <td>
                <font face="Arial" style="font-size:13px;">
                    <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                        <apex:param value="{!contract.WF_Invoice_Date__c}" /> 
                    </apex:outputText>
                
                </font>
            </td>
        </tr>
        <tr>
            <td bgcolor="#d7dee9">
                <font face="Arial"  style="font-size:13px;">Due: </font>
            </td>    
            <td>
                <font face="Arial" style="font-size:13px;">Due Upon Receipt</font>
            </td>
        </tr>    
    </table>     
    </td>
    

    
</tr>


</table>

<br/>

<table border="0" cellspacing="0" cellpadding="1" width="100%" id="table2">
<tr>
       <td colspan="2" style="font-size:13px;">
           <font face="Arial">BarbaraG@aps.us <br/><br/></font>
       </td>
</tr>
<tr>
       <td style="font-size:13px;">          
           <font face="Arial">Bill To:<br/><br/>
                             {!Contract.Account.Name}<br/>  
                             {!Contract.Account.BillingStreet}<br/>
                             {!Contract.Account.BillingCity}. {!Contract.Account.BillingState} {!Contract.Account.BillingPostalCode} 
           </font>
        </td>
        
        <td width="20%"></td>
        
        <td style="font-size:13px;">
           <font face="Arial">Ship To:<br/><br/>
                              {!Contract.Account.Name}<br/>
                              {!Contract.Account.ShippingStreet}<br/>
                              {!Contract.Account.ShippingCity}. {!Contract.Account.BillingState} {!Contract.Account.ShippingPostalCode}
           </font>
        </td>
</tr>    
</table>
<br/><br/><br/>


<table border="1" cellspacing="0" cellpadding="1" width="85%" id="table15">
<tr>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Contract Number</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Product</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Term</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Invoice Amount</font></td>
</tr>
<tr>
        <td align="center"><font face="Arial">
             {!Contract.ContractNumber}
            </font>
        </td>
        <td align="center"><font face="Arial">
             Maintenance
            </font>
        </td>
        <td align="center"><font face="Arial">
          <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                <apex:param value="{!contract.startdate}" /> 
          </apex:outputText>-<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
              <apex:param value="{!Contract.Contract_End_Date__c}" />
          </apex:outputText>
            </font>
        </td>
        <td align="center"><font face="Arial">
            <apex:outputText value="{0,number,$#,###,###.00}">
    <apex:param value="{!Contract.Total_Maintenance_Price__c}" />
  </apex:outputText>

            </font>
        </td>
</tr>



</table>
<br/><br/>

<table border="1" style="border-color: #3B5E91" cellspacing="0" cellpadding="1" width="100%" id="table4">
<tr>
       <td bgcolor="#d7dee9" align="left"><font face="Arial">Product(s) Covered</font></td>
       <td bgcolor="#d7dee9" align="center"><font face="Arial">Quantity</font></td>      
</tr>
<tr>
       <apex:repeat value="{!Contract.Service_Contract_Line_Items__r}" var="line">
          <tr>
             <td align="left">{!line.Product_LU__r.name}</td>
             
             <td align="right">{!(ROUND(line.Quantity__c,0))}</td>
          </tr>
       </apex:repeat>  
</tr>
</table>
<br/><br/>

<table border="1" cellspacing="0" cellpadding="1" width="65%" id="table3">
<tr>
       <td bgcolor="#d7dee9" align="left"><font face="Arial">Please Note Our Remit To Address</font></td>
</tr>
<tr>
        <td><font face="Arial">
              Advanced Public Safety, Inc.<br/>
              PO Box 535208<br/>
              Atlanta, GA 30353-5208<br/><br/>
              Wire Instructions: Wells Fargo Bank<br/>
              ABA#: 121000248 Account #: 412-1360267

            </font>
        </td>

</tr>
</table>
<br/>


</apex:page>

 This is the class code:

public with sharing class PdfGeneratorController {

  String parentId = ApexPages.currentPage().getParameters().get('id');

  Contract c = [SELECT id, ContractNumber from Contract WHERE Id = :parentId];
  String ContractNumber = c.ContractNumber;

 public PageReference savePdf() {

    //PageReference pdf = Page.PdfGeneratorTemplate;
    PageReference pdf = Page.ContractPDFCreation;
    // add parent id to the parameters for standardcontroller
    pdf.getParameters().put('id',parentId);

    // create the new attachment
  Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = 'Invoice - ' + ContractNumber + '.pdf';  
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = parentId;
    insert attach; 


    // send the user to the account to view results
    return new PageReference('/'+parentId);
   
  }


}

 Please let me know how to pass the Contract.id into the first VF page properly so I can be done with this.

 

Thank you,

Steve Laycock

 

 

 

 

I will give any who contribute kudos.

 

For the purposes of making this as simple as possible.  Lets work with the following hello world VF page renderas PDF.

 

What I need to know is how to attach the PDF that this creates and automatically save it to the contract's notes and attachment section.

 

The name will always be HelloWorld1 for the file that is saved to the attachments section.

 

<apex:page standardController="Contract"  
         showHeader="false" 
         sidebar="false" 
         renderAs="PDF"
         title="ContractPDF.pdf">
         <head>
             <title>ContractPDF.pdf</title>
         </head>
         <apex:outputText value="Hello World"/>
 </apex:page>

 Please let me know the simplest way of taking the above and inserting into the notes and attachments related list on the Contract object.

 

Thank you,

Steve Laycock

I have extended the standard Contract object so it now has a master detail relationship with an object called Contract_Line_Item__c which calculates maint and displays what is maint is being renewed on.

 

I also have a VisualForce page that renders a great PDF now that is properly formatted to display the needed data.

 

THE PROBLEM:

 

I need your help to figure out the best way via apex to have this PDF attach itself to....

 

1.  The contract itself,

2. An HTML email template and send it automatically to the customer/contact listed on the contract,

3. Lastly, the ability to have the PDF print automatically for snail mail purposes....

 

I will give kudos to anyone that contributes.

 

Thank you,

Steve Laycock

 

 

Hi everyone,

 

Our Company is using financial force accounting system, and I just wrote a trigger on the sales invoice object. Now when I wrote a test class for it, I use the code below:

 

c2g__CodaInvoice__c salesinvoice = new c2g__CodaInvoice__c();
//set values for the invoice
c2g__Opportunity__c = opp.id;
c2g__Account__c = acc.id;// opp and acc are already defined
...
... insert salesinvoice;

 But when I run the test, I always get an error message "no current company". Does anybody know what causes this error and how to get rid of it? Thanks a lot!!