-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
22Questions
-
17Replies
Including commas and and's in formula for combining line items
I have a formula field that I built in a custom object that combines various fields into this one field for a mail merge. The custom object is called Product Donations, and there are about 12 fields referencing various line items that are referenced here.
SUBSTITUTE( IF(ISBLANK(NEW_Letters__c),"", Letter_Count__c) &IF(ISBLANK(Gators__c),""," "&TEXT(Gators__c) & " handmade gators,") &IF(ISBLANK(Paracords__c),"", " "&TEXT(Paracords__c) & " paracord bracelets,") &IF(ISBLANK(Cool_Ties__c),"", " "&TEXT(Cool_Ties__c) & " handmade cool ties,") &IF(ISBLANK(Phone_Cards__c),"", " "&TEXT(Phone_Cards__c) & " phone cards,") &IF(ISBLANK(Battalion_Buddy__c),"", " "&TEXT(Battalion_Buddy__c) & " battalion buddies,") &IF(ISBLANK(Comic_Books__c),"", " comic books,") &IF(ISBLANK(Magazines__c),"", " magazines,") &IF(ISBLANK(Books__c),"", " books,") &IF(ISBLANK(Handmade_Cards__c),"", " handmade cards,") &IF(ISBLANK(Care_Kits__c),""," care kits,") &IF(ISBLANK(Gift_Cards__c),""," gift cards,") &IF(ISBLANK(Socks__c),"", " socks,") &IF(ISBLANK(Girl_Scout_Cookies__c),"", " "&TEXT(Girl_Scout_Cookies__c) & " boxes of Girl Scout cookies,") &IF(ISBLANK(Food_And_Snacks__c),"", " snack foods,") &IF(ISBLANK(Toys_Animals_Bears__c),""," assorted toys,") &IF(ISBLANK(Beanie_Babies__c),"", " "&TEXT(Beanie_Babies__c)& " Beanie Babies,") &IF(ISBLANK(Hats__c),"", " "&TEXT(Hats__c) & " handmade hats," ) &IF(ISBLANK(Scarves__c),"", " "&TEXT(Scarves__c)& " handmade scarves,") &IF(ISBLANK(Video_Games__c),"", " "&TEXT(Video_Games__c)& " video games,") &IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(CDs_DVDs__c)& " CD's,") &IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(DVDs__c)& " DVD's,") &IF(ISBLANK(Candy_lbs__c),"", " "&TEXT(Candy_lbs__c)& " Lbs of candy,") &IF(ISBLANK(Assorted_Items__c),""," assorted items,") &IF(ISBLANK(Recyclables__c),"", " recyclable items,")& " ", ",.", "" )
On the letter count, if there are additional itmes, I notice that a comma does not appear after it, it reads for example letters 1 scarves, 20 paracords, assorted items. Additionally, I am also looking for a way to include the word "and" after the comma if multiple line items exist. In this case, it should read as
letters 1 scarves, 20 paracords and assorted items.
Instead of
letters 1 scarves, 20 paracords, assorted items
Also is there a formula to singularize items that have a 1 in it. For instance 1 scarves should just say scarf.
I can help with any further questions, even set up a trigger if needed.
Hope this helps.
-
- Medhanie Habte
- May 11, 2016
- Like
- 0
- Continue reading or reply
Bypass Salesforce Standard Account Lookup with Visualforce page
This VF page, based on Jeff Douglas's Rollup your own Salesforce Lookup Popup enables our users to create Contact records. Now I recently created another lookup like this one for accounts, where when a user types an account or looks up an account to connect a new contact to an existing Salesforce account. I added some Javascript to force the Account lookup to open and run the custom Account lookup I created, however, with the script, I still get the Salesforce standard lookup, where should I place this code (attached below) or what should I add to enable the custom page I built to open.
Hope it helps.
Code for the Visualforce page
<apex:page controller="ContactLookupControl" title="Search" showHeader="false" sideBar="false" tabStyle="Contact" id="pg"> <apex:form > <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel"> <!-- SEARCH TAB --> <apex:tab label="Search" name="tab1" id="tabOne"> <apex:actionRegion > <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/> <apex:inputText id="txtSearch" value="{!searchString}" /> <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span> </apex:outputPanel> <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block"> <apex:pageBlock id="searchResults"> <apex:pageBlockTable value="{!results}" var="a" id="tblResults"> <apex:column > <apex:facet name="header"> <apex:outputPanel >Name</apex:outputPanel> </apex:facet> <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!JSENCODE(a.Name)}', false);self.close();" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink> </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Account Name</apex:outputPanel> </apex:facet> {!a.Account.Name} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Street</apex:outputPanel> </apex:facet> {!a.MailingStreet} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >City</apex:outputPanel> </apex:facet> {!a.MailingCity} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >State</apex:outputPanel> </apex:facet> {!a.MailingState} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Postal Code</apex:outputPanel> </apex:facet> {!a.MailingPostalCode} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Phone</apex:outputPanel> </apex:facet> {!a.Phone} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Email</apex:outputPanel> </apex:facet> {!a.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:actionRegion> </apex:tab> <!-- NEW CONTACT TAB --> <apex:tab label="New Contact" name="tab2" id="tabTwo"> <apex:pageBlock id="newContact" title="New Contact" > <apex:pageBlockButtons > <apex:commandButton action="{!saveContact}" value="Save & Close"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection columns="2"> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField value="{!Contact.LastName}"/> <apex:inputField value="{!Contact.AccountId}"/> <apex:inputField value="{!Contact.MailingStreet}"/> <apex:inputField value="{!Contact.MailingCity}"/> <apex:inputField value="{!Contact.MailingState}"/> <apex:inputField value="{!Contact.MailingPostalCode}"/> <apex:inputField value="{!Contact.MailingCountry}"/> <apex:inputField value="{!Contact.Phone}"/> <apex:inputField value="{!Contact.Email}"/> </apex:pageBlockSection> </apex:pageBlock> <script> if({!Contact.id!=null}){ //alert('{!Contact.Name} {!Contact.id}'); top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!Contact.Id}','{!JSENCODE(Contact.Name)}', false);self.close(); } </script> <script> var overwriteObj3="001"; var overwriteObjConf="Account"; var overwriteObjC="003"; var overwriteObjConfC="Contact"; function getParameterByName( name ,url){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( url ); if( results == null ) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } var lookupPickOrig=null; $(document).ready(function(){ $("body").bind("OnRenderDone",function(){ if(lookupPickOrig==null){ lookupPickOrig= openLookup;//save old function if needed } openLookup=function(a, b,c, d,e,f,g,l){//overwrite with your custom code //alert(a+"~"+b+"~"+c+"~"+d+"~"+e+"~"+f+"~"+g+"~"+l); var ax=a; if(ax.indexOf("lktp=001”)>-1){ var lknm=getParameterByName("lknm",ax); var lkfm=getParameterByName("lkfm",ax); var lksrch=getParameterByName("lksrch",ax); //alert(b+"~"+c+"~"+d+"~"+e+"~"+f+"~"+g+"~"+l); ax="/apex/AccountLookupControl?"+(ax.split("?")[1]+"&frm="+escape(lkfm)+"&txt="+escape(lknm)+d); // lookupPickOrig(ax, b,c, d,e,f,g,l); window.open(ax,"_blank","width=690,height=690"); }else{ lookupPickOrig(ax, b,c, d,e,f,g,l); } //put your code here } }); }); </script> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page>
The Script that should open the custom popup and bypass the standard Salesforce account lookup dialog
<script> var overwriteObj3="001"; var overwriteObjConf="Account"; var overwriteObjC="003"; var overwriteObjConfC="Contact"; function getParameterByName( name ,url){ name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var results = regex.exec( url ); if( results == null ) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } var lookupPickOrig=null; $(document).ready(function(){ $("body").bind("OnRenderDone",function(){ if(lookupPickOrig==null){ lookupPickOrig= openLookup;//save old function if needed } openLookup=function(a, b,c, d,e,f,g,l){//overwrite with your custom code //alert(a+"~"+b+"~"+c+"~"+d+"~"+e+"~"+f+"~"+g+"~"+l); var ax=a; if(ax.indexOf("lktp=001”)>-1){ var lknm=getParameterByName("lknm",ax); var lkfm=getParameterByName("lkfm",ax); var lksrch=getParameterByName("lksrch",ax); //alert(b+"~"+c+"~"+d+"~"+e+"~"+f+"~"+g+"~"+l); ax="/apex/AccountLookupControl?"+(ax.split("?")[1]+"&frm="+escape(lkfm)+"&txt="+escape(lknm)+d); // lookupPickOrig(ax, b,c, d,e,f,g,l); window.open(ax,"_blank","width=690,height=690"); }else{ lookupPickOrig(ax, b,c, d,e,f,g,l); } //put your code here } }); }); </script>
-
- Medhanie Habte
- April 08, 2016
- Like
- 0
- Continue reading or reply
assign a contact to a Person Account (Silly Question?!)
This allows us to send emails or generate correspondence in some of our reports. On some occassions, we will then receive a contact representative who is affiliated with the organization and we want to assign to a person account record that already exists, however, the trigger force-renames the account, which we don't want. In essence, we want to be able to assign a contact to an already existing account, even if that account may be a person account. Is there a trigger to address.
I've include a video to demonstrate here.
http://screencast.com/t/LE7AybwbAon
Hope it helps.
-
- Medhanie Habte
- March 04, 2016
- Like
- 0
- Continue reading or reply
External Data Source types
-
- Medhanie Habte
- December 24, 2015
- Like
- 0
- Continue reading or reply
External Data Source picklist values
-
- Medhanie Habte
- December 24, 2015
- Like
- 0
- Continue reading or reply
Uploading Attachment files when creating a record
-
- Medhanie Habte
- December 21, 2015
- Like
- 0
- Continue reading or reply
Creating a formula to compare date values that don't match
IF(npo02__FirstCloseDate__c <> Account.npe01__FirstDonationDate__c, IF(npo02__FirstCloseDate__c < Account.npe01__FirstDonationDate__c, npo02__FirstCloseDate__c, IF(npo02__FirstCloseDate__c > Account.npe01__FirstDonationDate__c, Account.npe01__FirstDonationDate__c ,npo02__FirstCloseDate__c )))However, I get this error message reading Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 2.
Any thing I'm missing. Hope it helps.
-
- Medhanie Habte
- December 11, 2015
- Like
- 0
- Continue reading or reply
Adding a formula field that populates based on two if statements
IF(Account.Name <> Contact.Full_Name__c) and IF(Donor_Type__c !="Individual") then Product_Donations_Summary__c = "Greetings from Us", Dear+Contact.First_Name__c
Hope it helps.
-
- Medhanie Habte
- October 19, 2015
- Like
- 0
- Continue reading or reply
Writing a trigger to sort a concatenated formula field by numerical value
trigger ProductDonationsSummary on Product_Donations__c (before insert) { Map<Integer, String> mapNumValueAndFieldLabel = new Map<Integer,String>(); String strMessage; //null checkers for the field and adding the number value as key and the string message as the value if its not null/blank/zero IF(Total_LettersTally__c != null && Total_LettersTally__c != '' && Integer.valueOf(Total_LettersTally__c) != 0) mapNumValueAndFieldLabel.put(Integer.valueOf(Total_LettersTally__c), Total_LettersTally__c + " letters"); IF(Gators__c != null && Gators__c != '' && Integer.valueOf(Gators__c) != 0) mapNumValueAndFieldLabel.put(Integer.valueOf(Gators__c), Gators__c + " Gators"); IF(Paracords__c != null && Paracords__c != '' && Integer.valueOf(Paracords__c) != 0) mapNumValueAndFieldLabel.put(Integer.valueOf(Paracords__c), Paracords__c + " paracord bracelets"); //and so on for other fields.... //Proceed further only if either of the fields have non zero values if(mapNumValueAndFieldLabel.values().size() > 0) { List<Integer> lstNumValue = new List<integer> (); lstNumValue.addAll(mapNumValueAndFieldLabel.keyset()); //Sort the Values (by default SFDC sorts it in ascending order) lstNumValue.sort(); //Iterating through the sorted Integer list in reverse order (descending) to get the final String message from the map for(Integer i = lstNumValue.size()-1; i >= 0; i--) { strMessage = mapNumValueAndFieldLabel.get(lstNumValue(i)) + ", "; } } //strMessage will hold the message you want to display }
-
- Medhanie Habte
- October 15, 2015
- Like
- 0
- Continue reading or reply
Unexpected token error with apostrophes in lookup/create page
-
- Medhanie Habte
- October 04, 2015
- Like
- 0
- Continue reading or reply
Sorting a custom contactenated formula field with number values in descending order
Additionally, I am trying to determine a way to include a formula for instance if a value in any of these items amounts to one, then it would just read as one letter.
Also is there a way to include an and in this formula after the last comma in the event that there a values in more than one item, so it would 11 handmade card, 11 phone care and one letter.
Let me know if this is possible and many thanks.
SUBSTITUTE( IF(ISBLANK(Total_LettersTally__c),""," "&TEXT(Total_LettersTally__c) & " letters,") &IF(ISBLANK(Gators__c),""," "&TEXT(Gators__c) & " Gators,") &IF(ISBLANK(Paracords__c),"", " "&TEXT(Paracords__c) & " paracord bracelets,") &IF(ISBLANK(Cool_Ties__c),"", " "&TEXT(Cool_Ties__c) & " cool ties,") &IF(ISBLANK(Phone_Cards__c),"", " "&TEXT(Phone_Cards__c) & " phone cards,") &IF(ISBLANK(Battalion_Buddy__c),"", " "&TEXT(Battalion_Buddy__c) & " battalion buddies,") &IF(ISBLANK(Comic_Books__c),"", " "&TEXT(Comic_Books__c) & " comic books,") &IF(ISBLANK(Handmade_Cards__c),"", " "&TEXT(Handmade_Cards__c) & " handmade cards,") &IF(ISBLANK(Care_Kits__c),"", " "&TEXT(Care_Kits__c) & " care kits,") &IF(ISBLANK(Gift_Cards__c),"", " "&TEXT(Gift_Cards__c) & " gift cards,") &IF(ISBLANK(Socks__c),"", " "&TEXT(Socks__c) & " socks,") &IF(ISBLANK(Girl_Scout_Cookies__c),"", " "&TEXT(Girl_Scout_Cookies__c) & " girl scout cookies,") &IF(ISBLANK(Food_And_Snacks__c),"", " "&TEXT(Food_And_Snacks__c) & " food and snack items,") &IF(ISBLANK(Toys_Animals_Bears__c),"", " "&TEXT(Toys_Animals_Bears__c)& " toys, animals And bears,") &IF(ISBLANK(Beanie_Babies__c),"", " "&TEXT(Beanie_Babies__c)& " beanie babies,") &IF(ISBLANK(Hats__c),"", " "&TEXT(Hats__c) & " hats," ) &IF(ISBLANK(Scarves__c),"", " "&TEXT(Scarves__c)& " scarves,") &IF(ISBLANK(Video_Games__c),"", " "&TEXT(Video_Games__c)& " video games,") &IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(CDs_DVDs__c)& " CD's & DVD's,") &IF(ISBLANK(Candy_lbs__c),"", " "&TEXT(Candy_lbs__c)& " lbs of candy,") &IF(ISBLANK(Assorted_Items__c),"", " "&TEXT(Assorted_Items__c)& " assorted items,") &IF(ISBLANK(Recyclables__c),".", " "&TEXT(Recyclables__c)& " recyclable items,")& " ", ",.", "" )
-
- Medhanie Habte
- October 01, 2015
- Like
- 0
- Continue reading or reply
Update Opportunity Amount for Recurring Subscriptions based on a currency field
I am trying to figure out a way to update the opportunity amount field to match a custom currency field that updates when a payment is made. My goal is for the amount field to match up with the custom currency (basically watching the field for any changes) and this would be contingent on if the recurring payment picklist field is set to recurring and the subscription end date is not greater than or does not equal TODAY. It would process on update.
I have attempted to do this via workflow, but this does not process during an APEX batch as the value is considered NULL. Any steps I can take. I trust this helps. I'll be looking around for ideas too.
-
- Medhanie Habte
- September 27, 2015
- Like
- 0
- Continue reading or reply
Trim first blank space in Contact Full Name Formula
Hope it helps.
-
- Medhanie Habte
- September 08, 2015
- Like
- 0
- Continue reading or reply
Creating a formula field for mail merges disambiguating between contacts and accounts
Currently my formula for the field is configured this way, I've created a concatenated formula in contact object which takes the first and last name and merges it into one. For instance First Name: Joe Last Name: Smith = Joe Smith
For the custom Object I've designed this formula in the field
IF(Account__r.Name = Contact__r.FullName__c , NULL,"Attn: " & Contact__r.FirstName & Contact__r.FullName__c)
However, at times, when I only input the last name and leave the first name field blank, in the instance that the contact does not have the first name, the Attention to formula returns a value when it should be blank.
Are there any customizations, I can make to my formula to make it so that even without the first name filled, it only returns when the account name and contact name do not match. IE Account Name SampleCO, Contact Joe Smith
Account Contact Attention to
-
- Medhanie Habte
- September 07, 2015
- Like
- 0
- Continue reading or reply
Utilize Apex Repeat to print multiple PDF pages
Greetings, I am looking to utilize Apex Repeat to be able to print multiple PDF pages based on the quantity field in the code below "<p>Quanity: {!relatedTo.Quantity__c}</p>".
This PDF file is part of an email, so I only enclosed the PDF code. Let me know which steps I need to take to make it possible. Hope it helps.
</messaging:htmlEmailBody> <messaging:attachment renderAs="PDF" filename="DonationReceipt"> <GMBLBC:barcode value="{!relatedTo.Tracking_Number__c}" displayText="true"/> <p></p> <p><h1><b>Donor Request Form</b></h1></p> <p>Organization Name: {!relatedTo.Organization_Name__c}</p> <p>Contact Name: {!relatedTo.First_Name__c} {!relatedTo.Last_Name__c}</p> <p>Shipping Address: {!relatedTo.Mailing_Street__c}, {!relatedTo.Mailing_City__c}, {!relatedTo.Mailing_State__c} {!relatedTo.Mailing_Postal_Code__c}</p> <p>Confirmation Number: {!relatedTo.Tracking_Number__c}</p> <p>Quanity: {!relatedTo.Quantity__c}</p> <p>Print this document and affix to your shipment, and mail to:</p> <table border="1" cellpadding="1" cellspacing="1" style="width:90%"> <tbody> <tr> <td><strong>General Products</strong></td> <td><strong>Quantity</strong></td> <td><strong>Handmade Items</strong></td> <td><strong>Quantity</strong></td> </tr> <tr> <td>CDs/DVDs</td> <td>{!relatedTo.CDs_DVDs__c}</td> <td>Scarves</td> <td>{!relatedTo.Scarves__c}</td> </tr> <tr> <td>Phone Cards</td> <td>{!relatedTo.Phone_Cards__c}</td> <td>Gators</td> <td>{!relatedTo.Gators__c}</td> </tr> <tr> <td>Girl Scout Cookies</td> <td>{!relatedTo.Girl_Scout_Cookies__c}</td> <td>Hats</td> <td>{!relatedTo.Hats__c}</td> </tr> <tr> <td>Beanie Babies</td> <td>{!relatedTo.Beanie_Babies__c}</td> <td>Cool-ties</td> <td>{!relatedTo.Cool_ties__c}</td> </tr> <tr> <td>Gift Cards</td> <td>{!relatedTo.Gift_Cards__c}</td> <td>Paracord Bracelets</td> <td>{!relatedTo.Paracords__c}</td> </tr> <tr> <td>Gift Card Value</td> <td>{!relatedTo.Gift_Card_Value__c}</td> <td> </td> <td> </td> </tr> <tr> <td><strong>Letters</strong></td> <td><strong>Quantity</strong></td> <td><strong>Other Items</strong></td> <td><strong>Quantity</strong></td> </tr> <tr> <td>Deployed Troops</td> <td>{!relatedTo.Deployed_Troops__c}</td> <td>Candy (lbs)</td> <td>{!relatedTo.Candy_lbs__c}</td> </tr> <tr> <td>New Recruits</td> <td>{!relatedTo.New_Recruits__c}</td> <td>Recyclables</td> <td>{!relatedTo.Recyclables__c}</td> </tr> <tr> <td>Veterans</td> <td>{!relatedTo.Veterans__c}</td> <td>Assorted Items</td> <td>{!relatedTo.Assorted_Items__c}</td> </tr> <tr> <td>Wounded Warriors</td> <td>{!relatedTo.Wounded_Warriors__c}</td> <td>Other Special Items</td> <td>{!relatedTo.Other_Special_Items__c}</td> </tr> </tbody> </table> <p>Addtional Details of Other Special Items: {!relatedTo.Description_of_Other_Special_Item__c}</p>
-
- Medhanie Habte
- July 05, 2015
- Like
- 0
- Continue reading or reply
Too Many SoQL queries 101
Any thing, I may need to adjust here.
public class eventsControllerTests { static testMethod void myPage_Test() { //Test converage for the myPage visualforce page PageReference pageRef = Page.Events_Home; Test.setCurrentPageReference(pageRef); // create an instance of the controller eventsController myPageCon = new eventsController(); //try calling methods/properties of the controller in all possible scenarios to get the best coverage. myPageCon.Setup(); String efSetupPage = myPageCon.Setup().getUrl(); System.assertEquals('/apex/EventsSuccess',efSetupPage); myPageCon.closePopupOK(); } static testMethod void testRegistrationsTrigger(){ //First, prepare 200 contacts for the test data String contactLastName = 'Apex'; String contactFirstName = 'Joe'; String contactTitle = 'Manager'; Contact ct = new Contact(lastname=contactLastName, firstname=contactFirstName, title=contactTitle); insert ct; ct = [SELECT Name, Title from Contact WHERE Id = :ct.Id]; Event__c ev = new Event__c(name = 'My Event'); insert ev; Event_Registration__c reg = new Event_Registration__c(Contact__c=ct.Id,Event__c=ev.Id); insert reg; reg = [SELECT Name_on_Badge__c, Title_On_Badge__c from Event_Registration__c WHERE Id = :reg.Id]; System.assertEquals(ct.Name, reg.Name_on_Badge__c); System.assertEquals(ct.Title, reg.Title_on_Badge__c); } }
-
- Medhanie Habte
- July 03, 2015
- Like
- 0
- Continue reading or reply
“Required fields are missing: [ProfileId]: [ProfileId]” when running Apex Class Test for ChatterAnswersAuthProviderRegTest
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]
I am curious to know where to go about obtaining the the id of a Chatter Answers Profile. I have attempted to call ProfileId though it appears the profile Id's I have available do not seem to allow. Or any steps I need to take.
@isTest(SeeAllData=True) private class ChatterAnswersAuthProviderRegTest { static testMethod void validateCreateUpdateUser() { User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ]; System.runAs ( thisUser ) { Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast', 'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook', null, new Map<String, String>{'language' => 'en_US'}); ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration(); Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1]; reg.setSiteAdminUserId(adminUser[0].Id); User newUser = reg.createUser(null, userData); System.assert(newUser != null, 'A new user should have been created'); System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same'); System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same'); System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same'); Contact c = new Contact(); c.AccountId = (newUser.Username.split('@'))[0]; c.LastName = 'contactLast'; insert(c); newUser.Alias = 'firstusr'; newUser.TimeZoneSidKey = 'America/Los_Angeles'; newUser.LocaleSidKey = 'en_US'; newUser.EmailEncodingKey = 'UTF-8'; newUser.LanguageLocaleKey = 'en_US'; newUser.ContactId = c.Id; insert(newUser); Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast', 'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook', null, new Map<String, String>{'language' => 'en_US'}); reg.updateUser(newUser.Id, null, updateUserData); User dbUser = [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id]; System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated'); System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated'); System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated'); } } }
-
- Medhanie Habte
- July 02, 2015
- Like
- 0
- Continue reading or reply
Override Contact Lookup with Visualforce page
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
I have configured it successfully with the contact object in mind, customizing the code to enable it to work with the contact object, having the ability to create records within the vf page. Everything works well.
A couple of questions I am wondering about expanding its implementation and expansion. I will include the current code, I have below.
1. One of the things, I am attempting to determine is if it is possible to override the current contact quick create/lookup page. When a user clicks the magnifying glass on a certain object, are they then able to taken to the corresponding visualforce. I've heard historically, this may not be possible, so I'll understand if that is the case. But if so, what are the best methods to implement.
2. More so, I am working on an application that will be utilizing such a lookup, I am wondering if there is a way to incorporate as a visualpage within the object or a field to essentially update the related contact lookup field within the object.
Many thanks for all your help.
VF PAGE
<apex:page controller="ContactLookupControl" title="Search" showHeader="false" sideBar="false" tabStyle="Contact" id="pg"> <apex:form > <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel"> <!-- SEARCH TAB --> <apex:tab label="Search" name="tab1" id="tabOne"> <apex:actionRegion > <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/> <apex:inputText id="txtSearch" value="{!searchString}" /> <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span> </apex:outputPanel> <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block"> <apex:pageBlock id="searchResults"> <apex:pageBlockTable value="{!results}" var="a" id="tblResults"> <apex:column > <apex:facet name="header"> <apex:outputPanel >Name</apex:outputPanel> </apex:facet> <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink> </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Account Name</apex:outputPanel> </apex:facet> {!a.Account.Name} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Street</apex:outputPanel> </apex:facet> {!a.MailingStreet} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >City</apex:outputPanel> </apex:facet> {!a.MailingCity} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >State</apex:outputPanel> </apex:facet> {!a.MailingState} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Postal Code</apex:outputPanel> </apex:facet> {!a.MailingPostalCode} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Phone</apex:outputPanel> </apex:facet> {!a.Phone} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Email</apex:outputPanel> </apex:facet> {!a.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:actionRegion> </apex:tab> <!-- NEW CONTACT TAB --> <apex:tab label="New Contact" name="tab2" id="tabTwo"> <apex:pageBlock id="newContact" title="New Contact" > <apex:pageBlockButtons > <apex:commandButton action="{!saveContact}" value="Save"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection columns="2"> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField value="{!Contact.LastName}"/> <apex:inputField value="{!Contact.AccountId}"/> <apex:inputField value="{!Contact.MailingStreet}"/> <apex:inputField value="{!Contact.MailingCity}"/> <apex:inputField value="{!Contact.MailingState}"/> <apex:inputField value="{!Contact.MailingPostalCode}"/> <apex:inputField value="{!Contact.MailingCountry}"/> <apex:inputField value="{!Contact.Phone}"/> <apex:inputField value="{!Contact.Email}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page>
Apex Class
public class ContactLookupControl { public Contact contact {get;set;} // new contact to create public List<Contact> results{get;set;} // search results public string searchString{get;set;} // search keyword public ContactLookupControl() { contact = new Contact(); // get the current search string searchString = System.currentPageReference().getParameters().get('lksrch'); runSearch(); } // performs the keyword search public PageReference search() { runSearch(); return null; } // prepare the query and issue the search command private void runSearch() { // TODO prepare query string for complex serarches & prevent injections results = performSearch(searchString); } // run the search and return the records found. private List<Contact> performSearch(string searchString) { String soql = 'select id, name,account.Name,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact'; if(searchString != '' && searchString != null) soql = soql + ' where name LIKE \'%' + searchString +'%\''; soql = soql + ' limit 25'; System.debug(soql); return database.query(soql); } // save the new contact record public PageReference saveContact() { insert contact; // reset the contact contact = new Contact(); return null; } // used by the visualforce page to send the link to the right dom element public string getFormTag() { return System.currentPageReference().getParameters().get('frm'); } // used by the visualforce page to send the link to the right dom element for the text box public string getTextBox() { return System.currentPageReference().getParameters().get('txt'); } }
-
- Medhanie Habte
- June 21, 2015
- Like
- 0
- Continue reading or reply
Enabling Apex Classes to search for more fields
Hi all, I've been working on this visualforce lookup page, to successful results. I've modified to to specific work with the contact object with great success and a 76% pass rate in apex tests.
The page is modeled after this blog and is for a custom app/object we are building
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
One of the things we are looking to do is include additional columns for contact fields specific to a search result. I have been able to successfully replicate this result with the contact name, appearing in two tables.
However, I am trying to figure out a way to enable results for additional fields within the contact object, allowing the second column to reveal other fields such as address, account etc. Ideally, I envision that there would be columns for account, mailing street, phone and email.
I'd love to know more about how to achieve enhancing my Soql results.
Currently, here is how my code is configured.
APEX CLASS
public class ContactLookupControl {
public Contact contact {get;set;} // new contact to create
public List<Contact> results{get;set;} // search results
public string searchString{get;set;} // search keyword
public ContactLookupControl() {
contact = new Contact();
// get the current search string
searchString = System.currentPageReference().getParameters().get('lksrch');
runSearch();
}
// performs the keyword search
public PageReference search() {
runSearch();
return null;
}
// prepare the query and issue the search command
private void runSearch() {
// TODO prepare query string for complex serarches & prevent injections
results = performSearch(searchString);
}
// run the search and return the records found.
private List<Contact> performSearch(string searchString) {
String soql = 'select id, name from contact';
if(searchString != '' && searchString != null)
soql = soql + ' where name LIKE \'%' + searchString +'%\'';
soql = soql + ' limit 25';
System.debug(soql);
return database.query(soql);
}
// save the new contact record
public PageReference saveContact() {
insert contact;
// reset the contact
contact = new Contact();
return null;
}
// used by the visualforce page to send the link to the right dom element
public string getFormTag() {
return System.currentPageReference().getParameters().get('frm');
}
// used by the visualforce page to send the link to the right dom element for the text box
public string getTextBox() {
return System.currentPageReference().getParameters().get('txt');
}
VF PAGE
<apex:page controller="ContactLookupControl"
title="Search"
showHeader="false"
sideBar="false"
tabStyle="Contact"
id="pg">
<apex:form >
<apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
<apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">
<!-- SEARCH TAB -->
<apex:tab label="Search" name="tab1" id="tabOne">
<apex:actionRegion >
<apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
<apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/>
<apex:inputText id="txtSearch" value="{!searchString}" />
<span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span>
</apex:outputPanel>
<apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
<apex:pageBlock id="searchResults">
<apex:pageBlockTable value="{!results}" var="a" id="tblResults">
<apex:column >
<apex:facet name="header">
<apex:outputPanel >Name</apex:outputPanel>
</apex:facet>
<apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:outputPanel >Name</apex:outputPanel>
</apex:facet>
<apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:actionRegion>
</apex:tab>
<!-- NEW CONTACT TAB -->
<apex:tab label="New Contact" name="tab2" id="tabTwo">
<apex:pageBlock id="newContact" title="New Contact" >
<apex:pageBlockButtons >
<apex:commandButton action="{!saveContact}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<apex:pageBlockSection columns="2">
<apex:inputField value="{!Contact.FirstName}"/>
<apex:inputField value="{!Contact.LastName}"/>
<apex:inputField value="{!Contact.AccountId}"/>
<apex:inputField value="{!Contact.MailingStreet}"/>
<apex:inputField value="{!Contact.MailingCity}"/>
<apex:inputField value="{!Contact.MailingState}"/>
<apex:inputField value="{!Contact.MailingPostalCode}"/>
<apex:inputField value="{!Contact.MailingCountry}"/>
<apex:inputField value="{!Contact.Phone}"/>
<apex:inputField value="{!Contact.Email}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:tab>
</apex:tabPanel>
</apex:outputPanel>
</apex:form>
</apex:page>
-
- Medhanie Habte
- June 20, 2015
- Like
- 0
- Continue reading or reply
Alternatives to Quick Create
I'm looking to figure a way to replace quick create by creating a visualforce page which would enable me to enter contact or account data that is linked to the opportunity object or other pertinent objects. I am aware that the QuickCreate functionality isn't the best and should not be used in any circumstances, however, I am using a GridBuddy type applicable that pulls Accounts and Contacts as lookups and includes the quick create option, which is ideal for an opportunity that doesn't have ties to an account in Salesforce.
-
- Medhanie Habte
- June 05, 2015
- Like
- 0
- Continue reading or reply
Including commas and and's in formula for combining line items
I have a formula field that I built in a custom object that combines various fields into this one field for a mail merge. The custom object is called Product Donations, and there are about 12 fields referencing various line items that are referenced here.
SUBSTITUTE( IF(ISBLANK(NEW_Letters__c),"", Letter_Count__c) &IF(ISBLANK(Gators__c),""," "&TEXT(Gators__c) & " handmade gators,") &IF(ISBLANK(Paracords__c),"", " "&TEXT(Paracords__c) & " paracord bracelets,") &IF(ISBLANK(Cool_Ties__c),"", " "&TEXT(Cool_Ties__c) & " handmade cool ties,") &IF(ISBLANK(Phone_Cards__c),"", " "&TEXT(Phone_Cards__c) & " phone cards,") &IF(ISBLANK(Battalion_Buddy__c),"", " "&TEXT(Battalion_Buddy__c) & " battalion buddies,") &IF(ISBLANK(Comic_Books__c),"", " comic books,") &IF(ISBLANK(Magazines__c),"", " magazines,") &IF(ISBLANK(Books__c),"", " books,") &IF(ISBLANK(Handmade_Cards__c),"", " handmade cards,") &IF(ISBLANK(Care_Kits__c),""," care kits,") &IF(ISBLANK(Gift_Cards__c),""," gift cards,") &IF(ISBLANK(Socks__c),"", " socks,") &IF(ISBLANK(Girl_Scout_Cookies__c),"", " "&TEXT(Girl_Scout_Cookies__c) & " boxes of Girl Scout cookies,") &IF(ISBLANK(Food_And_Snacks__c),"", " snack foods,") &IF(ISBLANK(Toys_Animals_Bears__c),""," assorted toys,") &IF(ISBLANK(Beanie_Babies__c),"", " "&TEXT(Beanie_Babies__c)& " Beanie Babies,") &IF(ISBLANK(Hats__c),"", " "&TEXT(Hats__c) & " handmade hats," ) &IF(ISBLANK(Scarves__c),"", " "&TEXT(Scarves__c)& " handmade scarves,") &IF(ISBLANK(Video_Games__c),"", " "&TEXT(Video_Games__c)& " video games,") &IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(CDs_DVDs__c)& " CD's,") &IF(ISBLANK(CDs_DVDs__c),"", " "&TEXT(DVDs__c)& " DVD's,") &IF(ISBLANK(Candy_lbs__c),"", " "&TEXT(Candy_lbs__c)& " Lbs of candy,") &IF(ISBLANK(Assorted_Items__c),""," assorted items,") &IF(ISBLANK(Recyclables__c),"", " recyclable items,")& " ", ",.", "" )
On the letter count, if there are additional itmes, I notice that a comma does not appear after it, it reads for example letters 1 scarves, 20 paracords, assorted items. Additionally, I am also looking for a way to include the word "and" after the comma if multiple line items exist. In this case, it should read as
letters 1 scarves, 20 paracords and assorted items.
Instead of
letters 1 scarves, 20 paracords, assorted items
Also is there a formula to singularize items that have a 1 in it. For instance 1 scarves should just say scarf.
I can help with any further questions, even set up a trigger if needed.
Hope this helps.
- Medhanie Habte
- May 11, 2016
- Like
- 0
- Continue reading or reply
Creating a formula to compare date values that don't match
IF(npo02__FirstCloseDate__c <> Account.npe01__FirstDonationDate__c, IF(npo02__FirstCloseDate__c < Account.npe01__FirstDonationDate__c, npo02__FirstCloseDate__c, IF(npo02__FirstCloseDate__c > Account.npe01__FirstDonationDate__c, Account.npe01__FirstDonationDate__c ,npo02__FirstCloseDate__c )))However, I get this error message reading Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 2.
Any thing I'm missing. Hope it helps.
- Medhanie Habte
- December 11, 2015
- Like
- 0
- Continue reading or reply
Adding a formula field that populates based on two if statements
IF(Account.Name <> Contact.Full_Name__c) and IF(Donor_Type__c !="Individual") then Product_Donations_Summary__c = "Greetings from Us", Dear+Contact.First_Name__c
Hope it helps.
- Medhanie Habte
- October 19, 2015
- Like
- 0
- Continue reading or reply
Writing a trigger to sort a concatenated formula field by numerical value
trigger ProductDonationsSummary on Product_Donations__c (before insert) { Map<Integer, String> mapNumValueAndFieldLabel = new Map<Integer,String>(); String strMessage; //null checkers for the field and adding the number value as key and the string message as the value if its not null/blank/zero IF(Total_LettersTally__c != null && Total_LettersTally__c != '' && Integer.valueOf(Total_LettersTally__c) != 0) mapNumValueAndFieldLabel.put(Integer.valueOf(Total_LettersTally__c), Total_LettersTally__c + " letters"); IF(Gators__c != null && Gators__c != '' && Integer.valueOf(Gators__c) != 0) mapNumValueAndFieldLabel.put(Integer.valueOf(Gators__c), Gators__c + " Gators"); IF(Paracords__c != null && Paracords__c != '' && Integer.valueOf(Paracords__c) != 0) mapNumValueAndFieldLabel.put(Integer.valueOf(Paracords__c), Paracords__c + " paracord bracelets"); //and so on for other fields.... //Proceed further only if either of the fields have non zero values if(mapNumValueAndFieldLabel.values().size() > 0) { List<Integer> lstNumValue = new List<integer> (); lstNumValue.addAll(mapNumValueAndFieldLabel.keyset()); //Sort the Values (by default SFDC sorts it in ascending order) lstNumValue.sort(); //Iterating through the sorted Integer list in reverse order (descending) to get the final String message from the map for(Integer i = lstNumValue.size()-1; i >= 0; i--) { strMessage = mapNumValueAndFieldLabel.get(lstNumValue(i)) + ", "; } } //strMessage will hold the message you want to display }
- Medhanie Habte
- October 15, 2015
- Like
- 0
- Continue reading or reply
Unable to close visualforce popup after record has been created
One of the initial issue we have encountered is the inability to look up or add contact records with quotes (') in their first or last name as part of the query. This returns an exception error. A step I took to address was to escapesinglequote, which allows for looking up contacts with ('). Now with Single Quote escaped, I am unable to close the popup when I create new records or select a record with a (') in the result. I'm certain this may have to do with the code in the VF page. I am wondering what steps I need to take.
Are there any steps, I can take to address. Class and Page attached below.
Class
public class ContactLookupControl { public Contact contact {get;set;} // new contact to create public List<Contact> results{get;set;} // search results public string searchString{get;set;} // search keyword public ContactLookupControl() { contact = new Contact(); // get the current search string searchString = System.currentPageReference().getParameters().get('lksrch'); runSearch(); } // performs the keyword search public PageReference search() { runSearch(); return null; } // prepare the query and issue the search command private void runSearch() { // TODO prepare query string for complex serarches & prevent injections results = performSearch(searchString); } // run the search and return the records found. private List<Contact> performSearch(string searchString) { String soql = 'select id, name,account.Name,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact'; if(searchString != '' && searchString != null) soql = soql + ' where name LIKE \'%' + searchString +'%\''; soql = soql + ' limit 25'; System.debug(soql); return database.query(soql); } // save the new contact record public PageReference saveContact() { insert contact; contact=[select id,name,FirstName,LastName,AccountId,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact where id=:contact.id]; // reset the contact //contact = new Contact(); return null; } // used by the visualforce page to send the link to the right dom element public string getFormTag() { return System.currentPageReference().getParameters().get('frm'); } // used by the visualforce page to send the link to the right dom element for the text box public string getTextBox() { return System.currentPageReference().getParameters().get('txt'); } }
Page
<apex:page controller="ContactLookupControl" title="Search" showHeader="false" sideBar="false" tabStyle="Contact" id="pg"> <apex:form > <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel"> <!-- SEARCH TAB --> <apex:tab label="Search" name="tab1" id="tabOne"> <apex:actionRegion > <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/> <apex:inputText id="txtSearch" value="{!searchString}" /> <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span> </apex:outputPanel> <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block"> <apex:pageBlock id="searchResults"> <apex:pageBlockTable value="{!results}" var="a" id="tblResults"> <apex:column > <apex:facet name="header"> <apex:outputPanel >Name</apex:outputPanel> </apex:facet> <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false);self.close();" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink> </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Account Name</apex:outputPanel> </apex:facet> {!a.Account.Name} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Street</apex:outputPanel> </apex:facet> {!a.MailingStreet} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >City</apex:outputPanel> </apex:facet> {!a.MailingCity} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >State</apex:outputPanel> </apex:facet> {!a.MailingState} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Postal Code</apex:outputPanel> </apex:facet> {!a.MailingPostalCode} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Phone</apex:outputPanel> </apex:facet> {!a.Phone} </apex:column> <apex:column > <apex:facet name="header"> <apex:outputPanel >Email</apex:outputPanel> </apex:facet> {!a.Email} </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:actionRegion> </apex:tab> <!-- NEW CONTACT TAB --> <apex:tab label="New Contact" name="tab2" id="tabTwo"> <apex:pageBlock id="newContact" title="New Contact" > <apex:pageBlockButtons > <apex:commandButton action="{!saveContact}" value="Save & Close"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection columns="2"> <apex:inputField value="{!Contact.FirstName}"/> <apex:inputField value="{!Contact.LastName}"/> <apex:inputField value="{!Contact.AccountId}"/> <apex:inputField value="{!Contact.MailingStreet}"/> <apex:inputField value="{!Contact.MailingCity}"/> <apex:inputField value="{!Contact.MailingState}"/> <apex:inputField value="{!Contact.MailingPostalCode}"/> <apex:inputField value="{!Contact.MailingCountry}"/> <apex:inputField value="{!Contact.Phone}"/> <apex:inputField value="{!Contact.Email}"/> </apex:pageBlockSection> </apex:pageBlock> <script> if({!Contact.id!=null}){ //alert('{!Contact.Name} {!Contact.id}'); top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!Contact.Id}','{!Contact.Name}', false);self.close(); } </script> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page>
Hope it helps.
- MedhanieHabte
- October 09, 2015
- Like
- 0
- Continue reading or reply
Update Opportunity Amount for Recurring Subscriptions based on a currency field
I am trying to figure out a way to update the opportunity amount field to match a custom currency field that updates when a payment is made. My goal is for the amount field to match up with the custom currency (basically watching the field for any changes) and this would be contingent on if the recurring payment picklist field is set to recurring and the subscription end date is not greater than or does not equal TODAY. It would process on update.
I have attempted to do this via workflow, but this does not process during an APEX batch as the value is considered NULL. Any steps I can take. I trust this helps. I'll be looking around for ideas too.
- Medhanie Habte
- September 27, 2015
- Like
- 0
- Continue reading or reply
Creating a time zone formula for accounts
I'm pretty new to salesforce and formulas so forgive me if I'm missing something obvious. I'm trying to use a formula that will allow me to run reports on accounts sorted by their time zone. This is my formula:
IF(CASE(State, “California”, 1, “Nevada”, 1, “Oregon”, 1, “Washington”, 1, 0) >=1, “Pacific”, null)+
IF(CASE(State, “Arizona”, 1, “Colorado”, 1, “Idaho, 1, “Montana”, 1, “New Mexico”, 1, “Utah”, 1, “Wyoming”, 1, 0) >= 1, “Mountain”, null)+
IF(CASE(State, “Alabama”, 1, “Arkansas”, 1, “Illinois”, 1, “Iowa”, 1, “Kansas”, 1, “Louisiana”, 1, “Minnesota”, 1, “Mississippi”, 1, “Missouri”, 1, “Nebraska”, 1, “North Dakota”, 1, “Oklahoma”, 1, “South Dakota”, 1, “Tennessee”, 1, “Texas”, 1, “Wisconsin”, 1, 0) >= 1, “Central”, null)+
IF(CASE(State, “Connecticut”, 1, “Delaware”, 1, “Florida”, 1, “Georgia”, 1, “Indiana”, 1, “Kentucky”, 1, “Maine”, 1, “Maryland”, 1, “Massachusetts”, 1, “Michigan”, 1, “New Hampshire”, 1, “New Jersey”, 1, “New York”, 1, “North Carolina”, 1, “Ohio”, 1, “Pennsylvania”, 1, “Rhode Island”, 1, “South Carolina”, 1, “Vermont”, 1, “Virginia”, 1, “West Virginia”, 1, 0) >= 1,”Eastern”, null)+
IF(CASE(State, “Alaska”, 1, 0) >=1, “Alaskan”, null)+
IF(CASE(State, “Hawaii”, 1, 0) >=1, “Hawaiian”, null)+
IF(CASE(BillingState, “California”, 1, “Nevada”, 1, “Oregon”, 1, “Washington”, 1, “CA”, 1, “NV”, 1,”OR”, 1, “WA”, 1, 0) >=1, “Pacific”, null)+
IF(CASE(BillingState, “Arizona”, 1, “Colorado”, 1, “Idaho, 1, “Montana”, 1, “New Mexico”, 1, “Utah”, 1, “Wyoming”, 1,“AZ”, 1, “CO”, 1,”ID”, 1, “MT”, 1, “NM”, 1, “UT”, 1, “WY”, 1, 0) >= 1, “Mountain”, null)+
IF(CASE(BillingState, “Alabama”, 1, “Arkansas”, 1, “Illinois”, 1, “Iowa”, 1, “Kansas”, 1, “Louisiana”, 1, “Minnesota”, 1, “Mississippi”, 1, “Missouri”, 1, “Nebraska”, 1, “North Dakota”, 1, “Oklahoma”, 1, “South Dakota”, 1, “Tennessee”, 1, “Texas”, 1, “Wisconsin”, 1, “AL”, 1, “AR”, 1, “IL”, 1, “IA”, 1,”KS”, 1, “LA”, 1,”MN”, 1,”MS”, 1,”MO”, 1,”NE”, 1,”ND”, 1, “OK”, 1,”SD”, 1, “TN”, 1, “TX”, 1,”WI”, 1, 0) >= 1, “Central”, null)+
IF(CASE(BillingState, “Connecticut”, 1, “Delaware”, 1, “Florida”, 1, “Georgia”, 1, “Indiana”, 1, “Kentucky”, 1, “Maine”, 1, “Maryland”, 1, “Massachusetts”, 1, “Michigan”, 1, “New Hampshire”, 1, “New Jersey”, 1, “New York”, 1, “North Carolina”, 1, “Ohio”, 1, “Pennsylvania”, 1, “Rhode Island”, 1, “South Carolina”, 1, “Vermont”, 1, “Virginia”, 1, “West Virginia”, 1, “CT”, 1, “DE”, 1, “FL”, 1,“GA”, 1, “IN”, 1, “KY”, 1,“ME”, 1, “MD”, 1, “MA”, 1,”MI”, 1, “NH”, 1, “NJ”, 1, “NY”, 1, “NC”, 1, “OH”, 1, “PA”, 1, “RI”, 1, “SC”, 1, “VT”, 1, “VA”, 1, “WV”, 1, 0) >= 1,”Eastern”, null)+
IF(CASE(BillingState, “Alaska”, 1,“AK”, 1, 0) >=1, “Alaskan”, null)+
IF(CASE(BillingState, “Hawaii”, 1,“HI”, 1, 0) >=1, “Hawaiian”, null)+
I keep running into a syntax error when I test it. It highlights "California",
Is my formula incorrect? What am I doing incorrectly?
Regards,
Jeff
- Jeff Sherwood
- September 24, 2015
- Like
- 0
- Continue reading or reply
Trim first blank space in Contact Full Name Formula
Hope it helps.
- Medhanie Habte
- September 08, 2015
- Like
- 0
- Continue reading or reply
Creating a formula field for mail merges disambiguating between contacts and accounts
Currently my formula for the field is configured this way, I've created a concatenated formula in contact object which takes the first and last name and merges it into one. For instance First Name: Joe Last Name: Smith = Joe Smith
For the custom Object I've designed this formula in the field
IF(Account__r.Name = Contact__r.FullName__c , NULL,"Attn: " & Contact__r.FirstName & Contact__r.FullName__c)
However, at times, when I only input the last name and leave the first name field blank, in the instance that the contact does not have the first name, the Attention to formula returns a value when it should be blank.
Are there any customizations, I can make to my formula to make it so that even without the first name filled, it only returns when the account name and contact name do not match. IE Account Name SampleCO, Contact Joe Smith
Account Contact Attention to
- Medhanie Habte
- September 07, 2015
- Like
- 0
- Continue reading or reply
Too Many SoQL queries 101
Any thing, I may need to adjust here.
public class eventsControllerTests { static testMethod void myPage_Test() { //Test converage for the myPage visualforce page PageReference pageRef = Page.Events_Home; Test.setCurrentPageReference(pageRef); // create an instance of the controller eventsController myPageCon = new eventsController(); //try calling methods/properties of the controller in all possible scenarios to get the best coverage. myPageCon.Setup(); String efSetupPage = myPageCon.Setup().getUrl(); System.assertEquals('/apex/EventsSuccess',efSetupPage); myPageCon.closePopupOK(); } static testMethod void testRegistrationsTrigger(){ //First, prepare 200 contacts for the test data String contactLastName = 'Apex'; String contactFirstName = 'Joe'; String contactTitle = 'Manager'; Contact ct = new Contact(lastname=contactLastName, firstname=contactFirstName, title=contactTitle); insert ct; ct = [SELECT Name, Title from Contact WHERE Id = :ct.Id]; Event__c ev = new Event__c(name = 'My Event'); insert ev; Event_Registration__c reg = new Event_Registration__c(Contact__c=ct.Id,Event__c=ev.Id); insert reg; reg = [SELECT Name_on_Badge__c, Title_On_Badge__c from Event_Registration__c WHERE Id = :reg.Id]; System.assertEquals(ct.Name, reg.Name_on_Badge__c); System.assertEquals(ct.Title, reg.Title_on_Badge__c); } }
- Medhanie Habte
- July 03, 2015
- Like
- 0
- Continue reading or reply
“Required fields are missing: [ProfileId]: [ProfileId]” when running Apex Class Test for ChatterAnswersAuthProviderRegTest
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [ProfileId]: [ProfileId]
I am curious to know where to go about obtaining the the id of a Chatter Answers Profile. I have attempted to call ProfileId though it appears the profile Id's I have available do not seem to allow. Or any steps I need to take.
@isTest(SeeAllData=True) private class ChatterAnswersAuthProviderRegTest { static testMethod void validateCreateUpdateUser() { User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ]; System.runAs ( thisUser ) { Auth.UserData userData = new Auth.UserData('testId', 'testFirst', 'testLast', 'testFirst testLast', 'no-reply@salesforce.com', null, 'testuserlong', 'en_US', 'facebook', null, new Map<String, String>{'language' => 'en_US'}); ChatterAnswersAuthProviderRegistration reg = new ChatterAnswersAuthProviderRegistration(); Profile[] p = [SELECT Id FROM Profile WHERE Name = 'System Administrator']; User[] adminUser = [SELECT Id, Firstname, Lastname FROM User WHERE IsActive = true and ProfileId =: p[0].Id LIMIT 1]; reg.setSiteAdminUserId(adminUser[0].Id); User newUser = reg.createUser(null, userData); System.assert(newUser != null, 'A new user should have been created'); System.assertEquals(newUser.Firstname, 'testFirst', 'First name should have been same'); System.assertEquals(newUser.Lastname, 'testLast', 'Last name should have been same'); System.assertEquals(newUser.Email, 'no-reply@salesforce.com', 'Email should have been same'); Contact c = new Contact(); c.AccountId = (newUser.Username.split('@'))[0]; c.LastName = 'contactLast'; insert(c); newUser.Alias = 'firstusr'; newUser.TimeZoneSidKey = 'America/Los_Angeles'; newUser.LocaleSidKey = 'en_US'; newUser.EmailEncodingKey = 'UTF-8'; newUser.LanguageLocaleKey = 'en_US'; newUser.ContactId = c.Id; insert(newUser); Auth.UserData updateUserData = new Auth.UserData('testId', 'updatedFirst', 'updatedLast', 'updatedFirst updatedLast', 'no-reply@new.salesforce.com', null, 'testuserlong', 'en_US', 'facebook', null, new Map<String, String>{'language' => 'en_US'}); reg.updateUser(newUser.Id, null, updateUserData); User dbUser = [SELECT Id, Firstname, Lastname, Email FROM User WHERE Id = :newUser.Id]; System.assertEquals(dbUser.Firstname, 'updatedFirst', 'First name should have been updated'); System.assertEquals(dbUser.Lastname, 'updatedLast', 'Last name should have been updated'); System.assertEquals(dbUser.Email, 'no-reply@new.salesforce.com', 'Email should have been updated'); } } }
- Medhanie Habte
- July 02, 2015
- Like
- 0
- Continue reading or reply
Improve Apex Code Coverage
Here is an instance of my apex class itself
APEX CLASS
public class ContactLookupControl {
public Contact contact {get;set;} // new contact to create
public List<Contact> results{get;set;} // search results
public string searchString{get;set;} // search keyword
public ContactLookupControl() {
contact = new Contact();
// get the current search string
searchString = System.currentPageReference().getParameters().get('lksrch');
runSearch();
}
// performs the keyword search
public PageReference search() {
runSearch();
return null;
}
// prepare the query and issue the search command
private void runSearch() {
// TODO prepare query string for complex serarches & prevent injections
results = performSearch(searchString);
}
// run the search and return the records found.
private List<Contact> performSearch(string searchString) {
String soql = 'select id, name from contact';
if(searchString != '' && searchString != null)
soql = soql + ' where name LIKE \'%' + searchString +'%\'';
soql = soql + ' limit 25';
System.debug(soql);
return database.query(soql);
}
// save the new contact record
public PageReference saveContact() {
insert contact;
// reset the contact
contact = new Contact();
return null;
}
// used by the visualforce page to send the link to the right dom element
public string getFormTag() {
return System.currentPageReference().getParameters().get('frm');
}
// used by the visualforce page to send the link to the right dom element for the text box
public string getTextBox() {
return System.currentPageReference().getParameters().get('txt');
}
}
Here's the test class too
TEST CLASS
@isTest
public class ContactLookupControlTest {
static testMethod void validateContactLookupControl() {
Contact c = new Contact();
c.FirstName = 'Paul';
c.LastName = 'Reid';
c.MailingStreet = '205 Hill Street';
c.MailingCity = 'Los Angeles';
c.MailingState = 'CA';
c.MailingPostalCode = '90015';
c.Email = 'testingout1@aol.com';
insert c;
}
}
Are there any additional steps I can pursue to enable it to work accordingly. Let me know and hope it helps.
- MedhanieHabte
- June 20, 2015
- Like
- 0
- Continue reading or reply