• BenP
  • NEWBIE
  • 120 Points
  • Member since 2008

  • Chatter
    Feed
  • 3
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 57
    Questions
  • 128
    Replies
I have been trying to recycle some code that I used to show a related list on a record, but I've hit the limit of my knowledge (I'm not a real developer).

My goal is to have a button on an opportunity that will take the user to a VF page that shows all related files, but allows them to see more columns than the standard SF page.

This is the page and extension I'm fumbling with.  The query works for sure, but all I'm now seeing any data on the page.  It's like I'm not calling the method correctly.  I'm using this url to pass in the oppID parameter, /apex/OpportunityFiles?oppID=0062F000002nIy8QAE

Page
<apex:page standardController="ContentDocumentLink" extensions="OpportunityFilesExtension" >

<apex:pageBlock title="Files">
   <apex:pageBlockTable value="{!oppFiles}" var="contact">
      <apex:column value="{!contact.ContentDocument.Title}"/>
      
       <apex:column > 
            <apex:facet name="header">Title</apex:facet>
            <apex:outputText value="{!contact.ContentDocument.Title}"></apex:outputText>
        </apex:column>
   </apex:pageBlockTable>
</apex:pageBlock>
    
</apex:page>

Extension
public class OpportunityFilesExtension {

    //public List<ContentDocumentLink> oppFiles = new List<ContentDocumentLink>();
    public List<ContentDocumentLink> oppFiles {get; set;}
    
    public string oppID {get; set;} //holder for passed in Opp ID
    
    public OpportunityFilesExtension(ApexPages.StandardController controller) {
        
    oppID = ApexPages.currentPage().getParameters().get('oppID');
    system.debug('oppID is '+oppID);
    }
    
    //public OpportunityFiles(ApexPages.StandardController controller) {
      //  this.opp= (Opportunity)controller.getRecord(); //get the ID of the current opportunity
    //}
    public List<ContentDocumentLink> getFiles()
    {
         system.debug('oppID in getFiles is '+oppID);
        if (oppID == null)
         return null;
        
        
        oppFiles = [SELECT ContentDocumentId,Id,LinkedEntityId, ContentDocument.Title, 
					ContentDocument.ContentSize, ContentDocument.Description, 
					ContentDocument.FileExtension, ContentDocument.Owner.Name, 
					ContentDocument.LatestPublishedVersionId 
					FROM ContentDocumentLink WHERE LinkedEntityId = :oppID AND ContentDocument.FileExtension != 'snote'
					limit 5 ];
                  
        return oppFiles;
    }
}

 
  • January 11, 2018
  • Like
  • 0
I have a force.com site that uses a custom controller.  I'm getting very random unhandled exception error issues and finally caught a log today.  The strange part is that it's coming from a section that shouldn't even run since it's inside an IF statement.  Any reason this section would execute? 

IF statement that seems to be executing:
if( wo != null ){
                    system.debug('new wo is '+wo.Id);
                    objWO1 = [Select Id, Name From Work_Orders__c Where Id=:wo.Id];
                    //system.debug('Inside new work order*************'+objWO1.Name);
                    //system.debug('Inside Id*************'+objWO1.Id);
                    woParam = objWO1.Id;
                    woParamName = objWO1.Name;

Here's a debug log snippet.  The above code starts at line 666 for reference.  You can see that it shouldn't run if wo == null, but the debug shows that it did.
 
15:51:57.0 (1469874893)|SYSTEM_METHOD_ENTRY|[666]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1469956278)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"acc":"0x30c3a1ee","accId":"0017000001RadedAAB","accNumber":"be671044","attfile":true,"count":0,"doAction":true,"existWO":"0x680d323e","goodPrefix":true,"lstDTOWOP":"0xa427ac2","lstExistingWOP":"0x34d35062","lstTempWOP":"0x1325b05e","mapExistingWOP":"0x3ec4bf05","mProduct":"0x19514e6d","newwo":false,"newworkorder":false,"nonExistingPrdName":"0x27c95675","partused":true,"prdNameMap":"0x9b742ae","productNameSet":"0x37aea486","reason":false,"serviceteamName":"MID-SOUTH MAINTENANC (7 more) ...","showWOD":true,"TargetLineRecordType":"0x2c0919e1","topPnl":false,"wo":"0x411e98eb","WOName":"wo-00635724","WORecordType":"0x720f0054","workorder":"0x30470007"}|0x5a62d92d
15:51:57.0 (1469968317)|SYSTEM_METHOD_EXIT|[666]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1469972333)|STATEMENT_EXECUTE|[666]
15:51:57.0 (1469973796)|STATEMENT_EXECUTE|[667]
15:51:57.0 (1469978048)|HEAP_ALLOCATE|[667]|Bytes:10
15:51:57.0 (1469985060)|SYSTEM_METHOD_ENTRY|[667]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470063224)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"acc":"0x30c3a1ee","accId":"0017000001RadedAAB","accNumber":"be671044","attfile":true,"count":0,"doAction":true,"existWO":"0x680d323e","goodPrefix":true,"lstDTOWOP":"0xa427ac2","lstExistingWOP":"0x34d35062","lstTempWOP":"0x1325b05e","mapExistingWOP":"0x3ec4bf05","mProduct":"0x19514e6d","newwo":false,"newworkorder":false,"nonExistingPrdName":"0x27c95675","partused":true,"prdNameMap":"0x9b742ae","productNameSet":"0x37aea486","reason":false,"serviceteamName":"MID-SOUTH MAINTENANC (7 more) ...","showWOD":true,"TargetLineRecordType":"0x2c0919e1","topPnl":false,"wo":"0x411e98eb","WOName":"wo-00635724","WORecordType":"0x720f0054","workorder":"0x30470007"}|0x5a62d92d
15:51:57.0 (1470075680)|SYSTEM_METHOD_EXIT|[667]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470095580)|SYSTEM_METHOD_ENTRY|[667]|String.valueOf(Object)
15:51:57.0 (1470105725)|SYSTEM_METHOD_EXIT|[667]|String.valueOf(Object)
15:51:57.0 (1470112295)|HEAP_ALLOCATE|[667]|Bytes:14
15:51:57.0 (1470121834)|SYSTEM_METHOD_ENTRY|[667]|System.debug(ANY)
15:51:57.0 (1470126594)|USER_DEBUG|[667]|DEBUG|new wo is null
15:51:57.0 (1470130133)|SYSTEM_METHOD_EXIT|[667]|System.debug(ANY)
15:51:57.0 (1470133136)|STATEMENT_EXECUTE|[668]
15:51:57.0 (1470136876)|HEAP_ALLOCATE|[668]|Bytes:55
15:51:57.0 (1470144596)|HEAP_ALLOCATE|[668]|Bytes:4
15:51:57.0 (1470155526)|SYSTEM_METHOD_ENTRY|[668]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470235255)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"acc":"0x30c3a1ee","accId":"0017000001RadedAAB","accNumber":"be671044","attfile":true,"count":0,"doAction":true,"existWO":"0x680d323e","goodPrefix":true,"lstDTOWOP":"0xa427ac2","lstExistingWOP":"0x34d35062","lstTempWOP":"0x1325b05e","mapExistingWOP":"0x3ec4bf05","mProduct":"0x19514e6d","newwo":false,"newworkorder":false,"nonExistingPrdName":"0x27c95675","partused":true,"prdNameMap":"0x9b742ae","productNameSet":"0x37aea486","reason":false,"serviceteamName":"MID-SOUTH MAINTENANC (7 more) ...","showWOD":true,"TargetLineRecordType":"0x2c0919e1","topPnl":false,"wo":"0x411e98eb","WOName":"wo-00635724","WORecordType":"0x720f0054","workorder":"0x30470007"}|0x5a62d92d
15:51:57.0 (1470247773)|SYSTEM_METHOD_EXIT|[668]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470419544)|SOQL_EXECUTE_BEGIN|[668]|Aggregations:0|SELECT Id, Name FROM Work_Orders__c WHERE Id = :tmpVar1
15:51:57.0 (1470431761)|LIMIT_USAGE|[668]|SOQL|24|100
15:51:57.0 (1470442563)|LIMIT_USAGE|[668]|AGGS|6|300
15:51:57.0 (1472390070)|SOQL_EXECUTE_END|[668]|Rows:0
15:51:57.0 (1472397967)|LIMIT_USAGE|[668]|SOQL_ROWS|20|50000
15:51:57.0 (1472413064)|HEAP_ALLOCATE|[668]|Bytes:4
15:51:57.0 (1472422707)|HEAP_ALLOCATE|[668]|Bytes:0
15:51:57.0 (1472442489)|HEAP_ALLOCATE|[668]|Bytes:4
15:51:57.0 (1472454664)|HEAP_ALLOCATE|[668]|Bytes:40
15:51:57.0 (1472508465)|HEAP_ALLOCATE|[668]|Bytes:46
15:51:57.0 (1472646397)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

 
  • November 28, 2016
  • Like
  • 0
