• Dman100
  • NEWBIE
  • 15 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 144
    Questions
  • 147
    Replies

I am new to flex and had a couple of questions before diving in.  Currently, I use Eclipse to build Visualforce pages, apex classes and triggers.  If I am required to build external pages using the Salesforce API, I will develop the external pages using VisualStudio 2008 by compiling the enterprise wsdl into an assembly and creating aspx pages to build the external app.

 

I've built a pretty simple app in Visual Studio that handles a simple insert into a Salesforce custom object.  This works well.  Now, I'd like to try to incorporate flex.  As an example, I'd like to use a flex datagrid to display all the records in the custom oject, enable sorting and paging and editing capabilities.

 

Can flex be used with Visual Studio?  Can I build the flex apps in Eclipse and then integrated into an aspx page using Visual Studio?  I've looked at a couple of quick flex demos, but they use flex builder and I'm trying to get a handle on the possibilities using Eclipse/Visual Studio?

 

Also, I'm using Eclipse 3.3.2.

 

Thanks.

If a user has made a selection from a selectList, is there a way to display the selected value as the default?

 

Initially, when the user comes to the page, I have SelectOption set as follows:

 

options.add(new SelectOption('','-- Please select --')); for (string s : strSundays) { options.add(new SelectOption(s,s)); } return options;

 

Upon returning to the page for the specified record, I want to show the selected value as the default instead of '-- Please select --'

 

Here is the code used for the selection list:

 

VF code:

 

 

<apex:selectList multiselect="false" size="1" value="{!workweek}" > <apex:selectOptions value="{!items}" /> </apex:selectList>

 

Controller class code:

 

string workweek; public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); List<date> dates = getSundays(); List<string> strSundays = new List<string>(); for (date d: dates) { strSundays.add(string.valueof(d)); } options.add(new SelectOption('','-- Please select --')); for (string s : strSundays) { options.add(new SelectOption(s,s)); } return options; } public string getWorkWeek() { return workweek; } public void setWorkWeek(string workweek) { this.workweek = workweek; }

Thanks.

I have a date field in a custom object that I am going to populate from a visualforce page.

 

My method is as follows:

 

public date getStartDate() { date dtCurrentDate = date.today(); Integer i; date dtStartDate; i = dtCurrentDate.year(); string s = string.valueof('1/01/' + i); dtStartDate = date.parse(s); return dtStartDate; }

 

This displays my date on my visualforce page as:

 

1/01/09 12:00AM

 

How can I format to a shortdate as: 1/1/2009.  There is additional manipulation I will do to the date before inserting into the date field in my custom object, but I want to get the formatting to a shortdate without the time.

I have a trigger that occasionally throws an error due to a validation rule.  I have a try/catch block in my trigger, but the validation rule isn't caught in the catch block.  Is there a way to gracefully handle the error thrown by the validation rule when the trigger fires?

 

If there is no way to trap for the validation rule errors in a trigger, can anyone explain why?  Currently, a big red apex error message is generated, which is not very user friendly to the end-user.  I'm just trying to handle the error gracefully, if possible.

 

Thanks for any help.

Message Edited by Dman100 on 12-10-2009 11:27 AM

I want a pop-up with an informational message when a user closes an opportunity to make it an account.  So, I can create an s-control that has an alert().

 

<html> <head> <script> var result = "{!Opportunity.StageName}"; function init() { if (result == "Closed") { alert("My message goes here."); } } </script> </head> <body onload="init()"> </body> </html>

 

Can I use the merge field syntax to obtain the stage name of the opportunity being edited as I'm using above in the s-control?

 

In order to call this s-control, I would need to override the edit button on the opportunity in the buttons and links section, is that correct?

 

Thanks.

I've written a trigger that works perfectly after inserts and after updates.  The problem is after delete which can only use Trigger.old.

 

The trigger fires on the OpportunityLineItem and sets a value on the opportunity when a line item is inserted or updated.  I want to add the same process to fire when a line item is deleted, so the field value on the opportunity is updated correctly.

 

I've tried using if (Trigger.IsDelete) and looking at the trigger old values, but the obvious problem is it is still looking at the old values and not the new values that no longer includes the deleted line item.

 

For example, the trigger sets a value on the opportunity based on specific criteria defined by precedence (which criteria occurs first).  If that line item is deleted, then all the line items need to be iterated again to set the appropriate value on the opportunity (what is the new criteria that occurs first) after the line item has been deleted.

 

Is there a way to make this happen in the trigger?  It would seem, that I need to re-fire the  trigger after a line item has been deleted, so that I can examine the new line items after the delete occurred.

 

Is it possible to do this thru a workflow maybe?

 

Here is my existing trigger without the after delete:

 

trigger OpportunityLineItemVertical on OpportunityLineItem (after insert, after update) { OpportunityLineItem oli = [Select Opportunity.Id, Opportunity.Account.Id From OpportunityLineItem Where Id in :Trigger.new Limit 1]; List<OpportunityLineItem> olis = [Select Id, PricebookEntry.Product2.Name, PricebookEntry.Product2.Product_Line__c From OpportunityLineItem Where OpportunityId = :oli.Opportunity.Id]; for (OpportunityLineItem x : olis) { system.debug('Name = ' + x.PricebookEntry.Product2.Name); system.debug('Product Line = ' + x.PricebookEntry.Product2.Product_Line__c); } system.debug('Opportunity Id = ' + oli.Opportunity.Id); system.debug('Account Id = ' + oli.Opportunity.Account.Id); List<Id> pbeIds = new List<Id>(); for (Integer i = 0; i < Trigger.size; i++) { pbeIds.add(Trigger.new[i].PricebookEntryId); } for (Id i : pbeIds) { system.debug('Pricebook Entry Ids = ' + pbeIds); } List<PricebookEntry> pbes = [Select Product2Id From PricebookEntry Where Id in :pbeIds]; List<Id> prodIds = new List<Id>(); for (PricebookEntry pbe : pbes) { prodIds.add(pbe.Product2Id); } for (Id i : prodIds) { system.debug('Product Ids = ' + prodIds); } List<Product2> products = [Select Name, Product_Line__c From Product2 Where Id in :prodIds]; Account acct = [Select Local_Region__c, Market_Segment__c, Industry From Account Where Id = :oli.Opportunity.Account.Id]; Opportunity op = [Select OwnerId From Opportunity Where Id = :oli.Opportunity.Id]; system.debug('Owner Id = ' + op.OwnerId); User u = [Select ProfileId From User Where Id = :op.OwnerId]; system.debug('Profile Id = ' + u.ProfileId); Profile p = [Select Name From Profile Where Id = :u.ProfileId]; Boolean foundMarketplace = false; Boolean foundTeleAtlas = false; Boolean foundStoreSystems = false; Boolean foundLogisticsMgmt = false; try { for (OpportunityLineItem oppLine : Trigger.new) { for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Name == 'JDA Marketplace Replenish') { FoundMarketPlace = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Name == 'Tele Atlas') { foundTeleAtlas = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Product_Line__c == 'Store Operations') { foundStoreSystems = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Product_Line__c == 'Logistics Management') { foundLogisticsMgmt = true; } } if (p.Name.contains('Alliance')) { op.JDA_Vertical__c = 'VAR'; update op; break; } else if (acct.Local_Region__c != null && acct.Local_Region__c.contains('Latin America')) { op.JDA_Vertical__c = 'Latin America'; update op; break; } else if (foundMarketplace) { op.JDA_Vertical__c = 'Marketplace'; update op; break; } else if (foundTeleAtlas) { op.JDA_Vertical__c = 'Transportation'; update op; break; } else if (foundStoreSystems) { op.JDA_Vertical__c = 'Store Systems'; update op; break; } else if (foundLogisticsMgmt) { op.JDA_Vertical__c = 'Transportation'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.startsWith('Grocery')) { op.JDA_Vertical__c = 'Grocery/Drug'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.contains('Hardlines')) { op.JDA_Vertical__c = 'Retail Hardlines'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.contains('Softlines')) { op.JDA_Vertical__c = 'Retail Softlines'; update op; break; } else if (acct.Industry != null && acct.Industry == 'Manufacturing') { op.JDA_Vertical__c = 'Consumer Goods'; update op; break; } else if (acct.Industry != null && acct.Industry == 'Wholesale/Distribution') { op.JDA_Vertical__c = 'Wholesale/Distribution'; update op; break; } else { op.JDA_Vertical__c = 'Unknown'; update op; break; } } } catch (Exception ex) { Opportunity opp = [Select Error_Message__c From Opportunity Where Id = :oli.Opportunity.Id]; opp.Error_Message__c = ex.GetMessage(); update opp; return; } }

 

