• Mike @ BlackTab
  • NEWBIE
  • 55 Points
  • Member since 2012
  • Developer
  • BlackTab Group

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 48
    Questions
  • 81
    Replies

I have a strange problem where a DML update to a record doesn't actually update the record. Here's an example:

 

Test Method:

 

@isTest(SeeAllData=true)
    static void TestChatterAlert(){
    	Test.startTest();
    	User u = [SELECT id, Default_Chatter_Group__c FROM User LIMIT 1];
    	u.Default_Chatter_Group__c = 'Professional Services';
    	update u;
    	
    	Account a = new Account(Name = 'Test Account');
    	insert a;
    	
    	Opportunity o = new Opportunity(
    		Name = 'Test Opportunity',
    		AccountId = a.id,
    		StageName = 'Pre-Opportunity',
    		Amount = 500,
            Chatter_Created__c = false,
    		CloseDate = Date.today(),
    		OwnerId = u.id
    	);
    	insert o;

    	Opportunity opp = [SELECT id, StageName FROM Opportunity WHERE Id = :o.id LIMIT 1];
    	opp.StageName = 'Information Gathering';
        opp.Chatter_Created__c = false;
    	update opp;
    	Test.stopTest();
    }

 

Code To Cover:

 

if((Trigger.isAfter && (Trigger.isUpdate || Trigger.isInsert)) || Test.isRunningTest()){
		If(TriggerMonitor.ExecutedTriggers.contains('OpportunityChatter')) return;
		TriggerMonitor.ExecutedTriggers.add('OpportunityChatter');
		
		//Opportunity Chatter Trigger
		for(Opportunity o : Trigger.New){
			if(Trigger.isUpdate){
				system.debug('new stage name: ' + o.stagename + ' old stage name: ' + Trigger.oldMap.get(o.id).StageName);
				if((o.StageName == 'Information Gathering' && Trigger.oldMap.get(o.id).StageName == 'Pre-Opportunity' && o.Chatter_Created__c != true) || Test.isRunningTest()){
					//Get owner information
					User u = [SELECT id, Firstname, Lastname, Default_Chatter_Group__c FROM User WHERE id = :o.OwnerId LIMIT 1];
					//Get Account Information
					Account a = [SELECT id, Account_Type__c, BillingCity, BillingState FROM Account WHERE id = :o.AccountId LIMIT 1];
					
					if(u.Default_Chatter_Group__c != null){
						//Find Chatter Group
						List<CollaborationGroup> cgs = [SELECT id, name FROM CollaborationGroup WHERE name = :u.Default_Chatter_Group__c LIMIT 1];
						
						//Post to Chatter Group
						if(cgs.size() > 0){
							FeedItem post = new FeedItem();
							post.ParentId = cgs[0].id;
							post.Body = u.Firstname + ' ' + u.Lastname + ' has uncovered another Qualified Opportunity for a ' + a.Account_Type__c + ' in ' + a.BillingCity + ',' + a.BillingState + '\n\n' +
							            'Equipment Detail/Purpose:' + o.Equipment_Detail_Purpose__c + '\n' +
							            'Amount: $' + o.Amount + '\n' +
							            'Term: ' + o.Term__c + '\n' +
							            'Likely Structure: ' + o.Likely_Structure__c + '\n' +
							            'Estimated Close Date: ' + o.CloseDate.format();
							insert post;
							
							//Check the Chatter_Created__c on the related opp
							Opportunity oppToUpdate = new Opportunity(id=o.id, Chatter_Created__c = true);
							update oppToUpdate;
						}
					}
				}

 In the trigger, the 5th line that checks for Trigger.IsUpdate() is not covered by the test class. It just doesn't make any sense. 

 

Any help would be great. Thanks

Hello,

 

In the following javascript, i'm trying to 1.) Query a case 2.) Update a field based on a page parameter. When I try to update the case, salesforce is kicking back an error:

 

failed to update case {errors:{message:'sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.', statusCode:'INVALID_TYPE', }, id:null, success:'false', }

 

Here is the code:

 

  	function chooseRep(id){
            var fieldName = '{!$CurrentPage.parameters.field}';
            
            sforce.connection.sessionId = '{!$Api.Session_ID}';
            var result = sforce.connection.query("SELECT id, Sales_Rep__c, NDS_Assigned__c FROM Case WHERE ID = \'{!$CurrentPage.parameters.id}\'");
            
            
            
            if(fieldName == 'SalesRep'){
                result.records.Sales_Rep__c = id;
            }else{
            	result.recoreds.NDS_Assigned__c = id;       
            }
            
            var result2 = sforce.connection.update([result.records.Id]);
            if (result2[0].getBoolean("success")) {
    			alert("case with id " + result2[0].id + " updated");
  			} else {
    			alert("failed to update case " + result2[0]);
  			}
            
            var previousCase = "{!$CurrentPage.parameters.id}";
            window.location.href = "/" + previousCase;
        }

I'm thinking I need to cast the "result" variable to a case, but i'm not exactly sure how to do that via the Ajax Toolkit.

 

Thanks! 

 

I'm trying to implement the <support:clickToDial> component on a visualforce page, and it won't connect to the CTI adapter (Shoretel). It just has a greyed out phone icon and when you hover over it it says "Click to Dial Disabled". We know that the CTI adapter is set up correctly because we can click on normal phone fields within salesforce. 

Hello,

 

I was wondering if anyone had experience with implementing Click-To-Call on a VisualForce page. I tried useing the new <support:clickToCall> component, however it doesn't actually render the number as a link. Any insite would be greatly appreciated. 

I have a visualforce controller that creates a list of related_addresses__c records, and when I try to access this list the apex:input fields don't populate any data. Any Idea why this would be happening? Could this be a Summer '13 bug?

 

VF:

 

<apex:page standardController="Pre_Delivery_Inspection__c" extensions="addRelatedAddressesController" sidebar="true" showHeader="true" showChat="false">
  <apex:form id="Related_Address_Form">
      <div style="width:600px; margin: 0 auto;">
      <apex:sectionHeader title="Add Related Addresses" description="Relate Addresses to a Pre-Delivery Inspection"/>
      <apex:messages />
      
      <apex:pageblock >
          <apex:pageBlockButtons >
              <apex:commandButton value="Save" action="{!save}"/>
              <apex:commandButton value="Cancel" action="{!Cancel}"/>
              <apex:commandButton value="Add Row" action="{!addrow}" immediate="false" rerender="table,error"/>
              <apex:commandButton value="Remove Row" action="{!removeRow}" immediate="false" rerender="table,error"/>
          </apex:pageBlockButtons>
          
          <apex:pageblockTable value="{!relatedAddresses}" var="a" id="table" width="600px">
              <apex:column headerValue="Related Addresses" >
                  <apex:selectList value="{!a.Address__c}" multiselect="false" size="1">
                      <apex:selectOptions value="{!RelatedAddressOptions}"/>
                  </apex:selectList>
              </apex:column>
              <apex:column headerValue="Address Type">
                  <apex:inputField value="{!a.Address_Type__c}" />
              </apex:column>
          </apex:pageblockTable>
      </apex:pageblock>
      
      <!--This is an example, and should be removed -->
      <apex:selectList multiselect="false" size="1">
             <apex:selectOptions value="{!RelatedAddressOptions}"/>
      </apex:selectList>
      </div>
  </apex:form>
</apex:page>

 Controller:

 

public with sharing class addRelatedAddressesController {

    //Class Variables
    public List<Related_Addresses__c> relatedAddresses {get; set;}
    private final Pre_Delivery_Inspection__c pdi;
    public String accountId = ApexPages.currentPage().getParameters().get('acctid');
    public String preDeliveryInspectionId = ApexPages.currentPage().getParameters().get('pdiid');
    
    public addRelatedAddressesController(ApexPages.StandardController controller) {
        this.pdi = (Pre_Delivery_Inspection__c)controller.getRecord();
        relatedAddresses = new List<Related_Addresses__c>();
        
        for(Integer i = 0; i < 4; i++){
            Related_Addresses__c initRelatedAddress = new Related_Addresses__c();
            initRelatedAddress.Related_PDI__c = preDeliveryInspectionId;
            relatedAddresses.add(initRelatedAddress);
        }
    }
    
    public List<SelectOption> getRelatedAddressOptions(){
        List<SelectOption> addressOptions = new List<SelectOption>();
        addressOptions.add(new SelectOption('', '--None--'));
        //Select Related Address Records
        if(accountId != null){
            List<Address__c> relatedAddressList = [SELECT id, Name FROM Address__c WHERE Account__c = :accountId 
                                                   AND Address_Type__c INCLUDES ('Title To', 'Register To', 'DOT Info')];
            
            
            for(Address__c address : relatedAddressList){
               addressOptions.add(new SelectOption(address.Id, address.Name));
            }
        }
       System.debug('Address Option Count: ' + addressOptions.Size());
       return addressOptions;
    }
    
    public void addRow(){
       Related_Addresses__c newRelatedAddress = new Related_Addresses__c();
       newRelatedAddress.Related_PDI__c = preDeliveryInspectionId;
       relatedAddresses.add(newRelatedAddress);
    }
    
    public void removeRow(){
        Integer i = relatedAddresses.size();
        if(i != 0){
            relatedAddresses.remove(i-1);
        }
    }
    
    public pageReference save(){
        //Validate fields before saving
        Integer j = 0;
        while(j < relatedAddresses.size()){
            if(relatedAddresses.get(j).Address__c == null || relatedAddresses.get(j).Address_Type__c == null){
                relatedAddresses.remove(j);
            }else{
                j++;
            }
        }
        insert relatedAddresses;
        
        PageReference back = new PageReference('/' + preDeliveryInspectionId);
        back.setRedirect(true);
        return back;
    }
    
    public pageReference cancel(){
        
        PageReference back = new PageReference('/' + preDeliveryInspectionId);
        back.setRedirect(true);
        return back;
    }

}

 

I'm trying to use the CTI Toolkit, more specifically the sforce.console.cti.sendCTIMessage() function to enable click-to-dial on a Visualforce page. 

 

I'm running into a cross-domain security issue, and the browser console is simply outputting: "Service Clout Toolkit API cannot be used with your browser."

 

Is there another way to enable Click-To-Dial within Visualforce? I've seen posts from other users, however they were simply using the sendCTIMessage() within the Service Console or a custom Button or Link within salesforce. 

 

Here's the code I've implemented:

 

<apex:page>
<apex:includeScript value="/support/console/24.0/integration.js"/>
...
<b>Phone: </b><a href="javascript&colon;sforce.console.cti.sendCTIMessage('http://localhost:7332/CLICK_TO_DIAL?DN='+encodeURIComponent('{!IF(cm.LeadID != null, cm.Lead.Phone, cm.Contact.Phone)}')+'&ID={!IF(cm.LeadID != null, cm.Lead.Id, cm.Contact.Id)}&ENTITY_NAME=Contact');"  style="cursor:pointer; cursor:hand; text-decoration:underline;">{!IF(cm.LeadID != null, cm.Lead.Phone, cm.Contact.Phone)}<apex:image rendered="{!IF(ISBLANK(cm.Lead.Phone) && ISBLANK(cm.Contact.Phone), 'false', 'true')}" value="{!$Resource.PhoneIcon}" height="10" width="10" /></a>
...
</apex:page>

 

 

 

Hello,

 

I've experienced some inconsistencies when migrating components from a sandbox to a production org. I made sure I have the most recent copy of the component (Refreshed from server), and when I do a comparison of the XML files, there are no differences. Has anyone else encountered these issues? If so, how were the issues resolved?

 

Thanks

For some reason I cannot get cases to close by setting the status to closed. The "isClosed" checkbox remains unchecked even if I change the status.

 

Here is my code:

 

trigger CloseRelatedOppCases on Opportunity (before update) {

	List<Opportunity> opps = Trigger.new;
	
	for(Opportunity o : opps){
		if(o.StageName == 'Dead/Lost'){
			//Get record type ID of Engineering Engagement Request RT, Credit Verification Request, and Network Qualification Request
			RecordType rt1 = [SELECT id FROM RecordType WHERE Name = 'Engineering Engagement Request' LIMIT 1];
			RecordType rt2 = [SELECT id FROM RecordType WHERE Name = 'Credit Verification Request' LIMIT 1];
			RecordType rt3 = [SELECT id FROM RecordType WHERE Name = 'Network Qualification Request' LIMIT 1];
			
			//Find Associated NDS Cases
			List<Case> engineeringEngagementCases = [SELECT id FROM Case WHERE Opportunity__c = :o.Id AND RecordTypeId = :rt1.Id];
			List<Case> creditVerificationCases = [SELECT id FROM Case WHERE Opportunity__c = :o.Id AND RecordTypeId = :rt2.Id];
			List<Case> networkQualificationCases = [SELECT id FROM Case WHERE Opportunity__c = :o.Id AND RecordTypeId = :rt3.Id];
			
			//Combine All Cases into one list
			List<Case> cases = new List<Case>();
			cases.addall(engineeringEngagementCases);
			cases.addall(creditVerificationCases);
			cases.addall(networkQualificationCases);
			
			//Loop Through Cases and Set Status to Opportunity Dead/
			for(Case c : cases){
					c.Status = 'Opportunity Dead/Lost';
			}
			
			update cases;
		}
	}

}

 

Hello,

 

Is there a way to add the "Social Media Header" to a VF page? So the Account/Contact photo, Linkedin, Twitter, FB, etc. linking functions.

 

I did some investigation, and it looks like it uses an internal JS library called SocialCrm.js (However it's compiled and looks rather nasty). 

 

Maybe they're is a VF component, or component attribute im missing on the <apex:detail> component?

 

Thanks in advanced. 

I have a VF page that contains a few apex:commandlinks with an apex:param that passes a record id to an apex:detail component. 

 

The Problem: When I click the command link the top portion of the apex:detail component reRenders fine, but in order to refresh the related lists, you have to click the command button again. 

 

Here is a sample of the code:

 

<apex:commandLink style="color:red" action="{!changePreview}" value="{!gchildren.Name}" reRender="preview">
<apex:param name="currentRecord" assignTo="{!currentRecord}" value="{!gchildren.Id}"/>
</apex:commandLink>

 

<apex:outputpanel rendered="{!showPreview}" id="preview" style="float:left; margin-left:10px; width:850px; padding: 5px; border:#1797C0 5px solid; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px;" >
    <h1 style="font-size: 20px; color:red;">{!IF(currentRecord == null, "Select A Record To Preview", "")}</h1>
    <apex:detail subject="{!currentRecord}" title="false" inlineEdit="true" relatedListHover="false" showChatter="false" />
</apex:outputpanel>

 The changePreview() method is of type PageReference, and simply returns a null value

Hello, I would like to use the apex:listViews component (From multiple objects) on one page. For example, I want to show the list view for Accounts, Contacts, and Opportunities on one page. Is this possible? If so, could you provide an example?

I need a way for a user to pick any ListView they created, and turn it into a SOQL statement. Is this possible? If so, what would it take to do it?

	//RollUpTime Trigger Test
	static testMethod void testRollUpTime(){
		Project2__c project = new Project2__c();
		project.Name = 'Test Project';
		insert project;
		
		Milestone_NEW__c milestone = new Milestone_NEW__c();
		milestone.Name = 'Test Milestone';
		milestone.Project__c = project.Id;
		insert milestone;
		
		Deliverable__c deliverable = new Deliverable__c();
		deliverable.Name = 'Test Deliverable';
		deliverable.Milestone_NEW__c = milestone.Id;
		deliverable.Billable_Hours_Consumed__c = 0;
		deliverable.Billable_Hours_Planned__c = 0;
		insert deliverable;
		
		ToDo2__c todo = new ToDo2__c();
		todo.Deliverable__c = deliverable.Id;
		todo.Name = 'Test Todo';
		todo.Billable__c = TRUE;
		todo.Hours_Consumed__c = 10.5;
		insert todo;
		
		ToDo2__c todo2 = new ToDo2__c();
		todo2.Deliverable__c = deliverable.Id;
		todo2.Name = 'Test Todo2';
		todo2.Billable__c = FALSE;
		todo2.Hours_Consumed__c = 10.5;
		insert todo2;
		
		todo.Hours_Consumed__c = 15;
		todo2.Hours_Consumed__c = 15;
		update todo;
		update todo2;
		
		delete todo;
		delete todo2;
	}

 Trigger:

trigger RollUpTime on ToDo2__c (after insert, after update, after delete) {
    
    ToDo2__c todo = new ToDo2__c();
    
    if(Trigger.isInsert || Trigger.isUpdate){
        todo = Trigger.new[0];
    }else if(Trigger.isDelete){
        todo = Trigger.old[0];
    }
    
    if(todo.Deliverable__c != null){
    Deliverable__c deliverable = [SELECT id, Billable_Hours_Consumed__c, Billable_Hours_Planned__c, Non_Billable_Hours_Consumed__c, Non_Billable_Hours_Planned__c, Cost_To_Client__c FROM Deliverable__c WHERE id = :todo.Deliverable__c];
    
    //add related todo's time to related deliverable
    if(Trigger.isInsert || Trigger.isUpdate){
        if(todo.Billable__c == True){
            Decimal billableHoursConsumed = deliverable.Billable_Hours_Consumed__c;
            Decimal billableHoursPlanned = deliverable.Billable_Hours_Planned__c;
            Decimal costToClient = deliverable.Cost_To_Client__c;
        
            deliverable.Billable_Hours_Consumed__c = billableHoursConsumed + todo.Hours_Consumed__c;
            deliverable.Billable_Hours_Planned__c = billableHoursPlanned + todo.Hours_Planned__c;
            deliverable.Cost_To_Client__c = costToClient + todo.Cost_To_Client__c;
        }else{
            Decimal nonBillableHoursConsumed = deliverable.Non_Billable_Hours_Consumed__c;
            Decimal nonBillableHoursPlanned = deliverable.Non_Billable_Hours_Planned__c;
        
            deliverable.Non_Billable_Hours_Consumed__c = nonBillableHoursConsumed + todo.Hours_Consumed__c;
            deliverable.Non_Billable_Hours_Planned__c = nonBillableHoursPlanned + todo.Hours_Planned__c;
        }
    }else if(Trigger.isDelete){
        if(todo.Billable__c == True){
            Decimal billableHoursConsumed = deliverable.Billable_Hours_Consumed__c;
            Decimal billableHoursPlanned = deliverable.Billable_Hours_Planned__c;
            Decimal costToClient = deliverable.Cost_To_Client__c;
        
            deliverable.Billable_Hours_Consumed__c = billableHoursConsumed - todo.Hours_Consumed__c;
            deliverable.Billable_Hours_Planned__c = billableHoursPlanned - todo.Hours_Planned__c;
            deliverable.Cost_To_Client__c = costToClient - todo.Cost_To_Client__c;
        }else{
            Decimal nonBillableHoursConsumed = deliverable.Non_Billable_Hours_Consumed__c;
            Decimal nonBillableHoursPlanned = deliverable.Non_Billable_Hours_Planned__c;
        	Decimal costToClient = deliverable.Cost_To_Client__c;
        
            deliverable.Non_Billable_Hours_Consumed__c = nonBillableHoursConsumed - todo.Hours_Consumed__c;
            deliverable.Non_Billable_Hours_Planned__c = nonBillableHoursPlanned - todo.Hours_Planned__c;
            deliverable.Cost_To_Client__c = costToClient = costToClient - todo.Cost_To_Client__c;
        }
    }
    
    update deliverable;
    }
}

 The error occurs when inserting a new todo, and i'm having trouble figuring out what's causing it. Thanks

Background: I have three apex:selectLists that are dependent on one another. When a value is choosen in the first picklist, options in the other picklists become available. 

 

The problem: These picklists were working fine when nested inside an apex:pageBlockSection, however when I moved the code to a jQuery controlled div the values from the select lists are no longer passed to the controller. Any ideas?

 

VF:

 

<apex:selectlist value="{!projectID}" multiselect="false" size="1" style="margin-right: 5px;">
              <apex:selectOption itemvalue="" itemLabel="--Open Projects--" />
              <apex:selectoptions value="{!openProjects}"/>
              <apex:actionsupport event="onchange" rerender="milestoneList"/>
          </apex:selectlist>
          <apex:selectlist value="{!milestoneID}" multiselect="false" size="1" id="milestoneList" style="margin-right: 5px;">
              <apex:selectOption itemvalue="" itemLabel="--Milestones--" />
              <apex:selectoptions value="{!RelatedMilestones}"/>
              <apex:actionsupport event="onchange" rerender="deliverableList"/>
          </apex:selectlist>
          <apex:selectlist value="{!deliverableID}" multiselect="false" size="1" id="deliverableList">
              <apex:selectOption itemvalue="" itemLabel="--Deliverables--" />
              <apex:selectoptions value="{!RelatedDeliverabiles}"/>
          </apex:selectlist>

 Controller:

 

public String projectID {get; set;}
public String milestoneID {get; set;}
public String deliverableID {get; set;}

//Populate the "Related To" Project Picklist
    public List<SelectOption> getOpenProjects() {
        List<SelectOption> options = new List<SelectOption>();
        List<Project2__c> projects = [SELECT Name, ID FROM Project2__c 
                                      WHERE Status__c != 'Completed' 
                                      ORDER BY Name];
        
        for(Project2__c p : projects){
            options.add(new SelectOption(p.ID, p.Name));
        }
        
        return options;
    }
    
    //Populate the "Related To" Milestones Picklist
    public List<SelectOption> getRelatedMilestones() {
        List<SelectOption> options = new List<SelectOption>();
        List<Milestone_NEW__c> milestones = [SELECT Name, ID FROM Milestone_NEW__c 
                                             WHERE Project__c = :projectID 
                                             ORDER BY Name];
        
        for(Milestone_NEW__c m : milestones){
            options.add(new SelectOption(m.ID, m.Name));
        }
        
        return options;
    }
    
    //Populate the "Related To" Deliverablies Picklist
    public List<SelectOption> getRelatedDeliverabiles() {
        List<SelectOption> options = new List<SelectOption>();
        List<Deliverable__c> deliverables = [SELECT Name, ID FROM Deliverable__c 
                                             WHERE Milestone_NEW__c = :milestoneID 
                                             ORDER BY Name];
        
        for(Deliverable__c d : deliverables){
            options.add(new SelectOption(d.ID, d.Name));
        }
        
        return options;
    }

 

Does anyone have experience with using jQuery or the HTML5 "Draggable" feature to implement drag-and-drop capabilites? It seems like every tutorial I find on the web conflicts with the extJS and other internal SF javascript libraries. Any thoughts? Thanks

I'm trying to create 3 custom dependant picklist:

 

Projects, Milestones, and Deliverables

 

The problem i'm having is refreshing the dependant picklists when a parent picklist value is chosen.

 

Here is the code I have so far:

 

VF:

 

<p>Related To:</p>
          <apex:selectlist value="{!projectID}" multiselect="false" size="1">
              <apex:selectOption itemvalue="" itemLabel="--Open Projects--" />
              <apex:selectoptions value="{!openProjects}"/>
              <apex:actionsupport event="onchange" rerender="milestoneList"/>
          </apex:selectlist>
          <apex:selectlist value="{!milestoneID}" multiselect="false" size="1" id="milestoneList">
              <apex:selectOption itemvalue="" itemLabel="--Milestones--" />
              <apex:selectoptions value="{!RelatedMilestones}"/>
          </apex:selectlist>
          <apex:selectlist value="{!deliverableID}" multiselect="false" size="1">
              <apex:selectOption itemvalue="" itemLabel="--Deliverables--" />
              <apex:selectoptions value="{!RelatedDeliverabiles}"/>
          </apex:selectlist>

 

Apex:

 

public String projectID {get; set;}
    public String deliverableID {get; set;}
    public String milestoneID {get; set;}    

public List<SelectOption> getOpenProjects() {
        List<SelectOption> options = new List<SelectOption>();
        List<Project2__c> projects = [SELECT Name, ID FROM Project2__c WHERE Status__c != 'Completed' ORDER BY Name];
        
        for(Project2__c p : projects){
            options.add(new SelectOption(p.ID, p.Name));
        }
        
        return options;
    }
    
    public List<SelectOption> getRelatedMilestones() {
        List<SelectOption> options = new List<SelectOption>();
        List<Milestone_NEW__c> milestones = [SELECT Name, ID FROM Milestone_NEW__c WHERE Project__c = :projectID ORDER BY Name];
        
        for(Milestone_NEW__c m : milestones){
            options.add(new SelectOption(m.ID, m.Name));
        }
        
        return options;
    }
    
    public List<SelectOption> getRelatedDeliverabiles() {
        List<SelectOption> options = new List<SelectOption>();
        List<Deliverable__c> deliverables = [SELECT Name, ID FROM Deliverable__c WHERE Milestone_NEW__c = :milestoneID ORDER BY Name];
        
        for(Deliverable__c d : deliverables){
            options.add(new SelectOption(d.ID, d.Name));
        }
        
        return options;
    }

 

Anytime you try to delete a record in salesforce there is a _CONFIRMATIONTOKEN parameter, I was thinking this was the $Api.Session_Id global variable, but its completely different.

 

 

Is there any way of generating this? Thanks

Hello,

 

I have this simple query:

 

public List<AccountShare> getAccountShares (){
        return [SELECT Account.Name, id, AccountAccessLevel, AccountId, RowCause, UserOrGroupId FROM AccountShare WHERE RowCause != 'Owner'];
    }

 However I'm not sure how to acess the related User/Queue name from the UserOrGroupId field. Do I need a wrapper class?

 

Thanks

Hello,

 

I'm in the process of creating a todo manager. I need a way to relate a todo to almost any object (like an activity). What's the best way to do that?

 

I'm interested in hearing some solutions. Thanks

I have text from a textbox in this date format: 'mm/dd/yyyy' and use the following method to parse it:

 

date mydate = date.parse('12/27/2009');

 However when I try to insert the field into the database I get an Invalid Date Format error

 

What am I missing here?

Background: I have three apex:selectLists that are dependent on one another. When a value is choosen in the first picklist, options in the other picklists become available. 

 

The problem: These picklists were working fine when nested inside an apex:pageBlockSection, however when I moved the code to a jQuery controlled div the values from the select lists are no longer passed to the controller. Any ideas?

 

VF:

 

<apex:selectlist value="{!projectID}" multiselect="false" size="1" style="margin-right: 5px;">
              <apex:selectOption itemvalue="" itemLabel="--Open Projects--" />
              <apex:selectoptions value="{!openProjects}"/>
              <apex:actionsupport event="onchange" rerender="milestoneList"/>
          </apex:selectlist>
          <apex:selectlist value="{!milestoneID}" multiselect="false" size="1" id="milestoneList" style="margin-right: 5px;">
              <apex:selectOption itemvalue="" itemLabel="--Milestones--" />
              <apex:selectoptions value="{!RelatedMilestones}"/>
              <apex:actionsupport event="onchange" rerender="deliverableList"/>
          </apex:selectlist>
          <apex:selectlist value="{!deliverableID}" multiselect="false" size="1" id="deliverableList">
              <apex:selectOption itemvalue="" itemLabel="--Deliverables--" />
              <apex:selectoptions value="{!RelatedDeliverabiles}"/>
          </apex:selectlist>

 Controller:

 

public String projectID {get; set;}
public String milestoneID {get; set;}
public String deliverableID {get; set;}

//Populate the "Related To" Project Picklist
    public List<SelectOption> getOpenProjects() {
        List<SelectOption> options = new List<SelectOption>();
        List<Project2__c> projects = [SELECT Name, ID FROM Project2__c 
                                      WHERE Status__c != 'Completed' 
                                      ORDER BY Name];
        
        for(Project2__c p : projects){
            options.add(new SelectOption(p.ID, p.Name));
        }
        
        return options;
    }
    
    //Populate the "Related To" Milestones Picklist
    public List<SelectOption> getRelatedMilestones() {
        List<SelectOption> options = new List<SelectOption>();
        List<Milestone_NEW__c> milestones = [SELECT Name, ID FROM Milestone_NEW__c 
                                             WHERE Project__c = :projectID 
                                             ORDER BY Name];
        
        for(Milestone_NEW__c m : milestones){
            options.add(new SelectOption(m.ID, m.Name));
        }
        
        return options;
    }
    
    //Populate the "Related To" Deliverablies Picklist
    public List<SelectOption> getRelatedDeliverabiles() {
        List<SelectOption> options = new List<SelectOption>();
        List<Deliverable__c> deliverables = [SELECT Name, ID FROM Deliverable__c 
                                             WHERE Milestone_NEW__c = :milestoneID 
                                             ORDER BY Name];
        
        for(Deliverable__c d : deliverables){
            options.add(new SelectOption(d.ID, d.Name));
        }
        
        return options;
    }

 

I have an object that is filled from fields from another object. I created  a list of the same object type and I need to add the records to it. However it is giving me the Index out of bounds error when I add the record to the list. Here follows the code:

Line__c MELI                = new Line__c();                
List<Line__c> LMELI  = new List<Line__c>();

List<TX__c> Trx     = [SELECT  Id,  Amount__c
                                      FROM TX__c 

integer i = 0;

for (TX__c PMT : Trx) {
             
            MELI.MB__c             = Ref__c;                
            MELI.Tx__c                = PMT.Id;                                       
            MELI.Amount__c      = PMT.Amount__c;   
            LMELI.add(i++, MELI);                                               // The error is on this line                               
                          
    }  // for PMT ends here


I would greatly appreciate any help!

Thank you!
  • April 18, 2014
  • Like
  • 0
Hi I need to show  spaces between rightside and left side of title attribute 


<apex:page >
    <apex:pageBlock title="leftside of title               <Need extra spaces here  >                                                                    rightside of title">

    </apex:pageBlock>
</apex:page>

Regards
Sameer
I have following records in a list and want a disticnt count. e.g Highlighted records will be counted as 4. Basically there are 4 records under the pcode 'can' that are open since 4 weeks 

id       pcode     NumOfWeeksOpen    
111       can          4    
112       can          4
113       can          4
114       can          4

115       can          14
116       can          24   
117       can          45
118       can          34
119       can          37

Any suggestions?

Thanks!!
120       can          65


                         
Hi can we update salesforce records when User Uploads Word documents of a certain template in salesforce 
Have opened a case with Salesforce on this issue but thought I'd reach out to the dev community to see if anyone has any ideas.

Basically the issue occurs when you render a table with a repeating header as a PDF. On the first page the header will be rendered with extra whitespace above. On subsequent pages the header is fine, though in the sample code below that demonstrates the issue I have a border around the table and the top of the border is missing on all pages save the first.

A similar issue occurs with a repeating footer, though in this case the extra whitespace gets added below the footer. The sample code below does not show this behaviour.

One odd thing I've noticed is that if there is sufficient content before the table on the same page the table renders as expected (both first page and all subsequent pages). This can be observed by including the outputPanel in the sample code below.

<apex:page controller="TestPDFController" standardStylesheets="false" showHeader="false" sidebar="false" applyHtmlTag="false" applyBodyTag="false" renderAs="pdf" readOnly="true">
<html>
    <head>
        <style type="text/css">
            @page {
                size: letter portrait;
                margin-top: 1.0in;
                margin-bottom: 1.0in;
                margin-left: 1.0in;
                margin-right: 1.0in;
                counter-increment: page;
                @bottom-right {
                    content: "Page " counter(page)
                }
            }
            body {
                font-family: Arial, sans-serif;
                color: #000;
            }
            .dataTableClass {
                -fs-table-paginate: paginate;
                 border: 1px solid black; 
                 width: 100%;
            }
            .dataTableClass th, .dataTableClass td {
                vertical-align: top;
                text-align: left;
            }
            .dataTableClass .dtColHeader {
                font-size: 9pt;
                font-weight: bold;
            }
            .dataTableClass .dtColData {
                font-size: 9pt;
            }
        </style>
    </head>
  
    <body>
        <apex:outputPanel layout="block" rendered="false">
            <h3>By including these lines the table header...</h3>
            <h3>...renders as expected on all pages</h3>
        </apex:outputPanel>
        <apex:dataTable value="{!accounts}" var="rec" styleClass="dataTableClass" >
            <apex:facet name="header">
                <h3 style="text-align: center;">List of Accounts and Owners</h3>
            </apex:facet>
            <apex:column style="width: 60%;">
                <apex:facet name="header">
                    <apex:outputText value="Account Name" styleClass="dtColHeader" />
                </apex:facet>
                <apex:outputText value="{!rec.Name}" styleClass="dtColData"/>
            </apex:column>
            <apex:column style="width: 40%;">
                <apex:facet name="header">
                    <apex:outputText value="Owner Name" styleClass="dtColHeader" />
                </apex:facet>
                <apex:outputText value="{!rec.Owner.Name}" styleClass="dtColData" />
            </apex:column>
        </apex:dataTable>
    </body>
  
</html>
</apex:page>

public class TestPDFController
{
    public Account[] accounts{get; private set;}

    public TestPDFController()
    {
        init();
    }
  
    private void init()
    {
        this.accounts = [SELECT Id, Name, Owner.Name FROM Account ORDER BY Name LIMIT 100];
    }
}
Has anyone recently have problem using Esclipse to connect to the sandbox source? Since this week my Esclipse has stop working with our sandbox environment. We have turned on mydomain but it should still allow login through test.salesforce.com. But when try to refresh my sources code from sandbox it says it can't connect to test.salesforce.com.

It has been working before but i wonder if SF has done a release that have stop esclips calling to that site. I have even tried reseting my security token to get it working but no luck there. If anyone can help it would be very much appreciated.

I have a strange problem where a DML update to a record doesn't actually update the record. Here's an example:

 

Test Method:

 

@isTest(SeeAllData=true)
    static void TestChatterAlert(){
    	Test.startTest();
    	User u = [SELECT id, Default_Chatter_Group__c FROM User LIMIT 1];
    	u.Default_Chatter_Group__c = 'Professional Services';
    	update u;
    	
    	Account a = new Account(Name = 'Test Account');
    	insert a;
    	
    	Opportunity o = new Opportunity(
    		Name = 'Test Opportunity',
    		AccountId = a.id,
    		StageName = 'Pre-Opportunity',
    		Amount = 500,
            Chatter_Created__c = false,
    		CloseDate = Date.today(),
    		OwnerId = u.id
    	);
    	insert o;

    	Opportunity opp = [SELECT id, StageName FROM Opportunity WHERE Id = :o.id LIMIT 1];
    	opp.StageName = 'Information Gathering';
        opp.Chatter_Created__c = false;
    	update opp;
    	Test.stopTest();
    }

 

Code To Cover:

 

if((Trigger.isAfter && (Trigger.isUpdate || Trigger.isInsert)) || Test.isRunningTest()){
		If(TriggerMonitor.ExecutedTriggers.contains('OpportunityChatter')) return;
		TriggerMonitor.ExecutedTriggers.add('OpportunityChatter');
		
		//Opportunity Chatter Trigger
		for(Opportunity o : Trigger.New){
			if(Trigger.isUpdate){
				system.debug('new stage name: ' + o.stagename + ' old stage name: ' + Trigger.oldMap.get(o.id).StageName);
				if((o.StageName == 'Information Gathering' && Trigger.oldMap.get(o.id).StageName == 'Pre-Opportunity' && o.Chatter_Created__c != true) || Test.isRunningTest()){
					//Get owner information
					User u = [SELECT id, Firstname, Lastname, Default_Chatter_Group__c FROM User WHERE id = :o.OwnerId LIMIT 1];
					//Get Account Information
					Account a = [SELECT id, Account_Type__c, BillingCity, BillingState FROM Account WHERE id = :o.AccountId LIMIT 1];
					
					if(u.Default_Chatter_Group__c != null){
						//Find Chatter Group
						List<CollaborationGroup> cgs = [SELECT id, name FROM CollaborationGroup WHERE name = :u.Default_Chatter_Group__c LIMIT 1];
						
						//Post to Chatter Group
						if(cgs.size() > 0){
							FeedItem post = new FeedItem();
							post.ParentId = cgs[0].id;
							post.Body = u.Firstname + ' ' + u.Lastname + ' has uncovered another Qualified Opportunity for a ' + a.Account_Type__c + ' in ' + a.BillingCity + ',' + a.BillingState + '\n\n' +
							            'Equipment Detail/Purpose:' + o.Equipment_Detail_Purpose__c + '\n' +
							            'Amount: $' + o.Amount + '\n' +
							            'Term: ' + o.Term__c + '\n' +
							            'Likely Structure: ' + o.Likely_Structure__c + '\n' +
							            'Estimated Close Date: ' + o.CloseDate.format();
							insert post;
							
							//Check the Chatter_Created__c on the related opp
							Opportunity oppToUpdate = new Opportunity(id=o.id, Chatter_Created__c = true);
							update oppToUpdate;
						}
					}
				}

 In the trigger, the 5th line that checks for Trigger.IsUpdate() is not covered by the test class. It just doesn't make any sense. 

 

Any help would be great. Thanks

Hello,

 

In the following javascript, i'm trying to 1.) Query a case 2.) Update a field based on a page parameter. When I try to update the case, salesforce is kicking back an error:

 

failed to update case {errors:{message:'sObject type 'sObject' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.', statusCode:'INVALID_TYPE', }, id:null, success:'false', }

 

Here is the code:

 

  	function chooseRep(id){
            var fieldName = '{!$CurrentPage.parameters.field}';
            
            sforce.connection.sessionId = '{!$Api.Session_ID}';
            var result = sforce.connection.query("SELECT id, Sales_Rep__c, NDS_Assigned__c FROM Case WHERE ID = \'{!$CurrentPage.parameters.id}\'");
            
            
            
            if(fieldName == 'SalesRep'){
                result.records.Sales_Rep__c = id;
            }else{
            	result.recoreds.NDS_Assigned__c = id;       
            }
            
            var result2 = sforce.connection.update([result.records.Id]);
            if (result2[0].getBoolean("success")) {
    			alert("case with id " + result2[0].id + " updated");
  			} else {
    			alert("failed to update case " + result2[0]);
  			}
            
            var previousCase = "{!$CurrentPage.parameters.id}";
            window.location.href = "/" + previousCase;
        }

I'm thinking I need to cast the "result" variable to a case, but i'm not exactly sure how to do that via the Ajax Toolkit.

 

Thanks! 

 

I'm trying to implement the <support:clickToDial> component on a visualforce page, and it won't connect to the CTI adapter (Shoretel). It just has a greyed out phone icon and when you hover over it it says "Click to Dial Disabled". We know that the CTI adapter is set up correctly because we can click on normal phone fields within salesforce. 

Hello - I am new to doing more complex language in Custom Report Links and needed some help.  I am trying to create a dynamic link that will check the user's Region ("Americas") and then pull in a different report based on that factor.  

 

I keep getting a syntax error.  Do i need to encase the report links in some url brackets?

 

Thanks,

 

Charlie

 

{!IF(
{!ISPICKVAL($User.Region__c,"Americas")},
/00O80000005EMGc?pv0={!Campaign.Id},
/00O800000057qbj?pv0={!Campaign.Id}
)}

Hi, I am using below code to change my page block background color. body .bPageBlock .pbBody .red .pbSubheader{ background-color:#91AF6A !important; font-weight: bold ; font-face: comic sans ms ; color:#ffffff !important; } When i am using vf page with custom controller it is working fine, But problem is when i am using vf page with standard controller it is not applying background color mentioned above. Kindly help. Regards, Mayur

Hi,

 

For the lookup dialog window that pops up when inputting a lookup relationship in an object, the window that shows up is themed to be light blue and white (standard theme). Is there a way to make the style on this lookup window?

 

I know I can roll my own lookup window, and I've done it for some of the other fields, but there are a ton that I don't really want any changes done except changing the background color itself. Is there an option to change that through salesforce? Or is creating a dynamic lookup the only way?

 

Thanks,

Vivo

  • June 13, 2013
  • Like
  • 0

I have a visualforce controller that creates a list of related_addresses__c records, and when I try to access this list the apex:input fields don't populate any data. Any Idea why this would be happening? Could this be a Summer '13 bug?

 

VF:

 

<apex:page standardController="Pre_Delivery_Inspection__c" extensions="addRelatedAddressesController" sidebar="true" showHeader="true" showChat="false">
  <apex:form id="Related_Address_Form">
      <div style="width:600px; margin: 0 auto;">
      <apex:sectionHeader title="Add Related Addresses" description="Relate Addresses to a Pre-Delivery Inspection"/>
      <apex:messages />
      
      <apex:pageblock >
          <apex:pageBlockButtons >
              <apex:commandButton value="Save" action="{!save}"/>
              <apex:commandButton value="Cancel" action="{!Cancel}"/>
              <apex:commandButton value="Add Row" action="{!addrow}" immediate="false" rerender="table,error"/>
              <apex:commandButton value="Remove Row" action="{!removeRow}" immediate="false" rerender="table,error"/>
          </apex:pageBlockButtons>
          
          <apex:pageblockTable value="{!relatedAddresses}" var="a" id="table" width="600px">
              <apex:column headerValue="Related Addresses" >
                  <apex:selectList value="{!a.Address__c}" multiselect="false" size="1">
                      <apex:selectOptions value="{!RelatedAddressOptions}"/>
                  </apex:selectList>
              </apex:column>
              <apex:column headerValue="Address Type">
                  <apex:inputField value="{!a.Address_Type__c}" />
              </apex:column>
          </apex:pageblockTable>
      </apex:pageblock>
      
      <!--This is an example, and should be removed -->
      <apex:selectList multiselect="false" size="1">
             <apex:selectOptions value="{!RelatedAddressOptions}"/>
      </apex:selectList>
      </div>
  </apex:form>
</apex:page>

 Controller:

 

public with sharing class addRelatedAddressesController {

    //Class Variables
    public List<Related_Addresses__c> relatedAddresses {get; set;}
    private final Pre_Delivery_Inspection__c pdi;
    public String accountId = ApexPages.currentPage().getParameters().get('acctid');
    public String preDeliveryInspectionId = ApexPages.currentPage().getParameters().get('pdiid');
    
    public addRelatedAddressesController(ApexPages.StandardController controller) {
        this.pdi = (Pre_Delivery_Inspection__c)controller.getRecord();
        relatedAddresses = new List<Related_Addresses__c>();
        
        for(Integer i = 0; i < 4; i++){
            Related_Addresses__c initRelatedAddress = new Related_Addresses__c();
            initRelatedAddress.Related_PDI__c = preDeliveryInspectionId;
            relatedAddresses.add(initRelatedAddress);
        }
    }
    
    public List<SelectOption> getRelatedAddressOptions(){
        List<SelectOption> addressOptions = new List<SelectOption>();
        addressOptions.add(new SelectOption('', '--None--'));
        //Select Related Address Records
        if(accountId != null){
            List<Address__c> relatedAddressList = [SELECT id, Name FROM Address__c WHERE Account__c = :accountId 
                                                   AND Address_Type__c INCLUDES ('Title To', 'Register To', 'DOT Info')];
            
            
            for(Address__c address : relatedAddressList){
               addressOptions.add(new SelectOption(address.Id, address.Name));
            }
        }
       System.debug('Address Option Count: ' + addressOptions.Size());
       return addressOptions;
    }
    
    public void addRow(){
       Related_Addresses__c newRelatedAddress = new Related_Addresses__c();
       newRelatedAddress.Related_PDI__c = preDeliveryInspectionId;
       relatedAddresses.add(newRelatedAddress);
    }
    
    public void removeRow(){
        Integer i = relatedAddresses.size();
        if(i != 0){
            relatedAddresses.remove(i-1);
        }
    }
    
    public pageReference save(){
        //Validate fields before saving
        Integer j = 0;
        while(j < relatedAddresses.size()){
            if(relatedAddresses.get(j).Address__c == null || relatedAddresses.get(j).Address_Type__c == null){
                relatedAddresses.remove(j);
            }else{
                j++;
            }
        }
        insert relatedAddresses;
        
        PageReference back = new PageReference('/' + preDeliveryInspectionId);
        back.setRedirect(true);
        return back;
    }
    
    public pageReference cancel(){
        
        PageReference back = new PageReference('/' + preDeliveryInspectionId);
        back.setRedirect(true);
        return back;
    }

}