I have a force.com site that sometimes has an unhandled execption, it happens.  Normally I'd just turn on logging for that guest user and see what the people were doing wrong.  After winter '17, users will have to have a special cookie for logs to be created.

My thought was to set this special cookie whenever the user accesses the site.  That way I can just turn on logging when needed.

I see the setCookies method, but that adds the apex__ prefix to the name.  Is there another way?  I'm just an admin code hacker, so forgive me.
  • October 20, 2016
  • Like
  • 0
I have the code below, but it is incrementing the attachments for each email.  So the first has the correct number, but each one after just keeps adding to that number.  It's like I need to reset that list, but I'm unsure how.

It should accept a list of ids from a flow, then send an email with the record's attachments for each record.
 
@InvocableMethod
    public static void sendEmail(List<String> invoiceID) 
    {
        string emailAddresses;
        
        List<International_Invoice__c> invoices = [SELECT Id, Freight_Forwarder_Email__c FROM International_Invoice__c WHERE Id in :invoiceID];
		List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage> ();  
        List < Messaging.EmailFileAttachment > attachments = new List < Messaging.EmailFileAttachment > ();
        
        List<Id> attIds = new List<Id>();
        for (International_Invoice__c invoice : invoices) {
        emailAddresses =  'ben.p@test.com';
         
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setToAddresses(new String[]{emailAddresses});
        
        message.setSubject('subject');
        message.setHtmlBody('body' );  // If the body is empty, use an empty string
        // Don't set the reply to, because it's auto-calculated.
        message.setUseSignature(true);
        message.setSaveAsActivity(true);
        
            for(Attachment att: [select id,body,parentId,contentType,Name from Attachment where parentId =: invoice.Id])
            {
                Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
                attach.setContentType(att.ContentType);
                attach.setFileName(att.Name);
                attach.setBody(att.body);
                attachments.add(attach);
                attIds.add(att.id);
            }
               
        message.setFileAttachments(attachments);
            
                mails.add(message);
        }
        Messaging.sendEmail(mails);
    }

 
  • April 18, 2016
  • Like
  • 0
I'm attempting to override a standard New button to prevent all but two profiles from creating from that standard button.  The problem I'm having is that when I get to the record type selection screen, I click continue and then see the same record type selection screen.  After clicking continue again, all is well.  I think I'm hitting the standard record type selection page first then I'm being sent to the URL in my extension.

I'm totally a script kitty, but I'm trying so forgive my code if it's bad.

VF page:
<apex:page standardController="Work_Orders__c" extensions="newWOextension" action="{!getRedir}" >


    <apex:pageBlock rendered="{!showError}" >
        <apex:pageBlockSection ></apex:pageBlockSection>
        <font color="red" size="4">
        <apex:outputText value="Please create new work orders using the button on cases."  >
        </apex:outputText>
        </font>
        <apex:form >
        <apex:commandButton value="Go Back" action="{!Cancel}"/>
        </apex:form>
    </apex:pageBlock>


</apex:page>
Extension:
public without sharing class newWOextension {

    public boolean showError{ get; set; }
    public Work_Orders__c record{ get; set; }
    
    public newWOextension(ApexPages.StandardController controller) {
        this.record = (Work_Orders__c)controller.getRecord();
    }

    public PageReference getRedir() {

        User u = [Select Profile.Name from User where Id = :Userinfo.getUserId()];
    showError=true;
        
        PageReference newPage;
        //if the current users profile is not a warranty admin or system admin, show the error message
        if (u.Profile.Name != 'Warranty Administrator' && u.Profile.Name != 'System Administrator' ) {
            showError = true;
            return null;
        } 
        //otherwise send them to the recordtype selection screen for work orders
        else {
            showError=false;
            
            return new PageReference('/setup/ui/recordtypeselect.jsp?ent=01I7000000084o3&retURL=%2Fa0V%2Fo&save_new_url=%2Fa0V%2Fe%3FretURL%3D%252Fa0V%252Fo&nooverride=1');
             }
    

    }

    private final ApexPages.StandardController controller;

}


 
  • September 25, 2015
  • Like
  • 0
I have a plain text VF email template that I'm working on.  It needs to be plain text so that the user can add some information before sending.

I'm attempting to show one address if the account is a person account and another if it's a standard account. 

With the code below I'm getting "syntax error", not very descriptive.  Any ideas?

<messaging:emailTemplate subject="RMA Request" recipientType="User" relatedToType="Case" >
<messaging:plainTextEmailBody >

Returning From:
 
Account Number - {!relatedto.Account.Customer_Number__c}
Name - {!relatedto.Contact.Name}
Address - {!IF(relatedTo.Account.IsPersonAccount, {!relatedto.Account.PersonShippingStreet}, {relatedto.Account.ShippingStreet})}



Phone - {!relatedto.Contact.Phone}
Email - {!relatedto.Contact.Email}


</messaging:plainTextEmailBody>
</messaging:emailTemplate>

  • October 14, 2014
  • Like
  • 0
I have a public site setup, but I've started getting random reports of users seeing the authorization required page.  I have all inserts/updates wrapped in try catch statements, but I haven't been able to replicate the problem to see the error in a debug log.

Is there a better way to catch random errors like this?  Maybe if the user hits the authorization required page, email everything to me or something?

I'm a beginner with APEX so forgive my ignorance.
  • March 05, 2014
  • Like
  • 0
I have this custom url that is used to get the lat/long for a record.  What I'd like to do is tack that function onto a trigger so that if the address is updated, the lat/long gets updated too.

This url sends the parameters to a VF page which processes that with the help of a class and updates the record.  The page and class are part of a managed package, so I can't see the class code.  I'm in a pinch, so I'm hoping to get something going quick.  I can work with the developer, but that will take weeks when I have days.

/apex/SVMXC__COMM_validateAddress?objID={!SVMXC__Service_Group__c.Id}&objName=SVMXC__Service_Group__c&street=Address__c&city=City__c&state=State__c&country=Country_Code__c&zip=Zip__c&latitude=Latitude__c&longitude=Longitude__c
  • January 30, 2014
  • Like
  • 1

I need to hide the "New Note" button which I've found I can do with a java component via the sidebar.  I'd rather do this on a page layout basis if possible, so I thought I could stick the script in a hidden vf page.  Well, that's not working.  My java is below along with the page I made (I don't use the picklist part).  Is this possible, or did I just not create the page correctly?  Thank you for the help.

 

Java sidebar component:

<script type="text/javascript" 

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">   
/* Set your sidebar component, button, and picklist field labels here */   
var customComponentName = 'Hide new note button';   /*must equal the custom component label*/

var buttonLabel = 'New Note';  /*button to hide*/
 
var picklistLabel = 'My Picklist';    /*picklist to control when hid if applicable*/
  
$(document).ready(function(){         
/* hide the sidebar component from user */        
$('.htmlAreaComponentModule').find('h2:contains("'+customComponentName+'")').parent().parent().hide(); 
    
/* only hide button if picklist value is "High" */                   
var picklistValue = $('td.labelCol:contains("'+picklistLabel+'")').next().find('div').html();                   
var btn = $('input[value="'+buttonLabel+'"]');                                              
btn.hide();   
}); </script>

 VF page I created:

<apex:page standardController="Lead">
<script type="text/javascript" 

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">   
/* Set your sidebar component, button, and picklist field labels here */   
var customComponentName = 'Hide new note button';   /*must equal the custom component label*/

var buttonLabel = 'New Note';  /*button to hide*/
 
var picklistLabel = 'My Picklist';    /*picklist to control when hid if applicable*/
  
$(document).ready(function(){         
/* hide the sidebar component from user */        
$('.htmlAreaComponentModule').find('h2:contains("'+customComponentName+'")').parent().parent().hide(); 
    
/* only hide button if picklist value is "High" */                   
var picklistValue = $('td.labelCol:contains("'+picklistLabel+'")').next().find('div').html();                   
var btn = $('input[value="'+buttonLabel+'"]');                                              
btn.hide();   
}); </script>
</apex:page>

 

  • November 22, 2013
  • Like
  • 0

Firefox will remember what I typed into fields on my standard pages and a custom search box.  For some reason IE will not remember anywhere in salesforce, but will on some other sites.  Autocomplete is enabled in IE, so it seems to be related to salesforce pages only.  Any ideas of what to look for?  What brought this up was a user complaining that the custom sidebar search box wasn't autocompleting.

 

<form action="/search/SearchResults?searchType=2&amp;search=Search&amp;asPhrase=1&amp;sen=001&amp;sen=003&amp;sen=500&amp;sen=a27&amp;sen=a29&amp;sen=a1s&amp;sen=00a&amp;sen=00T&amp;sen=002&amp;sen=00P&amp;sen=00O&amp;sen=005&amp;sen=a0A&amp;sen=a1r" method="post" name="advsrch" autocomplete="on"><input class="searchTextBox" maxlength="80" name="sbstr" +"*"="" size="18" value="" type="search">&nbsp;<input value=" Go! " class="btn" type="submit"></form>

 

  • September 19, 2013
  • Like
  • 0

Below is a section of a test class that I'm modifying due to a trigger change.  It passes all tests in the sandbox, but when trying to deploy I get an error at the first assert stating it can't find the sample work order.  I'm thinking this is due to a record not being created earlier on, but I can't see the error in the debug log.  My question is how to set/use the debug log correctly so that it shows the error and I can fix it.

 

Thank you for any help.

 

static testMethod void TestUpdateProductCodeTrigger()
     {  
     	Product2 part = [Select Id, Name From Product2 where Family = 'Pumps' and Site__c = 'E' and IsActive = true and status__c = 'A' limit 1];                       
        System.debug('part is: ' +part.Name);
        
		              
        RecordType rtBusinessAcc1 = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'Account'
                                AND Name = 'Business Account'];
                                
        RecordType rtConsumerAcc1 = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'Account'
                                AND Name = 'Consumer Account'];                        
                                

        Account ac1 = new Account (Name='test test',Email__c = 'test@test.com', RecordTypeId = rtBusinessAcc1.Id, Phone='4081234567', Type = 'SLS');
        try{
        insert ac1;

        }
               catch (Exception e) {
                system.debug('business account insert error is '+e.getMessage());
                }
                
        Account ac = new Account (
        		FirstName = 'Test',
        		LastName = 'Name',
        		Phone = '9195551212',
        		PersonMailingStreet = '123 Test',
        		PersonMailingCity = 'sanford',
        		PersonMailingState = 'NC',
        		PersonMailingCountry = 'US',
        		Pump_Seal_Test_Site__c = False,
        		RecordTypeId = rtConsumerAcc1.Id
        		);
        try{
        insert ac;
        }
               catch (Exception e) {
                system.debug('person account insert error is '+e.getMessage());
                } 
        System.debug('The person account name is: ' +ac.Name);       
        Contact ct = [Select Id, FirstName, LastName, accountid From Contact Where accountid = : ac.Id ];
        System.debug('The contact name is: ' +ct.FirstName  +ct.LastName);
        
        Case cs1 = new Case (
                    AccountId = ac.Id, 
                    ContactId = ct.Id, 
                    Status = 'New',
                    Origin = 'Email',
                    Type = 'Service',
                    Description = 'Test',
                    Product_Number__c = Part.Id,
                    Product_Model__c = 'Pumps',
                    Problem_Code__c = 'AC01=test',
                    Installation_Date__c = System.today()- 30
                    );
        insert cs1;
		System.debug('The case number is: ' +cs1.CaseNumber);
		
        Case cs2 = new Case (
                    AccountId = ac.Id, 
                    ContactId = ct.Id, 
                    Status = 'New',
                    Origin = 'Email',
                    Type = 'Service',
                    Description = 'Test',
                    Product_Number__c = Part.Id,
                    Installation_Date__c = System.today()
                    );
        insert cs2;
		System.debug('The case number is: ' +cs2.CaseNumber);
		
        
		
        // Invoking the Method "SVMX_GetProductCode()"
        String strProdCodeSP1 = SVMX_ProductInfo.SVMX_GetProductCode(Part.Id);
        
        RecordType rt = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'SVMXC__Service_Order__c'
                                AND Name = 'Regular'];
        RecordType rt1 = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'SVMXC__Service_Order__c'
                                AND Name = 'Fast Track'];                        
        
        //Select warranty admin user
		        
        RecordType rType = [SELECT Id from RecordType where SObjectType = 'SVMXC__Service_Group__c' and Name = 'Setup'];
          
        User usr = [Select Id, Name from User Where Profile.Name = 'Warranty Administrator' and IsActive = true limit 1 ];
        
        System.debug('The user name is: ' +usr.Name);
        
          
		SVMXC__Service_Group__c sg = new SVMXC__Service_Group__c(Warranty_Station_Email__c = 'abc@xyz.com', 
																	SVMXC__Active__c = true,
																	Equipment__c = 'a,b',
																	QAD_Vend_Code__c = 'ZZ125487', 
																	QADCode__c = 'ZZ000000', 
																	PolicyExp__c = System.today()+ 7, 
																	Name = 'testsvg', 
																	Insurance_number__c = '4517744', 
																	AppDate__c = System.today(), Region__c = 'Arizona', SVMXC__Group_Type__c = 'Partner', Phone__c = '(919) 566-8899',
																	Address__c = '123 main', City__c = 'sanford', State__c = 'nc', Zip__c = '27330', Country_Code__c = 'US',
																	ABC__c = 'A', RecordTypeId = rType.Id, Sales_Rep__c = ac1.Id, Service_Rep__c = ac1.Id, 
																	Admin__c = usr.Id);
		try{
        insert sg;
        }
               catch (Exception e) {
                system.debug('service team insert error is '+e.getMessage());
                }
		//insert sg;
		System.debug('The team name is: ' +sg.Name);
        
		System.runAs(usr)//run as a warranty admin profile user
        {
        // Create WO with Product                 
        SVMXC__Service_Order__c  SampleWorkOrder1 = new SVMXC__Service_Order__c (
        RecordTypeId = rt.Id,
		SVMXC__Case__c = cs1.Id ,
        SVMXC__Company__c  = ac.Id , 
        SVMXC__Contact__c = ct.Id,
        Product__c = Part.Id,
        SVMXC__Service_Group__c = sg.Id,
		SVMXC__Priority__c = 'Medium',
		SVMXC__Order_Type__c = 'Field Service',
		Repair_Date__c = System.today(),
        SVMXC__Order_Status__c ='Processing Error',
        Reason_For_Denial__c = 'Test denial'
        );
         
        try{
        insert SampleWorkOrder1;
        }
               catch (Exception e) {
                system.debug('sample work order 1 insert error is '+e.getMessage());
                }     
        System.debug('The work order number is: ' +SampleWorkOrder1.Name);
        
        //assert that the processed date and processed by fields are set correctly on insert
        SVMXC__Service_Order__c wo = [Select Id, Processed_Date__c, Processed_By__c From SVMXC__Service_Order__c Where Id = :SampleWorkOrder1.Id];
        System.assertEquals(wo.Processed_Date__c, System.today());
        System.assertEquals(wo.Processed_By__c, UserInfo.getName());
        
                        
        SVMXC__Service_Order__c  SampleWorkOrder2 = [SELECT Id ,Product__c, SVMXC__Order_Status__c, Reason_For_Denial__c FROM SVMXC__Service_Order__c where Id= :SampleWorkOrder1.Id ];
        SampleWorkOrder2.Product__c = Part.Id;        
        SampleWorkOrder2.SVMXC__Service_Group__c =sg.Id;
        SampleWorkOrder2.SVMXC__Company__c  = ac.Id;
        SampleWorkOrder2.SVMXC__Order_Status__c = 'Warranty Denied';
        SampleWorkOrder2.Reason_For_Denial__c = 'Test denial';
        try{
        update SampleWorkOrder2;
        }
               catch (Exception e) {
                system.debug('svol insert error is '+e.getMessage());
                }
        //assert that the processed date and processed by fields are set correctly on update
        SVMXC__Service_Order__c wo2 = [Select Id, Processed_Date__c, Processed_By__c From SVMXC__Service_Order__c Where Id = :SampleWorkOrder2.Id];
        System.assertEquals(wo.Processed_Date__c, System.today());
        System.assertEquals(wo.Processed_By__c, UserInfo.getName()); 
        
        SampleWorkOrder2.Amount__c = 0;
        SampleWorkOrder2.SVMXC__Order_Status__c = 'Warranty Processed';
        
        try{
        	update SampleWorkOrder2;
        }
        catch (Exception e) {
                System.Assert(e.getMessage().contains ('A dollar amount is required'));
                }
        
                                
        SVMXC__Service_Order__c  SampleWorkOrder3 = new SVMXC__Service_Order__c (
        SVMXC__Case__c = cs2.Id ,
        SVMXC__Contact__c =ct.Id,
        Product__c = Part.Id,
        SVMXC__Company__c  = ac.Id,
        Product_Model__c = 'Automation',
        Installation_Date__c = System.today(),
        SVMXC__Order_Status__c = 'Open',
        SVMXC__Priority__c = 'Medium',
        SVMXC__Order_Type__c = 'Field Service',
        Street__c = '123 test street',
        City__c = 'test city',
        State__c = 'test state',
        CaseProductGroup__c = 'Filter',
        Case_Problem_Code__c = 'FP93: WS STOCKING',
        SVMXC__Problem_Description__c = 'test description',
        SVMXC__Service_Group__c =sg.Id,
        RecordTypeId = rt1.Id); 
        try{
        insert SampleWorkOrder3;
        }
               catch (Exception e) {
                system.debug('svol insert error is '+e.getMessage());
                }
        
        SVMXC__Service_Order__c  SampleWorkOrder4 =  [SELECT Id ,Product__c FROM SVMXC__Service_Order__c where Id= :SampleWorkOrder1.Id ];
        SampleWorkOrder2.Product__c = Part.Id;
        SampleWorkOrder2.SVMXC__Service_Group__c =sg.Id;
        SampleWorkOrder2.SVMXC__Company__c  = ac.Id;
        try{
        update SampleWorkOrder4;
        }
               catch (Exception e) {
                system.debug('svol insert error is '+e.getMessage());
                } 
        }                  
     }

 

  • July 23, 2013
  • Like
  • 0