I have written a test method for my trigger, but the assertion fails:

 

assertion Failed: Expected: VAR, Actual: null

 

I have checked and re-checked my test method to verify the correct values.  I don't see why the value is null.  I've manually gone into the opportunity records that should be getting updated and tested the actual trigger on them and the value is correctly set.  So, I'm not sure why the test is failing.  I was hoping another pair of eyes could spot the problem.

 

Here is my trigger code:

 

trigger OpportunityLineItemVertical on OpportunityLineItem (after insert, after update) { OpportunityLineItem oli = [Select Opportunity.Id, Opportunity.Account.Id From OpportunityLineItem Where Id in :Trigger.new Limit 1]; List<OpportunityLineItem> olis = [Select Id, PricebookEntry.Product2.Name, PricebookEntry.Product2.Product_Line__c From OpportunityLineItem Where OpportunityId = :oli.Opportunity.Id]; for (OpportunityLineItem x : olis) { system.debug('Name = ' + x.PricebookEntry.Product2.Name); system.debug('Product Line = ' + x.PricebookEntry.Product2.Product_Line__c); } system.debug('Opportunity Id = ' + oli.Opportunity.Id); system.debug('Account Id = ' + oli.Opportunity.Account.Id); List<Id> pbeIds = new List<Id>(); for (Integer i = 0; i < Trigger.size; i++) { pbeIds.add(Trigger.new[i].PricebookEntryId); } for (Id i : pbeIds) { system.debug('Pricebook Entry Ids = ' + pbeIds); } List<PricebookEntry> pbes = [Select Product2Id From PricebookEntry Where Id in :pbeIds]; List<Id> prodIds = new List<Id>(); for (PricebookEntry pbe : pbes) { prodIds.add(pbe.Product2Id); } for (Id i : prodIds) { system.debug('Product Ids = ' + prodIds); } List<Product2> products = [Select Name, Product_Line__c From Product2 Where Id in :prodIds]; Account acct = [Select Local_Region__c, Market_Segment__c, Industry From Account Where Id = :oli.Opportunity.Account.Id]; Opportunity op = [Select OwnerId From Opportunity Where Id = :oli.Opportunity.Id]; system.debug('Owner Id = ' + op.OwnerId); User u = [Select ProfileId From User Where Id = :op.OwnerId]; system.debug('Profile Id = ' + u.ProfileId); Profile p = [Select Name From Profile Where Id = :u.ProfileId]; Boolean foundMarketplace = false; Boolean foundTeleAtlas = false; Boolean foundStoreSystems = false; Boolean foundLogisticsMgmt = false; try { for (OpportunityLineItem oppLine : Trigger.new) { for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Name == 'JDA Marketplace Replenish') { FoundMarketPlace = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Name == 'Tele Atlas') { foundTeleAtlas = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Product_Line__c == 'Store Operations') { foundStoreSystems = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Product_Line__c == 'Logistics Management') { foundLogisticsMgmt = true; } } if (p.Name.contains('Alliance')) { op.JDA_Vertical__c = 'VAR'; update op; break; } else if (acct.Local_Region__c != null && acct.Local_Region__c.contains('Latin America')) { op.JDA_Vertical__c = 'Latin America'; update op; break; } else if (foundMarketplace) { op.JDA_Vertical__c = 'Marketplace'; update op; break; } else if (foundTeleAtlas) { op.JDA_Vertical__c = 'Transportation'; update op; break; } else if (foundStoreSystems) { op.JDA_Vertical__c = 'Store Systems'; update op; break; } else if (foundLogisticsMgmt) { op.JDA_Vertical__c = 'Transportation'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.startsWith('Grocery')) { op.JDA_Vertical__c = 'Grocery/Drug'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.contains('Hardlines')) { op.JDA_Vertical__c = 'Retail Hardlines'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.contains('Softlines')) { op.JDA_Vertical__c = 'Retail Softlines'; update op; break; } else if (acct.Industry != null && acct.Industry == 'Manufacturing') { op.JDA_Vertical__c = 'Consumer Goods'; update op; break; } else if (acct.Industry != null && acct.Industry == 'Wholesale/Distribution') { op.JDA_Vertical__c = 'Wholesale/Distribution'; update op; break; } else { op.JDA_Vertical__c = 'Unknown'; update op; break; } } } catch (Exception ex) { Opportunity opp = [Select Error_Message__c From Opportunity Where Id = :oli.Opportunity.Id]; opp.Error_Message__c = ex.GetMessage(); update opp; return; } }

 

Here is my unit test:

 

public class testOpportunityLineItemVertical { static testMethod void test_OpportunityLineItemVertical() { Profile p = [Select Id From Profile Where Name = 'JDA Alliance User']; system.debug('Profile Id = ' + p.Id); List<User> users = [Select Id From User Where ProfileId = :p.Id]; List<Id> userIds = new List<Id>(); for (User u : users) { userIds.add(u.Id); } system.debug('User Ids = ' + userIds); List<Opportunity> opps = [Select Id, JDA_Vertical__c From Opportunity Where OwnerId in :userIds AND Product_Lines__c > 0 AND StageName = 'Open']; List<Id> oppIds = new List<Id>(); for (Opportunity o : opps) { oppIds.add(o.Id); } system.debug('Opportunity Ids = ' + oppIds); List<OpportunityLineItem> olis = [Select Id, Quantity From OpportunityLineItem Where OpportunityId in :oppIds]; List<OpportunityLineItem> test1 = new List<OpportunityLineItem>(); for (OpportunityLineItem oli : olis) { oli.Quantity = 1; test1.add(oli); } update test1; for (Opportunity op : opps) { System.AssertEquals('VAR', op.JDA_Vertical__c); } } }

 

Thanks for any help.

Is it possible to create a validation rule that only allows a user with a specific profile to close a custom object record when a custom field equals a specific value?

 

For example, only allow the profile installation to close custom object engagements records when qualification equals install.  Is this possible?

 

If not thru a validation rule, is there another way to accomplish this?

 

Thanks.

I'm trying to debug an old s-control that has been working fine, but recently encountered an error.

 

Here is the s-control code:

 

