• Dman100
  • NEWBIE
  • 15 Points
  • Member since 2007

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

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.