I have the following code setup for my sidebar search box (I found it via google, so I'm not that skilled) so that it performs an advanced search each time on certain objects.  I'd like to wrap the search terms in quotes with an * at the end to get the best results.  Something like "search*" would be the search term vs. search.  Any idea how I could wrap the input in quotes and tack on the *? 

 

<form action="/search/SearchResults?searchType=2&amp;sen=001&amp;sen=003&amp;sen=500&amp;sen=a27&amp;sen=a29&amp;sen=a1s&amp;sen=00a&amp;sen=00T&amp;sen=002&amp;sen=00P&amp;sen=00O&amp;sen=005&amp;sen=a0A&amp;sen=a1r" method="post" name="advsrch"><input class="searchTextBox" maxlength="80" name="sbstr" size="18" value="" type="text">&nbsp;<input value=" Go! " class="btn" type="submit"></form>

 

  • July 17, 2013
  • Like
  • 0

I've been searching around, but have yet to find the solution.  I have the trigger below that prevents the case from being deleted if the work order count field is > 0.  The problem is that it shows a somewhat harsh system error message vs. a nice popup window that the user can click ok on.  Any suggestions?

 

trigger BeforeDeleteCase on Case (before delete) {

for (Case cs : trigger.old)
    {
        
        if (cs.Work_order_count__c > 0)
        //if the work order count is more than zero
            {
            	cs.addError('Can delete this case, A work order for this case currently exists');
            }  
           
}
}

 

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Can delete this case, A work order for this case currently exists".

Click here to return to the previous page. 

 

  • March 19, 2013
  • Like
  • 0

I have the following workflow / field update and asked it to re-evaluate after running, but it seems to stop after the first time.

 

AND (
ISPICKVAL( Status__c , "Open" ) ,
OR (
Due_Date_Weekday__c = "Saturday" ,
Due_Date_Weekday__c = "Sunday" )
)

 Due_Date_Weekday__c is a formula field.  Is that formula not calculated until the record is commited, or do you think it's something else?

I just need to move the due date up so it's not set to saturday or sunday.

  • February 28, 2013
  • Like
  • 0

I have a force.com site page that references a class that will display an error.  Inside this error I'd like to have a link to an external web page.  The problem is that the site is inserting it's site address before mine.  Instead of www.website.com, I'm getting site.force.com/page/mylink.  Any advice there?

 

if(sg.Is_Portal_User__c == 'True')
         {
                MyException e = new MyException('You have accessed the wrong portal. Click <a href="www.bit.ly/xxxxxx">here</a>' );
            ApexPages.addMessages(e);
            return null;
         }

 

  • September 13, 2012
  • Like
  • 0

I have an existing trigger that I want to add code to so that an email is sent if the record insert fails.  I added the code and the log sais isSuccess=true, but nothing is going out.  Any good advice?  The part I added is indented the furthest.  Prior to my fiddeling it only showed the error on the screen, but I'm trying to catch a force.com site user account's errors better.

 

try 
                  		{      
                        insert acc; 
                        System.debug('Account created successfully ' + acc.Id);
                        acc2 = [SELECT PersonContactId FROM Account Where Id = :acc.Id];
                        PersonContactId = acc2.PersonContactId;
                        na = acc2.id;  }catch(System.Exception qe) 
                        {
                        	
                                                // Create a new single email message object
						// that will send out a single email to the addresses in the To, CC & BCC list.
						Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
						// Strings to hold the email addresses to which you are sending the email.
						String[] toAddresses = new String[] {'xxxxxx@gmail.com'};
						//String[] ccAddresses = new String[] {'smith@gmail.com'};
						// Assign the addresses for the To and CC lists to the mail object.
						mail.setToAddresses(toAddresses);
						//mail.setCcAddresses(ccAddresses);
						// Specify the address used when the recipients reply to the email.
						mail.setReplyTo('xxxx@xxxx.com');
						// Specify the name used as the display name.
						mail.setSenderDisplayName('Portal Lite Error');
						// Specify the subject line for your email address.
						mail.setSubject('Portal Lite Error');
						// Set to True if you want to BCC yourself on the email.
						mail.setBccSender(false);
						// Optionally append the salesforce.com email signature to the email.
						// The email address of the user executing the Apex Code will be used.
						mail.setUseSignature(false);
						// Specify the text content of the email.
						mail.setPlainTextBody('An error occurred when creating person account: ' + qe.getMessage());
						mail.setHtmlBody('An error occurred when creating person account: ' + qe.getMessage());
						Messaging.SendEmailResult [] r =
						Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });	
                                                System.debug('Email result: '+r);
                        
													
                        SVO.addError('An error occurred when creating person account: ' + qe.getMessage());
                        System.debug('An error occurred when creating person account: ' + qe.getMessage());
                        }

 

  • August 15, 2012
  • Like
  • 0