<html> <head> <script type="text/javascript" src="/js/functions.js"></script> <script src="/soap/ajax/12.0/connection.js"></script> <script language="javascript1.2" type="text/javascript"> // Update Related Records function updateRelatedRecords() { //Get Records - Contact Roles for Account var AccountId = "{!Account.Id}"; var ParentId="{!Account.ParentId}"; var childAccounts; var parentContactRoles; var childContactRoles; var hasParentContactRoles = false; var hasChildAccounts = false; var strSQL; var result; //If the Account is a child Account which means it has ParentId then //nothing should happen if(ParentId != ''){ alert("This is a child Account"); } else { strSQL="Select Id, AccountId,Role,ContactID From AccountContactRole where AccountId='{!Account.Id}'"; result = sforce.connection.query(strSQL); parentContactRoles = result.getArray("records"); //If the Parent Account has no Contact Roles then it should //not do anything No update or insert to anything not even Child records if(parentContactRoles.length==0){ alert("There are no Contact Roles for this Account '{!Account.Name}'"); } else { hasParentContactRoles = true; } //If the Parent Account has no child Accounts then //do not do anything either strSQL="Select Id,Name from Account where ParentId='{!Account.Id}'"; result = sforce.connection.query(strSQL); childAccounts = result.getArray("records"); if(childAccounts.length==0){ alert("There are no child Accounts for '{!Account.Name}'"); } else { hasChildAccounts = true; } if(hasParentContactRoles && hasChildAccounts){ var newContactRoles = []; var contactRoleExists = false; var i,j,k; for (i in childAccounts){ //Get Contacts Roles for each child account strSQL="Select Id, AccountId, Role, ContactId From AccountContactRole where AccountId=" + "'" + childAccounts[i].Id + "'"; result = sforce.connection.query(strSQL); childContactRoles = result.getArray("records"); for(j in parentContactRoles){ contactRoleExists = false; for(k in childContactRoles){ if(parentContactRoles[j].Role == childContactRoles[k].Role) {contactRoleExists = true;} } if(!contactRoleExists){ var newContactRole = new sforce.SObject("AccountContactRole"); newContactRole.AccountId = childAccounts[i].Id; newContactRole.ContactId = parentContactRoles[j].ContactId; newContactRole.Role = parentContactRoles[j].Role; newContactRoles.push(newContactRole); } } } if(newContactRoles.length > 0){ result = sforce.connection.create(newContactRoles); document.write(newContactRoles.length + " new Contact Roles were created in child accounts."); } else { document.write("No Contact Roles assigned. All child accounts already have all roles defined."); } } } } </script> </head> <body onload="updateRelatedRecords()";> </body> </html>

 

I believe, the s-control is erroring out when it gets to this section:

 

 