I have a force.com site that has a problem with IE9 where it blanks the pick list fields and won't save the record.  If I use compatibility mode, the problem goes away.  I have been trying to force the page to load in compatibility mode by adding code to the VF page, but it's not working.  Any suggestions?

 

I added <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> in various places, but it's not working out.  Here's the first section of the VF page for reference.

 

<apex:page showHeader="false" sidebar="false"   controller="SVMX_WarrantyCalaimForm_Controller" id="Page1" >

<apex:stylesheet value="{!$Resource.SVMXVF_Resources1}" />

<style>

body { margin-top: 1%; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; }
.rowHeight {height:50px}


</style>

<script type="text/javascript">
  function customSelectChecked( form,value)
    {   
        var i = 0;
        for (i = 0; i < form.elements.length; i++) {
            if (form.elements[i].name.search('selected') > 0 && form.elements[i].disabled == false) {
                form.elements[i].checked = value;
            }
        }
    }     
    function customSelectAllOrNoneByCheckbox(form,control)
    {  customSelectChecked( form,control.checked); }
    
  </script> 
  
    <apex:form id="Form1">

 

  • April 20, 2012
  • Like
  • 0

I have a force.com site that has a problem with IE9 where it blanks the pick list fields and won't save the record.  If I use compatibility mode, the problem goes away.  I have been trying to force the page to load in compatibility mode by adding code to the VF page, but it's not working.  Any suggestions?

 

I added <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> in various places, but it's not working out.  Here's the first section of the VF page for reference.

 

<apex:page showHeader="false" sidebar="false"   controller="SVMX_WarrantyCalaimForm_Controller" id="Page1" >

<apex:stylesheet value="{!$Resource.SVMXVF_Resources1}" />

<style>

body { margin-top: 1%; margin-right: 0px; margin-bottom: 0px; margin-left: 25px; }
.rowHeight {height:50px}


</style>

<script type="text/javascript">
  function customSelectChecked( form,value)
    {   
        var i = 0;
        for (i = 0; i < form.elements.length; i++) {
            if (form.elements[i].name.search('selected') > 0 && form.elements[i].disabled == false) {
                form.elements[i].checked = value;
            }
        }
    }     
    function customSelectAllOrNoneByCheckbox(form,control)
    {  customSelectChecked( form,control.checked); }
    
  </script> 
  
    <apex:form id="Form1">

 

  • April 19, 2012
  • Like
  • 0

I have a force.com site where the guest user account creates records.  The problem I have is that internal users seem to be below that guest account in the hierarchy (they can't delete records owned by the guest account).  I share records owned by the guest account to internal users (read/write), but they still can't delete.  I must be missing something simple here.  ??

  • April 13, 2012
  • Like
  • 0

I'm creating a VF template to show some data and then the related data in a table.  I've been able to complete all but the related data, it's not showing.  The object is SVMXI__Parts_Request__c and the child object is SVMXI__Parts_Request_Line__c.  My current page (rough draft) is as follows:

<messaging:emailTemplate subject="Order confirmation" recipientType="User" relatedToType="SVMXI__Parts_Request__c">
<messaging:htmlEmailBody >
<br />
<br />
A parts order going to {!relatedto.Name__c} was just completed for you.  <br />
<br />
Ship to: {!relatedto.Name__c} <br />
Due Date: {!relatedto.Due_Date__c} <br />
<br />
<br />
<table border="0">
               
                    <tr >
                        <th>QTY</th>
                        <th>PART #</th>
                        <th>DESCRIPTION</th>
                    </tr>
                    
                    <apex:repeat value="{!relatedto.Parts_Request_Line__r}" var="prlin">
                    <tr>
                        
                        <td> {!prlin.Qty__c}</td>
                        <td> {!prlin.Parts__r.Name}</td>
                        <td> {!prlin.Parts__r.ProductCode}</td>
                    </tr>
                     </apex:repeat>
                     
           </table>


</messaging:htmlEmailBody>
</messaging:emailTemplate>

 The problem is that I'm not getting any data from parts request lines in the table.  I should mention these are part of a managed package.  Also when I go to the child object and check the lookup to the parent object, the child relationship name is R00N70000001ryqzEAA vs. a real name like other components.  

  • March 26, 2012
  • Like
  • 0
I have this custom url that is used to get the lat/long for a record.  What I'd like to do is tack that function onto a trigger so that if the address is updated, the lat/long gets updated too.

This url sends the parameters to a VF page which processes that with the help of a class and updates the record.  The page and class are part of a managed package, so I can't see the class code.  I'm in a pinch, so I'm hoping to get something going quick.  I can work with the developer, but that will take weeks when I have days.

/apex/SVMXC__COMM_validateAddress?objID={!SVMXC__Service_Group__c.Id}&objName=SVMXC__Service_Group__c&street=Address__c&city=City__c&state=State__c&country=Country_Code__c&zip=Zip__c&latitude=Latitude__c&longitude=Longitude__c
  • January 30, 2014
  • Like
  • 1
I have a force.com site that uses a custom controller.  I'm getting very random unhandled exception error issues and finally caught a log today.  The strange part is that it's coming from a section that shouldn't even run since it's inside an IF statement.  Any reason this section would execute? 

IF statement that seems to be executing:
if( wo != null ){
                    system.debug('new wo is '+wo.Id);
                    objWO1 = [Select Id, Name From Work_Orders__c Where Id=:wo.Id];
                    //system.debug('Inside new work order*************'+objWO1.Name);
                    //system.debug('Inside Id*************'+objWO1.Id);
                    woParam = objWO1.Id;
                    woParamName = objWO1.Name;

Here's a debug log snippet.  The above code starts at line 666 for reference.  You can see that it shouldn't run if wo == null, but the debug shows that it did.
 
15:51:57.0 (1469874893)|SYSTEM_METHOD_ENTRY|[666]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1469956278)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"acc":"0x30c3a1ee","accId":"0017000001RadedAAB","accNumber":"be671044","attfile":true,"count":0,"doAction":true,"existWO":"0x680d323e","goodPrefix":true,"lstDTOWOP":"0xa427ac2","lstExistingWOP":"0x34d35062","lstTempWOP":"0x1325b05e","mapExistingWOP":"0x3ec4bf05","mProduct":"0x19514e6d","newwo":false,"newworkorder":false,"nonExistingPrdName":"0x27c95675","partused":true,"prdNameMap":"0x9b742ae","productNameSet":"0x37aea486","reason":false,"serviceteamName":"MID-SOUTH MAINTENANC (7 more) ...","showWOD":true,"TargetLineRecordType":"0x2c0919e1","topPnl":false,"wo":"0x411e98eb","WOName":"wo-00635724","WORecordType":"0x720f0054","workorder":"0x30470007"}|0x5a62d92d
15:51:57.0 (1469968317)|SYSTEM_METHOD_EXIT|[666]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1469972333)|STATEMENT_EXECUTE|[666]
15:51:57.0 (1469973796)|STATEMENT_EXECUTE|[667]
15:51:57.0 (1469978048)|HEAP_ALLOCATE|[667]|Bytes:10
15:51:57.0 (1469985060)|SYSTEM_METHOD_ENTRY|[667]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470063224)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"acc":"0x30c3a1ee","accId":"0017000001RadedAAB","accNumber":"be671044","attfile":true,"count":0,"doAction":true,"existWO":"0x680d323e","goodPrefix":true,"lstDTOWOP":"0xa427ac2","lstExistingWOP":"0x34d35062","lstTempWOP":"0x1325b05e","mapExistingWOP":"0x3ec4bf05","mProduct":"0x19514e6d","newwo":false,"newworkorder":false,"nonExistingPrdName":"0x27c95675","partused":true,"prdNameMap":"0x9b742ae","productNameSet":"0x37aea486","reason":false,"serviceteamName":"MID-SOUTH MAINTENANC (7 more) ...","showWOD":true,"TargetLineRecordType":"0x2c0919e1","topPnl":false,"wo":"0x411e98eb","WOName":"wo-00635724","WORecordType":"0x720f0054","workorder":"0x30470007"}|0x5a62d92d
15:51:57.0 (1470075680)|SYSTEM_METHOD_EXIT|[667]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470095580)|SYSTEM_METHOD_ENTRY|[667]|String.valueOf(Object)
15:51:57.0 (1470105725)|SYSTEM_METHOD_EXIT|[667]|String.valueOf(Object)
15:51:57.0 (1470112295)|HEAP_ALLOCATE|[667]|Bytes:14
15:51:57.0 (1470121834)|SYSTEM_METHOD_ENTRY|[667]|System.debug(ANY)
15:51:57.0 (1470126594)|USER_DEBUG|[667]|DEBUG|new wo is null
15:51:57.0 (1470130133)|SYSTEM_METHOD_EXIT|[667]|System.debug(ANY)
15:51:57.0 (1470133136)|STATEMENT_EXECUTE|[668]
15:51:57.0 (1470136876)|HEAP_ALLOCATE|[668]|Bytes:55
15:51:57.0 (1470144596)|HEAP_ALLOCATE|[668]|Bytes:4
15:51:57.0 (1470155526)|SYSTEM_METHOD_ENTRY|[668]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470235255)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this|{"acc":"0x30c3a1ee","accId":"0017000001RadedAAB","accNumber":"be671044","attfile":true,"count":0,"doAction":true,"existWO":"0x680d323e","goodPrefix":true,"lstDTOWOP":"0xa427ac2","lstExistingWOP":"0x34d35062","lstTempWOP":"0x1325b05e","mapExistingWOP":"0x3ec4bf05","mProduct":"0x19514e6d","newwo":false,"newworkorder":false,"nonExistingPrdName":"0x27c95675","partused":true,"prdNameMap":"0x9b742ae","productNameSet":"0x37aea486","reason":false,"serviceteamName":"MID-SOUTH MAINTENANC (7 more) ...","showWOD":true,"TargetLineRecordType":"0x2c0919e1","topPnl":false,"wo":"0x411e98eb","WOName":"wo-00635724","WORecordType":"0x720f0054","workorder":"0x30470007"}|0x5a62d92d
15:51:57.0 (1470247773)|SYSTEM_METHOD_EXIT|[668]|WarrantyClaimController.__sfdc_wo()
15:51:57.0 (1470419544)|SOQL_EXECUTE_BEGIN|[668]|Aggregations:0|SELECT Id, Name FROM Work_Orders__c WHERE Id = :tmpVar1
15:51:57.0 (1470431761)|LIMIT_USAGE|[668]|SOQL|24|100
15:51:57.0 (1470442563)|LIMIT_USAGE|[668]|AGGS|6|300
15:51:57.0 (1472390070)|SOQL_EXECUTE_END|[668]|Rows:0
15:51:57.0 (1472397967)|LIMIT_USAGE|[668]|SOQL_ROWS|20|50000
15:51:57.0 (1472413064)|HEAP_ALLOCATE|[668]|Bytes:4
15:51:57.0 (1472422707)|HEAP_ALLOCATE|[668]|Bytes:0
15:51:57.0 (1472442489)|HEAP_ALLOCATE|[668]|Bytes:4
15:51:57.0 (1472454664)|HEAP_ALLOCATE|[668]|Bytes:40
15:51:57.0 (1472508465)|HEAP_ALLOCATE|[668]|Bytes:46
15:51:57.0 (1472646397)|FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

 
  • November 28, 2016
  • Like
  • 0
I have a force.com site that sometimes has an unhandled execption, it happens.  Normally I'd just turn on logging for that guest user and see what the people were doing wrong.  After winter '17, users will have to have a special cookie for logs to be created.

My thought was to set this special cookie whenever the user accesses the site.  That way I can just turn on logging when needed.

I see the setCookies method, but that adds the apex__ prefix to the name.  Is there another way?  I'm just an admin code hacker, so forgive me.
  • October 20, 2016
  • Like
  • 0
I have the code below, but it is incrementing the attachments for each email.  So the first has the correct number, but each one after just keeps adding to that number.  It's like I need to reset that list, but I'm unsure how.

It should accept a list of ids from a flow, then send an email with the record's attachments for each record.
 
@InvocableMethod
    public static void sendEmail(List<String> invoiceID) 
    {
        string emailAddresses;
        
        List<International_Invoice__c> invoices = [SELECT Id, Freight_Forwarder_Email__c FROM International_Invoice__c WHERE Id in :invoiceID];
		List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage> ();  
        List < Messaging.EmailFileAttachment > attachments = new List < Messaging.EmailFileAttachment > ();
        
        List<Id> attIds = new List<Id>();
        for (International_Invoice__c invoice : invoices) {
        emailAddresses =  'ben.p@test.com';
         
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setToAddresses(new String[]{emailAddresses});
        
        message.setSubject('subject');
        message.setHtmlBody('body' );  // If the body is empty, use an empty string
        // Don't set the reply to, because it's auto-calculated.
        message.setUseSignature(true);
        message.setSaveAsActivity(true);
        
            for(Attachment att: [select id,body,parentId,contentType,Name from Attachment where parentId =: invoice.Id])
            {
                Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
                attach.setContentType(att.ContentType);
                attach.setFileName(att.Name);
                attach.setBody(att.body);
                attachments.add(attach);
                attIds.add(att.id);
            }
               
        message.setFileAttachments(attachments);
            
                mails.add(message);
        }
        Messaging.sendEmail(mails);
    }

 
  • April 18, 2016
  • Like
  • 0
I'm attempting to override a standard New button to prevent all but two profiles from creating from that standard button.  The problem I'm having is that when I get to the record type selection screen, I click continue and then see the same record type selection screen.  After clicking continue again, all is well.  I think I'm hitting the standard record type selection page first then I'm being sent to the URL in my extension.

I'm totally a script kitty, but I'm trying so forgive my code if it's bad.

VF page:
<apex:page standardController="Work_Orders__c" extensions="newWOextension" action="{!getRedir}" >


    <apex:pageBlock rendered="{!showError}" >
        <apex:pageBlockSection ></apex:pageBlockSection>
        <font color="red" size="4">
        <apex:outputText value="Please create new work orders using the button on cases."  >
        </apex:outputText>
        </font>
        <apex:form >
        <apex:commandButton value="Go Back" action="{!Cancel}"/>
        </apex:form>
    </apex:pageBlock>


</apex:page>
Extension:
public without sharing class newWOextension {

    public boolean showError{ get; set; }
    public Work_Orders__c record{ get; set; }
    
    public newWOextension(ApexPages.StandardController controller) {
        this.record = (Work_Orders__c)controller.getRecord();
    }

    public PageReference getRedir() {

        User u = [Select Profile.Name from User where Id = :Userinfo.getUserId()];
    showError=true;
        
        PageReference newPage;
        //if the current users profile is not a warranty admin or system admin, show the error message
        if (u.Profile.Name != 'Warranty Administrator' && u.Profile.Name != 'System Administrator' ) {
            showError = true;
            return null;
        } 
        //otherwise send them to the recordtype selection screen for work orders
        else {
            showError=false;
            
            return new PageReference('/setup/ui/recordtypeselect.jsp?ent=01I7000000084o3&retURL=%2Fa0V%2Fo&save_new_url=%2Fa0V%2Fe%3FretURL%3D%252Fa0V%252Fo&nooverride=1');
             }
    

    }

    private final ApexPages.StandardController controller;

}


 
  • September 25, 2015
  • Like
  • 0
Hi all,

I am trying to find a way to create a VisualForce page that will be leveraged by a homepage component.

The idea is that the homepage component displays an input area where users will enter information and that after pushing on a button, Salesforce.com calls an existing report and replaces the 1st criteria of the report with the information entered by the user (this functionality currently exists in homepage components but it is my understanding that it will no longer be operational after Summer '15 release and I am then trying to figure out how to do something similar with VisualForce as per advised by Salesforce.com).

By checking a bit online I found a tutorial on YouTube (https://www.youtube.com/watch?v=8FE8gRGIGGM) explaining how to pull a report from a VisualForce. Basically some HTML should suffice for this and a sentence like this should work:

<apex:page standardController = "Account">
<p>
<a href="/5003300000nFasY?pc0=ACCOUNT_ID&pn0=eq&pv0{!LEFT(Account.ID,15)}" target="_blank"> Open Opportunities"</a>&nbsp;-&nbsp;What is the opportunity pipeline for {!Account.Name}?
</p>
</apex:page>

If I understand this logic right:
1) Report link is /5003300000nFasY
2) The first criteria to the report is passed through ?pc0=ACCOUNT_ID&pn0=eq&pv0{!LEFT(Account.ID,15)} (this is the criteria that I need to replace with the input from the user)
3) A separate window is opening thanks to target="_blank"