for (i in childAccounts){ //Get Contacts Roles for each child account strSQL="Select Id, AccountId, Role, ContactId From AccountContactRole where AccountId=" + "'" + childAccounts[i].Id + "'"; result = sforce.connection.query(strSQL); childContactRoles = result.getArray("records");

 

 

I just get a blank window that opens and it just times out and nothing happens.  No errors, but the s-control does not update the child accounts.

 

This only happens with one account.  The s-control has been working fine.  It seems like a governor limit issue?

 

I'm not overly proficient with javascript.  Is there a way I can display the error and see what is happening?  If it is a governor limit issue, is there a way to get around the limit?

 

Thanks for any help.

I'm writing my unit test code for my custom controller and I've gotten to 70%, but I'm missing coverage on my three sections of my class file that include ApexPages.Message.  Can anyone advise on how I can cover this code?

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctFrom = new Account(); private Account acctTo = new Account(); private Account acctToByParent = new Account(); private Account parentAcct = new Account(); private Account acctToByState = new Account(); private Account state = new Account(); public AccountMaintenanceController() { } public PageReference ChildAccountOwnershipCount() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; ChildAccountCount = [Select Count() From Account where ParentId =: parent.Id]; ChildAccountCount += ChildAccountCount + 1; lblChildAccounts = true; btnChildAccounts = true; return null; } public PageReference updateChildAccountOwnership() { try { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByParent.OwnerId = null; parentAcct.parentId = null; lblChildAccounts = false; btnChildAccounts = false; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public PageReference StateAccountOwnershipCount() { StateAccountCount = [Select Count() From Account where state__c =: state.state__c]; lblStateAccounts = true; btnStateAccounts = true; return null; } public PageReference AccountOpportunityOwnershipCount() { if (acctChkbox) { AccountCount = [Select Count() From Account where ownerId =: acctFrom.ownerId]; } else { AccountCount = 0; } if (oppyChkbox) { OpportunityCount = [Select Count() From Opportunity where ownerId =: acctFrom.ownerId AND stagename <> 'Closed Lost']; } else { OpportunityCount = 0; } if (oppyEmailChkbox) { CommissionSalespersonCount = [Select Count() From Opportunity where ownerId =: acctFrom.ownerId AND stagename <> 'Closed Lost']; } else { CommissionSalespersonCount = 0; } lblAccountsOpportunities = true; btnAccountsOpportunities = true; return null; } public PageReference updateAccountByState() { try { List<Account> accts = [Select Id, OwnerId From Account where state__c =: state.state__c]; List<Account> lst = new List<Account>(); for (Account acct: accts) { acct.OwnerId = acctToByState.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByState.ownerId = null; state.state__c = null; lblStateAccounts = false; btnStateAccounts = false; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public void updateAccountOwnership() { for (List<Account> acctsFrom : [Select Id, OwnerId From Account where ownerId =: acctFrom.ownerId]) { for (Account acct: acctsFrom) { acct.OwnerId = acctTo.OwnerId; } update acctsFrom; } } public void updateOpportunityOwnership() { for (List<Opportunity> oppys : [Select Id, OwnerId From Opportunity where ownerId =: acctFrom.ownerId AND stagename <> 'Closed Lost']) { for (Opportunity op: oppys) { op.OwnerId = acctTo.ownerId; } update oppys; } } public void updateCommissionSalesperson() { for (List<Opportunity> oppys : [Select Id, OwnerId From Opportunity where ownerId =: acctFrom.ownerId AND stagename <> 'Closed Lost']) { for (Opportunity op: oppys) { op.Commission_Salesperson__c = acctTo.ownerId; } update oppys; } } public PageReference updateAccountsOpportunities() { try { if (acctChkbox) { updateAccountOwnership(); } if (oppyChkbox) { updateOpportunityOwnership(); } if (oppyEmailChkbox) { updateCommissionSalesperson(); } ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Records updated successfully.'); ApexPages.addMessage(msg); acctFrom.ownerId = null; acctTo.ownerId = null; acctChkbox = false; oppyChkbox = false; oppyEmailChkbox = false; lblAccountsOpportunities = false; btnAccountsOpportunities = false; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountFrom() { return acctFrom; } public Account getAccountTo() { return acctTo; } public Boolean acctChkbox { get; set; } public Boolean oppyChkbox { get; set; } public Boolean oppyEmailChkbox { get; set; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } public Account getAccountToByState() { return acctToByState; } public Account getState() { return state; } public Integer ChildAccountCount { get; set; } public Integer StateAccountCount { get; set; } public Integer AccountCount { get; set; } public Integer OpportunityCount { get; set; } public Integer CommissionSalespersonCount { get; set; } public Boolean lblChildAccounts { get; set; } public Boolean lblStateAccounts { get; set; } public Boolean lblAccountsOpportunities { get; set; } public Boolean btnChildAccounts { get; set; } public Boolean btnStateAccounts { get; set; } public Boolean btnAccountsOpportunities { get; set; } static testMethod void test() { Account district = TestUtil.getTestAccount(); DbUtil.save(district); Account account = TestUtil.getTestAccount(); DbUtil.save(account); List<Account> accts = TestUtil.getTestAccounts(5); DbUtil.save(accts); Opportunity opp = TestUtil.getTestOppy(district.Id, district.ownerId); List<Account> children = new List<Account>(); for (Account acct: accts) { acct.parentId = district.Id; children.add(acct); } update children; // Create the controller AccountMaintenanceController Ctrl = new AccountMaintenanceController(); // Set properties Ctrl.acctToByParent.ownerId = district.ownerId; Ctrl.parentAcct.parentId = district.Id; Ctrl.acctToByState.ownerId = district.ownerId; Ctrl.state.state__c = 'TX'; Ctrl.acctFrom.ownerId = district.ownerId; Ctrl.acctTo.ownerId = account.ownerId; Ctrl.acctChkbox = true; Ctrl.oppyChkbox = true; Ctrl.oppyEmailChkbox = true; Ctrl.lblChildAccounts = true; Ctrl.lblStateAccounts = true; Ctrl.lblAccountsOpportunities = true; Ctrl.btnChildAccounts = true; Ctrl.btnStateAccounts = true; Ctrl.btnAccountsOpportunities = true; //Call methods Ctrl.ChildAccountOwnershipCount(); Ctrl.updateChildAccountOwnership(); Ctrl.StateAccountOwnershipCount(); Ctrl.updateAccountByState(); Ctrl.updateAccountOwnership(); Ctrl.updateOpportunityOwnership(); Ctrl.updateCommissionSalesperson(); Ctrl.AccountOpportunityOwnershipCount(); Ctrl.updateAccountsOpportunities(); // Create the controller AccountMaintenanceController Ctrl2 = new AccountMaintenanceController(); // Set properties Ctrl2.acctFrom.ownerId = district.ownerId; Ctrl2.acctTo.ownerId = account.ownerId; Ctrl2.acctChkbox = false; Ctrl2.oppyChkbox = true; Ctrl2.oppyEmailChkbox = true; //Call methods Ctrl2.updateAccountOwnership(); Ctrl2.updateOpportunityOwnership(); Ctrl2.updateCommissionSalesperson(); Ctrl2.AccountOpportunityOwnershipCount(); Ctrl2.updateAccountsOpportunities(); // Create the controller AccountMaintenanceController Ctrl3 = new AccountMaintenanceController(); // Set properties Ctrl3.acctFrom.ownerId = district.ownerId; Ctrl3.acctTo.ownerId = account.ownerId; Ctrl3.acctChkbox = true; Ctrl3.oppyChkbox = false; Ctrl3.oppyEmailChkbox = true; //Call methods Ctrl3.updateAccountOwnership(); Ctrl3.updateOpportunityOwnership(); Ctrl3.updateCommissionSalesperson(); Ctrl3.AccountOpportunityOwnershipCount(); Ctrl3.updateAccountsOpportunities(); // Create the controller AccountMaintenanceController Ctrl4 = new AccountMaintenanceController(); // Set properties Ctrl4.acctFrom.ownerId = district.ownerId; Ctrl4.acctTo.ownerId = account.ownerId; Ctrl4.acctChkbox = true; Ctrl4.oppyChkbox = true; Ctrl4.oppyEmailChkbox = false; //Call methods Ctrl4.updateAccountOwnership(); Ctrl4.updateOpportunityOwnership(); Ctrl4.updateCommissionSalesperson(); Ctrl4.AccountOpportunityOwnershipCount(); Ctrl4.updateAccountsOpportunities(); } }

 

Here are the sections that are not covered:

 

39 0 List<Account> lst = new List<Account>(); 40 0 for (Account acct: childAccts) 41 { 42 0 acct.OwnerId = acctToByParent.OwnerId; 43 0 lst.add(acct); 44 } 45 0 DbUtil.save(lst); 46 47 0 ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); 48 0 ApexPages.addMessage(msg); 49 50 0 acctToByParent.OwnerId = null; 51 0 parentAcct.parentId = null; 52 53 0 lblChildAccounts = false; 54 55 0 btnChildAccounts = false; 56 57 0 return null; ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); 128 0 ApexPages.addMessage(msg); 129 130 0 acctToByState.ownerId = null; 131 0 state.state__c = null; 132 133 0 lblStateAccounts = false; 134 135 0 btnStateAccounts = false; 136 137 0 return null; catch (Exception ex) 216 0 { 217 0 ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); 218 0 ApexPages.addMessage(errMsg); 219 0 return null; 220 } 221 } 222 223 0 public PageReference cancel() { 224 0 PageReference newpage = new PageReference(System.currentPageReference().getURL()); 225 0 newpage.setRedirect(true); 226 0 return newpage; 227 }

 

 

Thanks for any help.

I have a two pageBlocks and I want to display the second pageBlock after the command button the first pageBlock is fired.

 

I created a boolean public property in my controller:

 

public Boolean IsShown{ get; set; }

 

I set the property in my method:

 

public PageReference ChildAccountOwnershipCount() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; ChildAccountCount = [Select Count() From Account where ParentId =: parent.Id]; ChildAccountCount += ChildAccountCount + 1; IsShown = true; return null; }

 

 

Here is my VF code:

 

<apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit" id="ChildAccountsPageBlock"> <apex:pageBlockButtons > <apex:commandButton action="{!ChildAccountOwnershipCount}" value="Update" rerender="ChildAccountsPageBlock, Msg, ChildAccountConfirmPageBlock" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock id="ChildAccountConfirmPageBlock" rendered="{!IsShown}" > <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Confirm" rerender="ChildAccountsPageBlock, Msg" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection > <apex:outputLabel value="You are about to update {!ChildAccountCount} accounts. Please click to confirm." /> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion>

 

 

 

The second pageBlock does not open when the page posts back?

 

Thanks.

I need some help and guidance writing a unit test for a custom controller I've created.

 

public class AccountMaintenanceController { private Account acctToByParent = new Account(); private Account parentAcct = new Account(); public AccountMaintenanceController() { } public PageReference updateChildAccountOwnership() { try { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByParent.OwnerId = null; parentAcct.parentId = null; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } static testMethod void test() { } }

 

Sorry for the novice questions, but how do I set the property values in the test method and how do I call the method?

 

Thanks for any help.

I have updated my controller to include an Integer property:

 

public Integer ChildAccountCount { get; set; }

 

Then I set the property in my method:

 

 

public PageReference updateChildAccountOwnership() { try { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; ChildAccountCount = [Select Count() From Account where ParentId =: parent.Id]; ChildAccountCount += ChildAccountCount + 1; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByParent.OwnerId = null; parentAcct.parentId = null; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } }

 

 

In my VF page, I have a command button that calls the above method:

 

<apex:commandButton action="{!updateChildAccountOwnership}" value="Update" status="ChildAccountsLoadingStatus" rerender="ChildAccountsPageBlock, Msg" onclick="if (!confirmation()) return false;" />

 

 

I have a confirm dialog that opens before the update processes, which is where I want to display the property value.

 

I was trying to get the property value using the following method:

 

<apex:outputLabel value="{!ChildAccountCount}" id="theCount" /> <script> var total = document.getElementById('{!$Component.theCount}').value;</script>

 

The problem appears to be that the property value is not set when the confirm dialog is executed.  I want to show how many records are going to be updated before processing the update.

 

Any ideas?  It seems like I'm close, but can't get the value until after the user confirms and then the update processes and the property is set.

Message Edited by Dman100 on 10-19-2009 07:43 PM

I'm trying to display a confirm dialog to the user before executing an update.

 

I've tried the following:

 

<apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg, AccountMaintenance" status="AccountsOpportunitiesLoadingStatus" onclick="return confirm('Are you sure you want to update the following records?')" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons>

 

I discovered that I could process the update with the confirmation dialog using the actionFunction tag.  However, it causing some other problems.

 

I have three pageBlock sections wrapped in actionRegion tags, so that each pageBlock section will validate and process independently.

 

Once I added the actionFunction tag, the actionRegion no longer functions correctly.  When the page posts back, all three pageBlock sections validate.

 

Here is my VF code:

 

<apex:page Controller="AccountMaintenanceController"> <script> function confirmation() { var answer = confirm('Are you sure you want to update the following records?'); if (answer) { doSave(); } else { return false; } } </script> <h1>Manage Salesperson Territory Assignments</h1> <apex:form id="AccountMaintenance"> <apex:actionRegion > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg, AccountMaintenance" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton value="Update" onclick="confirmation();" /> <apex:actionFunction name="doSave" action="{!updateChildAccountOwnership}" rerender="UpdateChildAccountsSuccessMsg, AccountMaintenance" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageMessages rendered="true" id="UpdateChildAccountsSuccessMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock title="Update Account Ownership by State" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountByState}" value="Update" rerender="UpdateOwnerByStateSuccessMsg, AccountMaintenance" status="StateLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateOwnerByStateSuccessMsg" /> <apex:actionStatus id="StateLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to update owner of accounts by selected state" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByState.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="State" for="state" /> <apex:inputField value="{!State.State__c}" id="state" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> </apex:form> </apex:page>

 

 

Thanks for any help.

Message Edited by Dman100 on 10-17-2009 09:52 PM

I have a inputCheckbox and when the page posts back, the checkbox field is not getting set when the checkbox is selected.  I have a boolean property defined in the controller.  I'm not sure what I'm missing?

 

here is the VF code:

 

<apex:page Controller="AccountMaintenanceController"> <apex:form > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:outputLabel value="{!acctChkbox}" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctFrom = new Account(); private Account acctTo = new Account(); public PageReference updateAccountsOpportunities() { //List<Account> acctsFrom = [Select Id, OwnerId From Account where ownerId =: acctFrom.ownerId]; //List<Opportunity> oppys = [Select Id, OwnerId From Opportunity where ownerId =: acctFrom.ownerId]; //List<Account> acctsToUpdate = new List<Account>(); //for (Account acct: acctsFrom) //{ //acct.OwnerId = acctTo.OwnerId; //acctsToUpdate.add(acct); //} //if (acctChkbox == true) //{ //DbUtil.save(acctsToUpdate); //} //List<Opportunity> oppysToUpdate = new List<Opportunity>(); //for (Opportunity op: oppys) //{ //op.OwnerId = acctTo.ownerId; //oppysToUpdate.add(op); //} //if (oppyChkbox == true) //{ //DbUtil.save(oppysToUpdate); //} //List<Opportunity> oppysCommissionSalespersonToUpdate = new List<Opportunity>(); //for (Opportunity op: oppys) //{ //op.Commission_Salesperson__c = acctTo.ownerId; //oppysCommissionSalespersonToUpdate.add(op); //} //if (oppyEmailChkbox == true) //{ //DbUtil.save(oppysCommissionSalespersonToUpdate); //} //ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Records updated successfully.'); //ApexPages.addMessage(msg); //PageReference pr = System.Page.AccountMaintenance; //pr.setRedirect(true); //return pr; return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountFrom() { return acctFrom; } public Account getAccountTo() { return acctTo; } public Boolean acctChkbox { get { if (acctChkbox == null) { acctChkbox = false; } return acctChkbox; } set; } public Boolean oppyChkbox { get { if (oppyChkbox == null) { oppyChkbox = false; } return oppyChkbox; } set; } public Boolean oppyEmailChkbox { get { if (oppyEmailChkbox == null) { oppyEmailChkbox = false; } return oppyEmailChkbox; } set; } }

 

 

Thanks for any help.

I have a VF page that includes two pageBlock sections that call update methods.  Is it possible to validate only the pageBlock section where the update method is getting executed?

 

Here is my VF code:

 

<apex:page Controller="AccountMaintenanceController"> <h1>Manage Salesperson Territory Assignments</h1> <apex:form > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Update" rerender="UpdateChildAccountsSuccessMsg" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateChildAccountsSuccessMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Update Account Ownership by State" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountByState}" value="Update" rerender="UpdateOwnerByStateSuccessMsg" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateOwnerByStateSuccessMsg" /> <apex:pageBlockSection title="Used to update owner of accounts by selected state" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByState.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="State" for="state" /> <apex:inputField value="{!State.State__c}" id="state" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

controller class:

 

public class AccountMaintenanceController { private Account acctToByParent = new Account(); private Account parentAcct = new Account(); private Account acctToByState = new Account(); private Account state = new Account(); public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); return null; } public PageReference updateAccountByState() { List<Account> accts = [Select Id, OwnerId From Account where state__c =: state.state__c]; List<Account> lst = new List<Account>(); for (Account acct: accts) { acct.OwnerId = acctToByState.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } public Account getAccountToByState() { return acctToByState; } public Account getState() { return state; }

 

 

So, when I click the update button in either one of the pageBlock sections, it validates both pageBlock sections, so I cannot execute the update methods in the pageBlock sections independently.

 

Thanks for any help.

How do I clear the inputfields after an update?

 

here is my VF page:

 

<apex:page Controller="AccountMaintenanceController"> <h1>Manage Salesperson Territory Assignments</h1> <apex:form > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Update" rerender="successMsg" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="successMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctToByParent = new Account(); private Account parentAcct = new Account(); public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } }

 

 

I've tried setting the private fields to an empty string, but that did not work.

 

Thanks for any help.

I have several inputFields where the value is set to the account ownerid.  Is it possible to override the label?

 

<apex:page standardController="Account"> <h1>Manage Salesperson Territory Assignments</h1> <apex:form > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Update"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:inputField value="{!account.ownerId}"/> <apex:inputField value="{!account.ownerId}"/> <apex:inputField value="{!account.parentId}"/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Update Account Ownership by State" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Update"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Used to update owner of accounts by selected state" columns="1"> <apex:inputField value="{!account.ownerId}"/> <apex:inputField value="{!account.State__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

I would like to change the labels for the account owner inputFields to:

 

"Change Owner From:"

"Change Owner To:"

 

Is this possible?

I'm working with the following trigger that uses a Database savepoint.

 

trigger ServiceDeliveryBeforeInsertBeforeUpdate on Service_Delivery__c (before insert, before update) { Savepoint sp = Database.setSavePoint(); List<Service_Booking__c> bookingsToUpdate = new List<Service_Booking__c>(); try { if (Trigger.isUpdate) { // this is an update trigger; "zero out" all the records being updated List<Service_Delivery__c> tempRecords = new List<Service_Delivery__c>(); for (Service_Delivery__c delv : Trigger.old) { // try to insert a delivery that charges this same number of days if (delv.Days_Charged__c > 0) { // don't execute this logic for negative days Service_Delivery__c tempDelivery = new Service_Delivery__c(); tempDelivery.Days_Charged__c = -1 * delv.Days_Charged__c; // to "zero out" tempDelivery.Services_Engagement__c = delv.Services_Engagement__c; tempDelivery.Start__c = delv.Start__c; tempDelivery.End__c = delv.End__c; tempDelivery.Description__c = delv.Description__c; tempDelivery.Delivery_Type__c = delv.Delivery_Type__c; tempDelivery.Delivery_Sub_type__c = delv.Delivery_Sub_type__c; tempRecords.add(tempDelivery); } } insert tempRecords; } for (Service_Delivery__c delv : Trigger.new) { if (delv.Service_Booking__c != null) { Service_Booking__c bk = [SELECT Delivery_Type__c FROM Service_Booking__c WHERE Id = :delv.Service_Booking__c]; if (delv.Days_Charged__c > 0) { // don't execute this logic for negative charges (which are most likely from this trigger) Services_Engagement__c engagement = [Select Id, Name, Days_Available__c from Services_Engagement__c where Id = :delv.Services_Engagement__c]; if (engagement.Days_Available__c < delv.Days_Charged__c) { delv.adderror('You have attempted to bill ' + delv.Days_Charged__c + ' days against service obligation ' + engagement.Name + ', but only ' + engagement.Days_Available__c + ' days are available'); } else { // everything is fine; proceed with making booking inactive if (delv.Service_Booking__c != null) { Service_Booking__c booking = null; //Find the Service Booking associated with the Service Delivery booking = [SELECT Id, Active__c, Services_Engagement__c FROM Service_Booking__c WHERE Id = :delv.Service_Booking__c]; booking.Active__c = false; bookingsToUpdate.add(booking); } } } } } } finally { Database.rollback(sp); } update bookingsToUpdate; }

 

 

The problem is deliveries are still getting created if the booking is null on the delivery.  The following line checks this condition:

 

if (delv.Service_Booking__c != null)

My expectation is the code would exit this block and go to the finally statement and rollback (not create the delivery).  But, the delivery is still getting created.

 

Why?

 

Thanks for any help.

 

Is it possible to query attachments on an account.  I tried:

 

Select Title, Id from NoteAndAttachment WHERE ParentId = 'accountID'

 

Error: Query failed: Invalid Type for Operation: entity type does not support query

 

 

I have a date field in a custom object that I am going to populate from a visualforce page.

 

My method is as follows:

 

public date getStartDate() { date dtCurrentDate = date.today(); Integer i; date dtStartDate; i = dtCurrentDate.year(); string s = string.valueof('1/01/' + i); dtStartDate = date.parse(s); return dtStartDate; }

 

This displays my date on my visualforce page as:

 

1/01/09 12:00AM

 

How can I format to a shortdate as: 1/1/2009.  There is additional manipulation I will do to the date before inserting into the date field in my custom object, but I want to get the formatting to a shortdate without the time.

I have a trigger that occasionally throws an error due to a validation rule.  I have a try/catch block in my trigger, but the validation rule isn't caught in the catch block.  Is there a way to gracefully handle the error thrown by the validation rule when the trigger fires?

 

If there is no way to trap for the validation rule errors in a trigger, can anyone explain why?  Currently, a big red apex error message is generated, which is not very user friendly to the end-user.  I'm just trying to handle the error gracefully, if possible.

 

Thanks for any help.

Message Edited by Dman100 on 12-10-2009 11:27 AM

I've written a trigger that works perfectly after inserts and after updates.  The problem is after delete which can only use Trigger.old.

 

The trigger fires on the OpportunityLineItem and sets a value on the opportunity when a line item is inserted or updated.  I want to add the same process to fire when a line item is deleted, so the field value on the opportunity is updated correctly.

 

I've tried using if (Trigger.IsDelete) and looking at the trigger old values, but the obvious problem is it is still looking at the old values and not the new values that no longer includes the deleted line item.

 

For example, the trigger sets a value on the opportunity based on specific criteria defined by precedence (which criteria occurs first).  If that line item is deleted, then all the line items need to be iterated again to set the appropriate value on the opportunity (what is the new criteria that occurs first) after the line item has been deleted.

 

Is there a way to make this happen in the trigger?  It would seem, that I need to re-fire the  trigger after a line item has been deleted, so that I can examine the new line items after the delete occurred.

 

Is it possible to do this thru a workflow maybe?

 

Here is my existing trigger without the after delete:

 

trigger OpportunityLineItemVertical on OpportunityLineItem (after insert, after update) { OpportunityLineItem oli = [Select Opportunity.Id, Opportunity.Account.Id From OpportunityLineItem Where Id in :Trigger.new Limit 1]; List<OpportunityLineItem> olis = [Select Id, PricebookEntry.Product2.Name, PricebookEntry.Product2.Product_Line__c From OpportunityLineItem Where OpportunityId = :oli.Opportunity.Id]; for (OpportunityLineItem x : olis) { system.debug('Name = ' + x.PricebookEntry.Product2.Name); system.debug('Product Line = ' + x.PricebookEntry.Product2.Product_Line__c); } system.debug('Opportunity Id = ' + oli.Opportunity.Id); system.debug('Account Id = ' + oli.Opportunity.Account.Id); List<Id> pbeIds = new List<Id>(); for (Integer i = 0; i < Trigger.size; i++) { pbeIds.add(Trigger.new[i].PricebookEntryId); } for (Id i : pbeIds) { system.debug('Pricebook Entry Ids = ' + pbeIds); } List<PricebookEntry> pbes = [Select Product2Id From PricebookEntry Where Id in :pbeIds]; List<Id> prodIds = new List<Id>(); for (PricebookEntry pbe : pbes) { prodIds.add(pbe.Product2Id); } for (Id i : prodIds) { system.debug('Product Ids = ' + prodIds); } List<Product2> products = [Select Name, Product_Line__c From Product2 Where Id in :prodIds]; Account acct = [Select Local_Region__c, Market_Segment__c, Industry From Account Where Id = :oli.Opportunity.Account.Id]; Opportunity op = [Select OwnerId From Opportunity Where Id = :oli.Opportunity.Id]; system.debug('Owner Id = ' + op.OwnerId); User u = [Select ProfileId From User Where Id = :op.OwnerId]; system.debug('Profile Id = ' + u.ProfileId); Profile p = [Select Name From Profile Where Id = :u.ProfileId]; Boolean foundMarketplace = false; Boolean foundTeleAtlas = false; Boolean foundStoreSystems = false; Boolean foundLogisticsMgmt = false; try { for (OpportunityLineItem oppLine : Trigger.new) { for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Name == 'JDA Marketplace Replenish') { FoundMarketPlace = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Name == 'Tele Atlas') { foundTeleAtlas = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Product_Line__c == 'Store Operations') { foundStoreSystems = true; } } for (OpportunityLineItem o : olis) { if (o.PricebookEntry.Product2.Product_Line__c == 'Logistics Management') { foundLogisticsMgmt = true; } } if (p.Name.contains('Alliance')) { op.JDA_Vertical__c = 'VAR'; update op; break; } else if (acct.Local_Region__c != null && acct.Local_Region__c.contains('Latin America')) { op.JDA_Vertical__c = 'Latin America'; update op; break; } else if (foundMarketplace) { op.JDA_Vertical__c = 'Marketplace'; update op; break; } else if (foundTeleAtlas) { op.JDA_Vertical__c = 'Transportation'; update op; break; } else if (foundStoreSystems) { op.JDA_Vertical__c = 'Store Systems'; update op; break; } else if (foundLogisticsMgmt) { op.JDA_Vertical__c = 'Transportation'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.startsWith('Grocery')) { op.JDA_Vertical__c = 'Grocery/Drug'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.contains('Hardlines')) { op.JDA_Vertical__c = 'Retail Hardlines'; update op; break; } else if (acct.Market_Segment__c != null && acct.Market_Segment__c.contains('Softlines')) { op.JDA_Vertical__c = 'Retail Softlines'; update op; break; } else if (acct.Industry != null && acct.Industry == 'Manufacturing') { op.JDA_Vertical__c = 'Consumer Goods'; update op; break; } else if (acct.Industry != null && acct.Industry == 'Wholesale/Distribution') { op.JDA_Vertical__c = 'Wholesale/Distribution'; update op; break; } else { op.JDA_Vertical__c = 'Unknown'; update op; break; } } } catch (Exception ex) { Opportunity opp = [Select Error_Message__c From Opportunity Where Id = :oli.Opportunity.Id]; opp.Error_Message__c = ex.GetMessage(); update opp; return; } }

 

I'm trying to debug an old s-control that has been working fine, but recently encountered an error.

 

Here is the s-control code:

 

<html> <head> <script type="text/javascript" src="/js/functions.js"></script> <script src="/soap/ajax/12.0/connection.js"></script> <script language="javascript1.2" type="text/javascript"> // Update Related Records function updateRelatedRecords() { //Get Records - Contact Roles for Account var AccountId = "{!Account.Id}"; var ParentId="{!Account.ParentId}"; var childAccounts; var parentContactRoles; var childContactRoles; var hasParentContactRoles = false; var hasChildAccounts = false; var strSQL; var result; //If the Account is a child Account which means it has ParentId then //nothing should happen if(ParentId != ''){ alert("This is a child Account"); } else { strSQL="Select Id, AccountId,Role,ContactID From AccountContactRole where AccountId='{!Account.Id}'"; result = sforce.connection.query(strSQL); parentContactRoles = result.getArray("records"); //If the Parent Account has no Contact Roles then it should //not do anything No update or insert to anything not even Child records if(parentContactRoles.length==0){ alert("There are no Contact Roles for this Account '{!Account.Name}'"); } else { hasParentContactRoles = true; } //If the Parent Account has no child Accounts then //do not do anything either strSQL="Select Id,Name from Account where ParentId='{!Account.Id}'"; result = sforce.connection.query(strSQL); childAccounts = result.getArray("records"); if(childAccounts.length==0){ alert("There are no child Accounts for '{!Account.Name}'"); } else { hasChildAccounts = true; } if(hasParentContactRoles && hasChildAccounts){ var newContactRoles = []; var contactRoleExists = false; var i,j,k; for (i in childAccounts){ //Get Contacts Roles for each child account strSQL="Select Id, AccountId, Role, ContactId From AccountContactRole where AccountId=" + "'" + childAccounts[i].Id + "'"; result = sforce.connection.query(strSQL); childContactRoles = result.getArray("records"); for(j in parentContactRoles){ contactRoleExists = false; for(k in childContactRoles){ if(parentContactRoles[j].Role == childContactRoles[k].Role) {contactRoleExists = true;} } if(!contactRoleExists){ var newContactRole = new sforce.SObject("AccountContactRole"); newContactRole.AccountId = childAccounts[i].Id; newContactRole.ContactId = parentContactRoles[j].ContactId; newContactRole.Role = parentContactRoles[j].Role; newContactRoles.push(newContactRole); } } } if(newContactRoles.length > 0){ result = sforce.connection.create(newContactRoles); document.write(newContactRoles.length + " new Contact Roles were created in child accounts."); } else { document.write("No Contact Roles assigned. All child accounts already have all roles defined."); } } } } </script> </head> <body onload="updateRelatedRecords()";> </body> </html>

 

I believe, the s-control is erroring out when it gets to this section:

 

 

for (i in childAccounts){ //Get Contacts Roles for each child account strSQL="Select Id, AccountId, Role, ContactId From AccountContactRole where AccountId=" + "'" + childAccounts[i].Id + "'"; result = sforce.connection.query(strSQL); childContactRoles = result.getArray("records");

 

 

I just get a blank window that opens and it just times out and nothing happens.  No errors, but the s-control does not update the child accounts.

 

This only happens with one account.  The s-control has been working fine.  It seems like a governor limit issue?

 

I'm not overly proficient with javascript.  Is there a way I can display the error and see what is happening?  If it is a governor limit issue, is there a way to get around the limit?

 

Thanks for any help.

I have a two pageBlocks and I want to display the second pageBlock after the command button the first pageBlock is fired.

 

I created a boolean public property in my controller:

 

public Boolean IsShown{ get; set; }

 

I set the property in my method:

 

public PageReference ChildAccountOwnershipCount() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; ChildAccountCount = [Select Count() From Account where ParentId =: parent.Id]; ChildAccountCount += ChildAccountCount + 1; IsShown = true; return null; }

 

 

Here is my VF code:

 

<apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit" id="ChildAccountsPageBlock"> <apex:pageBlockButtons > <apex:commandButton action="{!ChildAccountOwnershipCount}" value="Update" rerender="ChildAccountsPageBlock, Msg, ChildAccountConfirmPageBlock" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock id="ChildAccountConfirmPageBlock" rendered="{!IsShown}" > <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Confirm" rerender="ChildAccountsPageBlock, Msg" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection > <apex:outputLabel value="You are about to update {!ChildAccountCount} accounts. Please click to confirm." /> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion>

 

 

 

The second pageBlock does not open when the page posts back?

 

Thanks.

I need some help and guidance writing a unit test for a custom controller I've created.

 

public class AccountMaintenanceController { private Account acctToByParent = new Account(); private Account parentAcct = new Account(); public AccountMaintenanceController() { } public PageReference updateChildAccountOwnership() { try { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); acctToByParent.OwnerId = null; parentAcct.parentId = null; return null; } catch (Exception ex) { ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()); ApexPages.addMessage(errMsg); return null; } } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } static testMethod void test() { } }

 