This code allows displaying a report pulling data from an account record: basically I guess all I would need to figure out is the code to include an input section (to the users can enter the criteria wanted) since the <a> would work as a "button" to trigger the display of the report.

Any assistance will be more than welcome :)

Thanks in advance,

Harold
Hi, 

I created a process to add the accountID to the relatedto field for all new tasks. This works fine when you log a call, but when you add an email via the Salesforce for Outlook addin. It skips this process. I would like to to add to any all new tasks, not just the ones i create in sf.com. Please advise. 
**Wasnt' sure what category to use. 
I have created custom button and used javascript code to display the error messages and redirect to wizard pages but salesforce1 doesn't display that button.

Salesforce1 doesn't support javascript, how to over come this?

How to use custom button with any web lanaguage code to display error msg or redirect to different page on salesforce1
 
I have a plain text VF email template that I'm working on.  It needs to be plain text so that the user can add some information before sending.

I'm attempting to show one address if the account is a person account and another if it's a standard account. 

With the code below I'm getting "syntax error", not very descriptive.  Any ideas?

<messaging:emailTemplate subject="RMA Request" recipientType="User" relatedToType="Case" >
<messaging:plainTextEmailBody >

Returning From:
 
Account Number - {!relatedto.Account.Customer_Number__c}
Name - {!relatedto.Contact.Name}
Address - {!IF(relatedTo.Account.IsPersonAccount, {!relatedto.Account.PersonShippingStreet}, {relatedto.Account.ShippingStreet})}



Phone - {!relatedto.Contact.Phone}
Email - {!relatedto.Contact.Email}


</messaging:plainTextEmailBody>
</messaging:emailTemplate>

  • October 14, 2014
  • Like
  • 0
I have a public site setup, but I've started getting random reports of users seeing the authorization required page.  I have all inserts/updates wrapped in try catch statements, but I haven't been able to replicate the problem to see the error in a debug log.

Is there a better way to catch random errors like this?  Maybe if the user hits the authorization required page, email everything to me or something?

I'm a beginner with APEX so forgive my ignorance.
  • March 05, 2014
  • Like
  • 0
I have this custom url that is used to get the lat/long for a record.  What I'd like to do is tack that function onto a trigger so that if the address is updated, the lat/long gets updated too.

This url sends the parameters to a VF page which processes that with the help of a class and updates the record.  The page and class are part of a managed package, so I can't see the class code.  I'm in a pinch, so I'm hoping to get something going quick.  I can work with the developer, but that will take weeks when I have days.

/apex/SVMXC__COMM_validateAddress?objID={!SVMXC__Service_Group__c.Id}&objName=SVMXC__Service_Group__c&street=Address__c&city=City__c&state=State__c&country=Country_Code__c&zip=Zip__c&latitude=Latitude__c&longitude=Longitude__c
  • January 30, 2014
  • Like
  • 1
We have a visual workflow enabled for a site. 

The visual worflow incldues the SendEmail apex plugin to send a confirmation email to a customer. However, it uses my email address whereas we want to use a generic from address (e.g. support@...)

1. How can you set the from address? 
2. Why does it pick me by default? Is it because I am the Site Contact? Or the Flow designer? 

I need to hide the "New Note" button which I've found I can do with a java component via the sidebar.  I'd rather do this on a page layout basis if possible, so I thought I could stick the script in a hidden vf page.  Well, that's not working.  My java is below along with the page I made (I don't use the picklist part).  Is this possible, or did I just not create the page correctly?  Thank you for the help.

 

Java sidebar component:

<script type="text/javascript" 

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">   
/* Set your sidebar component, button, and picklist field labels here */   
var customComponentName = 'Hide new note button';   /*must equal the custom component label*/

var buttonLabel = 'New Note';  /*button to hide*/
 
var picklistLabel = 'My Picklist';    /*picklist to control when hid if applicable*/
  
$(document).ready(function(){         
/* hide the sidebar component from user */        
$('.htmlAreaComponentModule').find('h2:contains("'+customComponentName+'")').parent().parent().hide(); 
    
/* only hide button if picklist value is "High" */                   
var picklistValue = $('td.labelCol:contains("'+picklistLabel+'")').next().find('div').html();                   
var btn = $('input[value="'+buttonLabel+'"]');                                              
btn.hide();   
}); </script>

 VF page I created:

<apex:page standardController="Lead">
<script type="text/javascript" 

src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">   
/* Set your sidebar component, button, and picklist field labels here */   
var customComponentName = 'Hide new note button';   /*must equal the custom component label*/

var buttonLabel = 'New Note';  /*button to hide*/
 
var picklistLabel = 'My Picklist';    /*picklist to control when hid if applicable*/
  
$(document).ready(function(){         
/* hide the sidebar component from user */        
$('.htmlAreaComponentModule').find('h2:contains("'+customComponentName+'")').parent().parent().hide(); 
    
/* only hide button if picklist value is "High" */                   
var picklistValue = $('td.labelCol:contains("'+picklistLabel+'")').next().find('div').html();                   
var btn = $('input[value="'+buttonLabel+'"]');                                              
btn.hide();   
}); </script>
</apex:page>

 

  • November 22, 2013
  • Like
  • 0

Firefox will remember what I typed into fields on my standard pages and a custom search box.  For some reason IE will not remember anywhere in salesforce, but will on some other sites.  Autocomplete is enabled in IE, so it seems to be related to salesforce pages only.  Any ideas of what to look for?  What brought this up was a user complaining that the custom sidebar search box wasn't autocompleting.

 

<form action="/search/SearchResults?searchType=2&amp;search=Search&amp;asPhrase=1&amp;sen=001&amp;sen=003&amp;sen=500&amp;sen=a27&amp;sen=a29&amp;sen=a1s&amp;sen=00a&amp;sen=00T&amp;sen=002&amp;sen=00P&amp;sen=00O&amp;sen=005&amp;sen=a0A&amp;sen=a1r" method="post" name="advsrch" autocomplete="on"><input class="searchTextBox" maxlength="80" name="sbstr" +"*"="" size="18" value="" type="search">&nbsp;<input value=" Go! " class="btn" type="submit"></form>

 

  • September 19, 2013
  • Like
  • 0

Below is a section of a test class that I'm modifying due to a trigger change.  It passes all tests in the sandbox, but when trying to deploy I get an error at the first assert stating it can't find the sample work order.  I'm thinking this is due to a record not being created earlier on, but I can't see the error in the debug log.  My question is how to set/use the debug log correctly so that it shows the error and I can fix it.

 

Thank you for any help.

 