Sorry for the novice questions, but how do I set the property values in the test method and how do I call the method?

 

Thanks for any help.

I'm trying to display a confirm dialog to the user before executing an update.

 

I've tried the following:

 

<apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg, AccountMaintenance" status="AccountsOpportunitiesLoadingStatus" onclick="return confirm('Are you sure you want to update the following records?')" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons>

 

I discovered that I could process the update with the confirmation dialog using the actionFunction tag.  However, it causing some other problems.

 

I have three pageBlock sections wrapped in actionRegion tags, so that each pageBlock section will validate and process independently.

 

Once I added the actionFunction tag, the actionRegion no longer functions correctly.  When the page posts back, all three pageBlock sections validate.

 

Here is my VF code:

 

<apex:page Controller="AccountMaintenanceController"> <script> function confirmation() { var answer = confirm('Are you sure you want to update the following records?'); if (answer) { doSave(); } else { return false; } } </script> <h1>Manage Salesperson Territory Assignments</h1> <apex:form id="AccountMaintenance"> <apex:actionRegion > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg, AccountMaintenance" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton value="Update" onclick="confirmation();" /> <apex:actionFunction name="doSave" action="{!updateChildAccountOwnership}" rerender="UpdateChildAccountsSuccessMsg, AccountMaintenance" status="ChildAccountsLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:actionStatus id="ChildAccountsLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageMessages rendered="true" id="UpdateChildAccountsSuccessMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> <apex:actionRegion > <apex:pageBlock title="Update Account Ownership by State" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountByState}" value="Update" rerender="UpdateOwnerByStateSuccessMsg, AccountMaintenance" status="StateLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateOwnerByStateSuccessMsg" /> <apex:actionStatus id="StateLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to update owner of accounts by selected state" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByState.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="State" for="state" /> <apex:inputField value="{!State.State__c}" id="state" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:actionRegion> </apex:form> </apex:page>

 

 

Thanks for any help.

Message Edited by Dman100 on 10-17-2009 09:52 PM

I have a inputCheckbox and when the page posts back, the checkbox field is not getting set when the checkbox is selected.  I have a boolean property defined in the controller.  I'm not sure what I'm missing?

 

here is the VF code:

 

<apex:page Controller="AccountMaintenanceController"> <apex:form > <apex:pageBlock title="Update Account and Opportunity Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateAccountsOpportunities}" value="Update" rerender="UpdateAccountsOpportunitiesSuccessMsg" status="AccountsOpportunitiesLoadingStatus" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="UpdateAccountsOpportunitiesSuccessMsg" /> <apex:actionStatus id="AccountsOpportunitiesLoadingStatus"> <apex:facet name="start"> Updating records... <img src="{!$Resource.AjaxLoading}"/> </apex:facet> </apex:actionStatus> <apex:pageBlockSection title="Used to transfer ownership of accounts and opportunities from one sales rep to another" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner From" for="old_account_owner" /> <apex:inputField value="{!AccountFrom.ownerId}" id="old_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountTo.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Account Ownership" for="acct_owner" /> <apex:inputCheckbox value="{!acctChkbox}" id="acct_owner" /> </apex:pageBlockSectionItem> <apex:outputLabel value="{!acctChkbox}" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Ownership" for="oppy_owner" /> <apex:inputCheckbox value="{!oppyChkbox}" id="oppy_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Opportunity Email" for="oppy_email" /> <apex:inputCheckbox value="{!oppyEmailChkbox}" id="oppy_email" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctFrom = new Account(); private Account acctTo = new Account(); public PageReference updateAccountsOpportunities() { //List<Account> acctsFrom = [Select Id, OwnerId From Account where ownerId =: acctFrom.ownerId]; //List<Opportunity> oppys = [Select Id, OwnerId From Opportunity where ownerId =: acctFrom.ownerId]; //List<Account> acctsToUpdate = new List<Account>(); //for (Account acct: acctsFrom) //{ //acct.OwnerId = acctTo.OwnerId; //acctsToUpdate.add(acct); //} //if (acctChkbox == true) //{ //DbUtil.save(acctsToUpdate); //} //List<Opportunity> oppysToUpdate = new List<Opportunity>(); //for (Opportunity op: oppys) //{ //op.OwnerId = acctTo.ownerId; //oppysToUpdate.add(op); //} //if (oppyChkbox == true) //{ //DbUtil.save(oppysToUpdate); //} //List<Opportunity> oppysCommissionSalespersonToUpdate = new List<Opportunity>(); //for (Opportunity op: oppys) //{ //op.Commission_Salesperson__c = acctTo.ownerId; //oppysCommissionSalespersonToUpdate.add(op); //} //if (oppyEmailChkbox == true) //{ //DbUtil.save(oppysCommissionSalespersonToUpdate); //} //ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Records updated successfully.'); //ApexPages.addMessage(msg); //PageReference pr = System.Page.AccountMaintenance; //pr.setRedirect(true); //return pr; return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountFrom() { return acctFrom; } public Account getAccountTo() { return acctTo; } public Boolean acctChkbox { get { if (acctChkbox == null) { acctChkbox = false; } return acctChkbox; } set; } public Boolean oppyChkbox { get { if (oppyChkbox == null) { oppyChkbox = false; } return oppyChkbox; } set; } public Boolean oppyEmailChkbox { get { if (oppyEmailChkbox == null) { oppyEmailChkbox = false; } return oppyEmailChkbox; } set; } }

 

 

Thanks for any help.

How do I clear the inputfields after an update?

 

here is my VF page:

 

<apex:page Controller="AccountMaintenanceController"> <h1>Manage Salesperson Territory Assignments</h1> <apex:form > <apex:pageBlock title="Update Specific District or Account Ownership" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!updateChildAccountOwnership}" value="Update" rerender="successMsg" /> <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" /> </apex:pageBlockButtons> <apex:pageMessages rendered="true" id="successMsg" /> <apex:pageBlockSection title="Used to update owner of specified account and related child accounts" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Change Owner To" for="new_account_owner" /> <apex:inputField value="{!AccountToByParent.ownerId}" id="new_account_owner" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="District Account to update" for="account_name" /> <apex:inputField value="{!DistrictAccount.parentId}" id="account_name" required="true" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