static testMethod void TestUpdateProductCodeTrigger()
     {  
     	Product2 part = [Select Id, Name From Product2 where Family = 'Pumps' and Site__c = 'E' and IsActive = true and status__c = 'A' limit 1];                       
        System.debug('part is: ' +part.Name);
        
		              
        RecordType rtBusinessAcc1 = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'Account'
                                AND Name = 'Business Account'];
                                
        RecordType rtConsumerAcc1 = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'Account'
                                AND Name = 'Consumer Account'];                        
                                

        Account ac1 = new Account (Name='test test',Email__c = 'test@test.com', RecordTypeId = rtBusinessAcc1.Id, Phone='4081234567', Type = 'SLS');
        try{
        insert ac1;

        }
               catch (Exception e) {
                system.debug('business account insert error is '+e.getMessage());
                }
                
        Account ac = new Account (
        		FirstName = 'Test',
        		LastName = 'Name',
        		Phone = '9195551212',
        		PersonMailingStreet = '123 Test',
        		PersonMailingCity = 'sanford',
        		PersonMailingState = 'NC',
        		PersonMailingCountry = 'US',
        		Pump_Seal_Test_Site__c = False,
        		RecordTypeId = rtConsumerAcc1.Id
        		);
        try{
        insert ac;
        }
               catch (Exception e) {
                system.debug('person account insert error is '+e.getMessage());
                } 
        System.debug('The person account name is: ' +ac.Name);       
        Contact ct = [Select Id, FirstName, LastName, accountid From Contact Where accountid = : ac.Id ];
        System.debug('The contact name is: ' +ct.FirstName  +ct.LastName);
        
        Case cs1 = new Case (
                    AccountId = ac.Id, 
                    ContactId = ct.Id, 
                    Status = 'New',
                    Origin = 'Email',
                    Type = 'Service',
                    Description = 'Test',
                    Product_Number__c = Part.Id,
                    Product_Model__c = 'Pumps',
                    Problem_Code__c = 'AC01=test',
                    Installation_Date__c = System.today()- 30
                    );
        insert cs1;
		System.debug('The case number is: ' +cs1.CaseNumber);
		
        Case cs2 = new Case (
                    AccountId = ac.Id, 
                    ContactId = ct.Id, 
                    Status = 'New',
                    Origin = 'Email',
                    Type = 'Service',
                    Description = 'Test',
                    Product_Number__c = Part.Id,
                    Installation_Date__c = System.today()
                    );
        insert cs2;
		System.debug('The case number is: ' +cs2.CaseNumber);
		
        
		
        // Invoking the Method "SVMX_GetProductCode()"
        String strProdCodeSP1 = SVMX_ProductInfo.SVMX_GetProductCode(Part.Id);
        
        RecordType rt = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'SVMXC__Service_Order__c'
                                AND Name = 'Regular'];
        RecordType rt1 = [SELECT Id FROM RecordType 
                                WHERE SObjectType = 'SVMXC__Service_Order__c'
                                AND Name = 'Fast Track'];                        
        
        //Select warranty admin user
		        
        RecordType rType = [SELECT Id from RecordType where SObjectType = 'SVMXC__Service_Group__c' and Name = 'Setup'];
          
        User usr = [Select Id, Name from User Where Profile.Name = 'Warranty Administrator' and IsActive = true limit 1 ];
        
        System.debug('The user name is: ' +usr.Name);
        
          
		SVMXC__Service_Group__c sg = new SVMXC__Service_Group__c(Warranty_Station_Email__c = 'abc@xyz.com', 
																	SVMXC__Active__c = true,
																	Equipment__c = 'a,b',
																	QAD_Vend_Code__c = 'ZZ125487', 
																	QADCode__c = 'ZZ000000', 
																	PolicyExp__c = System.today()+ 7, 
																	Name = 'testsvg', 
																	Insurance_number__c = '4517744', 
																	AppDate__c = System.today(), Region__c = 'Arizona', SVMXC__Group_Type__c = 'Partner', Phone__c = '(919) 566-8899',
																	Address__c = '123 main', City__c = 'sanford', State__c = 'nc', Zip__c = '27330', Country_Code__c = 'US',
																	ABC__c = 'A', RecordTypeId = rType.Id, Sales_Rep__c = ac1.Id, Service_Rep__c = ac1.Id, 
																	Admin__c = usr.Id);
		try{
        insert sg;
        }
               catch (Exception e) {
                system.debug('service team insert error is '+e.getMessage());
                }
		//insert sg;
		System.debug('The team name is: ' +sg.Name);
        
		System.runAs(usr)//run as a warranty admin profile user
        {
        // Create WO with Product                 
        SVMXC__Service_Order__c  SampleWorkOrder1 = new SVMXC__Service_Order__c (
        RecordTypeId = rt.Id,
		SVMXC__Case__c = cs1.Id ,
        SVMXC__Company__c  = ac.Id , 
        SVMXC__Contact__c = ct.Id,
        Product__c = Part.Id,
        SVMXC__Service_Group__c = sg.Id,
		SVMXC__Priority__c = 'Medium',
		SVMXC__Order_Type__c = 'Field Service',
		Repair_Date__c = System.today(),
        SVMXC__Order_Status__c ='Processing Error',
        Reason_For_Denial__c = 'Test denial'
        );
         
        try{
        insert SampleWorkOrder1;
        }
               catch (Exception e) {
                system.debug('sample work order 1 insert error is '+e.getMessage());
                }     
        System.debug('The work order number is: ' +SampleWorkOrder1.Name);
        
        //assert that the processed date and processed by fields are set correctly on insert
        SVMXC__Service_Order__c wo = [Select Id, Processed_Date__c, Processed_By__c From SVMXC__Service_Order__c Where Id = :SampleWorkOrder1.Id];
        System.assertEquals(wo.Processed_Date__c, System.today());
        System.assertEquals(wo.Processed_By__c, UserInfo.getName());
        
                        
        SVMXC__Service_Order__c  SampleWorkOrder2 = [SELECT Id ,Product__c, SVMXC__Order_Status__c, Reason_For_Denial__c FROM SVMXC__Service_Order__c where Id= :SampleWorkOrder1.Id ];
        SampleWorkOrder2.Product__c = Part.Id;        
        SampleWorkOrder2.SVMXC__Service_Group__c =sg.Id;
        SampleWorkOrder2.SVMXC__Company__c  = ac.Id;
        SampleWorkOrder2.SVMXC__Order_Status__c = 'Warranty Denied';
        SampleWorkOrder2.Reason_For_Denial__c = 'Test denial';
        try{
        update SampleWorkOrder2;
        }
               catch (Exception e) {
                system.debug('svol insert error is '+e.getMessage());
                }
        //assert that the processed date and processed by fields are set correctly on update
        SVMXC__Service_Order__c wo2 = [Select Id, Processed_Date__c, Processed_By__c From SVMXC__Service_Order__c Where Id = :SampleWorkOrder2.Id];
        System.assertEquals(wo.Processed_Date__c, System.today());
        System.assertEquals(wo.Processed_By__c, UserInfo.getName()); 
        
        SampleWorkOrder2.Amount__c = 0;
        SampleWorkOrder2.SVMXC__Order_Status__c = 'Warranty Processed';
        
        try{
        	update SampleWorkOrder2;
        }
        catch (Exception e) {
                System.Assert(e.getMessage().contains ('A dollar amount is required'));
                }
        
                                
        SVMXC__Service_Order__c  SampleWorkOrder3 = new SVMXC__Service_Order__c (
        SVMXC__Case__c = cs2.Id ,
        SVMXC__Contact__c =ct.Id,
        Product__c = Part.Id,
        SVMXC__Company__c  = ac.Id,
        Product_Model__c = 'Automation',
        Installation_Date__c = System.today(),
        SVMXC__Order_Status__c = 'Open',
        SVMXC__Priority__c = 'Medium',
        SVMXC__Order_Type__c = 'Field Service',
        Street__c = '123 test street',
        City__c = 'test city',
        State__c = 'test state',
        CaseProductGroup__c = 'Filter',
        Case_Problem_Code__c = 'FP93: WS STOCKING',
        SVMXC__Problem_Description__c = 'test description',
        SVMXC__Service_Group__c =sg.Id,
        RecordTypeId = rt1.Id); 
        try{
        insert SampleWorkOrder3;
        }
               catch (Exception e) {
                system.debug('svol insert error is '+e.getMessage());
                }
        
        SVMXC__Service_Order__c  SampleWorkOrder4 =  [SELECT Id ,Product__c FROM SVMXC__Service_Order__c where Id= :SampleWorkOrder1.Id ];
        SampleWorkOrder2.Product__c = Part.Id;
        SampleWorkOrder2.SVMXC__Service_Group__c =sg.Id;
        SampleWorkOrder2.SVMXC__Company__c  = ac.Id;
        try{
        update SampleWorkOrder4;
        }
               catch (Exception e) {
                system.debug('svol insert error is '+e.getMessage());
                } 
        }                  
     }

 

  • July 23, 2013
  • Like
  • 0