Here is my controller class:

 

public class AccountMaintenanceController { private Account acctToByParent = new Account(); private Account parentAcct = new Account(); public PageReference updateChildAccountOwnership() { Account parent = [Select Id, OwnerId From Account where Id =: parentAcct.ParentId]; List<Account> childAccts = [Select Id, OwnerId From Account where ParentId =: parent.Id]; parent.ownerId = acctToByParent.ownerId; DbUtil.save(parent); List<Account> lst = new List<Account>(); for (Account acct: childAccts) { acct.OwnerId = acctToByParent.OwnerId; lst.add(acct); } DbUtil.save(lst); ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.INFO, 'Account ownership updated successfully.'); ApexPages.addMessage(msg); return null; } public PageReference cancel() { PageReference newpage = new PageReference(System.currentPageReference().getURL()); newpage.setRedirect(true); return newpage; } public Account getAccountToByParent() { return acctToByParent; } public Account getDistrictAccount() { return parentAcct; } }

 

 

I've tried setting the private fields to an empty string, but that did not work.

 

Thanks for any help.

I have the following validation rule, but it doesn't work as I'm expecting

 

AND(NOT(ISPICKVAL(Delivery_Type__c ,"Customer non-revenue")),(Days_Available__c < 0))

 

I want the validation rule to fire when the following is true:

 

If the picklist value "Customer non-revenue for the delivery type field is not selected and the days available field is less than zero.

 

So, if the delivery type is customer non-revenue, the validation evaluates to false and the validation doesn't fire.

 

right now, the validation is always evaluating to true and fires if the days available is negative.  I just can't get the delivery type portion of the validation working correctly.

 

Thanks for any help.

I have a trigger that I am firing on cases before update.  After the contacts are created, I am trying to update the contact lookup (reference) field on the case.

 

Here is what I am trying:

 

trigger InsertCaseContact on Case (before update) { //Create a new list for caseIds List<Id> caseIds = new List<Id>{}; //Loop through the Cases we're adding and build a list of Ids for(Case cas: Trigger.new) caseIds.add(cas.Id); List<Contact> addContacts = new List<Contact>(); // Loop through the Trigger.new array of Cases. for(Case cas:Trigger.new){ if (cas.SuppliedName != null) { addContacts.add(new Contact (LastName = cas.SuppliedName, Email = cas.SuppliedEmail, Phone = cas.SuppliedPhone, Email_ExtID__c = cas.SuppliedEmail)); } } upsert addContacts Email_ExtID__c; // loop thru contacts to retrieve contact ids List<Contact> newContacts = new List<Contact>(); for (Contact c: addContacts) { newContacts.add(c); } List<Case> cases = new List<Case>{}; for (Case c : Trigger.new) { c.ContactId = newContacts.Id; cases.add(c); } update cases; }

 


Save error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Contact

 

How can I update the contact reference field in the cases with with the list of new contacts?

 

Thanks for any help.

Is there an apex equivalent of getting the id of a newly inserted record?

 

trigger InsertCaseContact on Case (before update) { //Create a new list for caseIds List<Id> caseIds = new List<Id>{}; //Loop through the Cases we're adding and build a list of Ids for(Case cas: Trigger.new) caseIds.add(cas.Id); List<Contact> addContacts = new List<Contact>(); // Loop through the Trigger.new array of Cases. for(Case cas:Trigger.new){ if (cas.SuppliedName != null) { addContacts.add(new Contact (LastName = cas.SuppliedName, Email = cas.SuppliedEmail, Phone = cas.SuppliedPhone)); } } insert addContacts; }

 

I'd like to get the id of the newly inserted contact records.

I'm trying to create a formula field that returns the value true or a numeric value of 1 (either value would work) where a custom field that is a date/time datatype is greater than the current month

 

I was trying the following, but it is not correct:

 

After Month End (TEXT) = IF(End__c > THIS MONTH, 'true', 'false')

 

I just want to check if the date in the custom field end__c is past the current month and if so, set the value to true or 1.

 

Thanks.