• tsalb
  • NEWBIE
  • 210 Points
  • Member since 2010

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 50
    Questions
  • 85
    Replies

How would I update a lookup's field from this controller? The value is saved, but no DML is performed because I think my save method is incorrect.

 

Vendor_Name__c on Service_Request__c is a lookup to Contact.

 

public class VendorInvoiceController {

	private final Service_Request__c srf;
	public Contact vendor;
	
	public string orderId = ApexPages.currentPage().getParameters().get('orderId');
	public string vendorId = ApexPages.currentPage().getParameters().get('vendorId');
	public string rfpId = ApexPages.currentPage().getParameters().get('rfpId');

	//Constructor
	public VendorInvoiceController(){
		srf = [SELECT
			   Vendor_Name__r.Name, Vendor_Name__r.Id, Vendor_Name__r.MailingStreet,                                   Vendor_Name__r.Payment_Info__c,
			   Vendor_Invoiced_Received__c
			   FROM Service_Request__c WHERE Id =: orderId];
	}
	
	public Service_Request__c getSrf() {
		return srf;
	}
    
	public pageReference save(){
		vendor = [select Id from Contact where Id =: vendorId];
		//vendor.payment_info__c = 'test';
		update vendor;
		return null;
	}
	
	public pageReference updateMe() {
		update srf;
		return null;
	}

}

 

Page

<apex:page controller="VendorInvoiceController" showHeader="false" sidebar="false">

  <apex:form >
    <apex:pageMessages />
    <apex:pageBlock tabstyle="Service_Request__c">
    
      <apex:pageBlockSection title="Payment Information" id="test">
        <apex:outputfield value="{!srf.Vendor_Name__r.MailingStreet}"/>
        <apex:outputfield value="{!srf.Vendor_Name__r.Payment_Info__c}"/>
      </apex:pageBlockSection>
      
      <apex:pageBlockSection title="Update Me">
        <apex:inputField value="{!srf.Vendor_Name__r.Payment_Info__c}"/> //re-renders but no DML?
        <apex:inputField value="{!srf.Vendor_Invoiced_Received__c}"/>
      </apex:pageBlockSection>
      
      <apex:commandButton value="Update Address" action="{!save}" rerender="test"/>
      <apex:commandbutton value="Update Me" action="{!updateMe}"/>
      
    </apex:pageBlock>
  </apex:form>

</apex:page>

 

  • June 15, 2012
  • Like
  • 0

I'm having a hard time understanding how to initialize a (custom) standard controller in my test method for a example i've modified on a blog. This is borrowed from the blog: http://bobbuzzard.blogspot.co.uk/2011/07/managing-list-of-new-records-in.html.

 

Up until now, I've followed existing examples of test classes to "understand" my way around creating and testing standard controllers and extensions. Can anyone help me understand how to intialize the controller for my test class? For testing this kind of controller - do I need system assert or system assert equals?

 

I'm still trying to understand everything - slowly but surely - thanks for any help

 

Controller

 

public class ScorecardController {
	
 public List<VSCWrapper> wrappers {get; set;}
 public static Integer toDelIdent {get; set;}
 public static Integer addCount {get; set;}
 public String ParentId = ApexPages.currentPage().getParameters().get('ParentId');
 private Integer nextIdent=0;
  
 public ScorecardController() {
   wrappers=new List<VSCWrapper>();
   for (Integer idx=0; idx<1; idx++) {
     wrappers.add(new VSCWrapper(nextIdent++));
   }
 }
  
 public void delWrapper() {
   Integer toDelPos=-1;
   for (Integer idx=0; idx<wrappers.size(); idx++) {
     if (wrappers[idx].ident==toDelIdent) {
       toDelPos=idx;
     }
   }
   
   if (-1!=toDelPos) {
     wrappers.remove(toDelPos);
   }
 }
  
 public void addRows() {
   for (Integer idx=0; idx<addCount; idx++) {
     wrappers.add(new VSCWrapper(nextIdent++));
   }
 }
  
 public PageReference save() {
   List<Vendor_Scorecard__c> accs=new List<Vendor_Scorecard__c>();
   for (VSCWrapper wrap : wrappers) {
     accs.add(wrap.acc);
   }
   insert accs;
   return new PageReference('/' + ParentId);
 }
  
 public class VSCWrapper {
   public Vendor_Scorecard__c acc {get; private set;}
   public Integer ident {get; private set;}
   public String ParentId = ApexPages.currentPage().getParameters().get('ParentId');
  
   public VSCWrapper(Integer inIdent) {
     ident=inIdent;
     acc=new Vendor_Scorecard__c(Service_Request__c = ParentId);
   }
 }
 
//------------------------Begin Test Method------------------------

public static testMethod void testScorecardController() {
    
    //Create test Task Order
    Task_Order__c t = new Task_Order__c(Name = 'TestClassDemo');
    Insert t;	       
    
    //Create test Account
    Account a = new Account(Name = 'TestClassDemo', Task_Order__c = t.Id, Lin__c = '9999');
    Insert a;
   
    //Create test Contact
    Contact c = new Contact(LastName = 'TestClassDemo', AccountId = a.Id);
    Insert c; 
    
    //Create test Service Request
    Service_Request__c sr = new Service_Request__c(Task_Order__c = t.Id);
    Insert sr;
    
    Vendor_Scorecard__c vsc = new Vendor_Scorecard__c(Service_Request__c = sr.Id, Vendor__c = c.Id);
  	  	
    //Set the Test Page
    PageReference sc  = new PageReference('/apex/?'+sr.Id);
    Test.setCurrentPage(sc);
    
    ApexPages.StandardController se = new ApexPages.StandardController(vsc);   //PROBLEM LINE
       
    //Test Controller
    PageReference sP = se.save();
    
    //Test Controller Methods (need)
    se.ScorecardController();
    se.delWrapper();
    se.addRows();
    se.VSCWrapper();
   
        
}

//------------------------End Test Method------------------------    
 
 
}

 

 

Page

<apex:page controller="ScorecardController" tabstyle="Vendor_Scorecard__c">
 <apex:form style="width:40%">
   <apex:pageBlock title="Bulk Creation">
   <apex:outputText value="Additional items only - not clone(s) of existing"/>
      <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

         <apex:column headerValue="Service Request">
            <apex:inputField value="{!wrapper.acc.Service_Request__c}"/>
         </apex:column>
         <apex:column headerValue="Vendor Name">
            <apex:inputField value="{!wrapper.acc.Vendor__c}"/>
         </apex:column>
         <apex:column headerValue="Action">
            <apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> 
            </apex:commandButton>
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/> 
      </apex:commandButton>

      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
 </apex:form>
</apex:page>

 

  • June 07, 2012
  • Like
  • 0

I've used a pretty awesome trigger template, and I've tested that the trigger behavior is working as expected (knock on wood). I took it from a peer's blog (http://blog.deadlypenguin.com/blog/2012/02/13/classifying-triggers-in-salesforce/) and it's working well.

 

The logic of the trigger automatically inserts child records (Vendor_Scorecard__c) lookup to the parent (Service_Request__c) if Service Request is in Status of 'In Review'.

 

I'm having trouble on the test class, I need to query for the existence of child VSCs and assert that they inserted properly, but i'm not sure how. I also have another issue from a pre-existing trigger (too many SOQL) but i'm not sure why it hits the limit.

 

This tests a lot of triggers...and some are poorly written so I can't set test data over 5 records or it fails (that's another problem, not for today). How would I query for the created Vendor_Scorecard__c for each of the srf's in the list?

 

static testMethod void addVendorIdTest() {   
	
	//Create test Task Order
	Task_Order__c t = new Task_Order__c(Name = 'Test Task Order');
	Insert t;	       
	
	//Create test Account
	Account a = new Account(Name = 'Test', Task_Order__c = t.Id, Lin__c = '9999');
	Insert a;
   
	//Create test Contact
	Contact c = new Contact(LastName = 'Test', AccountId = a.Id, Vendor_Id__c = '123ABC');
	Insert c; 
	
	//Create test Service Request BULK
	List <Service_Request__c> srfTestList = new List <Service_Request__c>();
	  for (integer i=0; i<5; i++) {
		Service_Request__c sr = new Service_Request__c(
			Task_Order__c = t.Id, 
			Vendor_Id__c = '123ABC', 
			Status__c = 'New'
		);
		  srfTestList.add(sr);
	  }
			
	  insert srfTestList;
	  
	  test.startTest();  
	  for(Service_Request__c srf: srfTestList) {
		srf.Status__c = 'In Review';
		update srf;  	
	  }
	  test.stopTest();
				
	List <Service_Request__c> insertedSRFs = [Select Vendor_Name__c, Id FROM Service_Request__c WHERE Id IN: srfTestList];
	
	String testVendor = [SELECT Vendor_Name__c FROM Service_Request__c WHERE Id = :srfTestList LIMIT 1].Vendor_Name__c;
	
	for (Service_Request__c s: insertedSRFs){
	  System.assertEquals(c.Id, testVendor);
	}
	
}

 

This is the method (classified trigger) that creates the Vendor_Scorecard__c objects for each srf in srfList. Ignore the excessive comments, that's for me...

 

public void doAwesomeness() {
	
	if (isUpdate) {
		
	  set<Id> objIds = new Set<Id>();
	  
	  for (Service_Request__c srf: newObjs) {
		if (
			oldMap.get(srf.ID) != null &&
			oldMap.get(srf.ID).Status__c != srf.Status__c &&
			srf.Status__c == 'In Review'
		) {
		  //Set for unique IDs for records that pass conditionals above 
			objIds.add(srf.Id);
		}
	  }
	  
	  //Maybe don't need where Status statement, since it's done above?
	  //List is to house records that have passed conditions above		  
	  List <Service_Request__c> srfList =
		[SELECT Status__c, Id, Vendor_Name__c
		 FROM Service_Request__c
		 WHERE Status__c = 'In Review'
		 AND Id IN: objIds];
	  
	  //List for update of VSCs added, for each of the srf in the list above
	  List<Vendor_Scorecard__c> vscList = new List<Vendor_Scorecard__c>();

	  //for records in list, iterate through and use values from those records to create new child VSCs
	  for (Service_Request__c srf: srfList){
		Vendor_Scorecard__c vsc = new Vendor_Scorecard__c (
			Service_Request__c = srf.Id, 
			Vendor__c = srf.Vendor_Name__c,
			RecordTypeId = '012800000007dww');
		vscList.add(vsc);
	  }
	  if (!vscList.isEmpty()) {
		try {
		  insert vscList;
		} catch (DmlException e) {}
	  }
	//End Routing Boolean, return necessary?     
	} else {
	  return;
	}
}

 

 

 

 

 

  • June 01, 2012
  • Like
  • 0

I have a really simple extension to override save behavior - but I can't get it to redirect to the object's lookup relationship record?

 

Hardcoding the Account__c (lookup ID) seems to work fine. Commenting out the pagereference redirects, and just updating sub works fine too. I'm still pretty new to Apex/Visualforce so what am I missing here?

 

public class SubmissionExtension {
	
	private final Submissions__c sub;
	
	//Controller
	public SubmissionExtension(ApexPages.StandardController sCon) {
    	this.sub = (Submissions__c)sCon.getRecord();
    }
	
	//Overrides default save method - no redirects (which default save does)
    public PageReference save() {
    	
        update sub;
        PageReference redirect = new PageReference('/' + sub.Account__c);
        //PageReference redirect = new PageReference('/001S000000WPXVR');
        return redirect;
        
    }
    
}

 

<apex:page standardController="Submissions__c" extensions="SubmissionExtension" showHeader="false" sidebar="false">

<apex:form >
<table border="1" cellpadding="5" cellspacing="0" frame="border" style="width:100%">
        <tr>
            <td width="98%" height="60px">
                1. TEST<br/>
                <apex:inputTextArea style="width:100%; height:40px;" value="{!Submissions__c.q1e__c}" id="q1e"/></td>
            <td colspan="2">       
                <apex:selectRadio value="{!Submissions__c.q1__c}" layout="lineDirection">
           			<apex:selectoption itemValue="true"></apex:selectoption>
           			<apex:selectoption itemValue="false"></apex:selectoption>
       			</apex:selectradio></td>
        </tr>

    </tbody>        
</table>

<apex:commandButton value="Save Accord Form" action="{!save}" id="thebutton"/>

</apex:form>

</apex:page>

 

  • May 18, 2012
  • Like
  • 0

I was wondering if something like this is possible through S controls and a JS button?

 

The attachment would need to be on the Service_Request__c object, but the Id for the visualforce page references a different object (Proposal__c)

 

I'm getting the error (Expected ';' ) and I can't tell where i'm going wrong...

 

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/24.0';

try {
	var strQuery="Select Id from Proposal__c where Status__c = 'Awarded' and Service_Request__c = '"+'{!Proposal__c.Service_RequestId__c}'+"'";
	var LoeID = sforce.connection.query(strQuery);
	PageReference savePDF = new PageReference('/apex/vendorloe?rfpId='+LoeID);
	Blob pdfBlob = savePDF.getContent();
	var thisOb = new sforce.SObject("Service_Request__c");
		thisOb.Id = "{!Service_Request__c.Id}";
	var Atch = new sforce.SObject("Attachment");
		Atch.ParentId = thisOb.Id;
		Atch.Name = 'Letter of Engagement'+'.pdf'; 
		Atch.ContentType = 'pdf';
		ATch.Body = pdfBlob;
	
	result = sforce.connection.insert([Atch]);
} 
catch(er) {
	alert(er);
}

 

 

 

  • May 17, 2012
  • Like
  • 0

I'm not sure how to get my page to appear as a standard page layout visualforce insert. When accessing the page normally via url (/apex/page?rfpId=<record id>) it works fine. However when accessing via the salesforce url (naX.salesforce.com/<record ID>) the page layout insert errors "Content cannot be displayed: List has no rows for assignment to SObject"

 

I know this is an extension issue, but I'm not clear on where to make my edits so that my standard layout can access my visualforce page. 

 

The record where the VFpage Insert (Standard Layout) is, is the record ID that needs to be passed. I know it has something to do with getRecord(); but I'm not sure where to apply it.

 

EDIT: Ah, I need to add that this Page is rendered as a PDF.

 

Proposal Extension:

 

public with sharing class ProposalExtension {

    public String rfpId = ApexPages.currentPage().getParameters().get('rfpId'); 
    private final Proposal__c p;
    
    //Constructor for ProposalExtension	
    public ProposalExtension(ApexPages.StandardController pCon) {
        this.p = (Proposal__c)pCon.getRecord();
    }
	
	//Proposal used for vendor pages 
    Proposal__c rfp;
	
    public Proposal__c getRFP(){
    	rfp = [SELECT 
	    //Proposal Fields Examples
	    Id, Name, Contracting_Manager_Email__c
	    //Vendor (Contact) Fields Examples
	    Vendor__r.Name, Vendor__r.Account.Name
		
		FROM Proposal__c WHERE Id = :rfpId];	
		
		return rfp;	
    }      

}

 

 Sample VF page content:

Company:<apex:outputField value="{!rfp.Vendor__r.Account.Name}"/><br/>

 

  • April 27, 2012
  • Like
  • 0

Can named portal users use a javascript onclick button? I'm getting a cryptic error message from the customer portal side - but i've tested and the button works for internal users.

 

The profile has API enabled, and i've tried combinations of API only User, Portal Super User to no avail.

 

The error: 

 

Remote invocation failed, due to: (Lots of html markup,seems like my generic error page)

then...

Page Not Found: /portal/services/Soap/u/24.0

  • April 24, 2012
  • Like
  • 0

Is it possible to update multiple records from a detail page button with the help of a query? I know it's possible to do this with a list, but here's the scenario:

 

User recommends child record - changes a status and a boolean. Other child records also need to have their boolean(s) toggled to true. However, the button is on the detail page - NOT a list. 

 

The following works great:

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);

result = sforce.connection.update(newRecords);

location.reload(true);

 

 

However, I'm trying to introduce this, where Ideally i'd like to update other child records (with the same parent (Order__c) lookup)

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var otherP = sforce.connection.query("Select Id from Proposal__c where Order__c = '{!Proposal__c.OrderId__c}'  ");
otherP.test__c = true;
newRecords.push(otherP);  //Add all other records to array?

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);   //Add current detail page record to array

result = sforce.connection.update(newRecords);

location.reload(true);

 

  • April 23, 2012
  • Like
  • 0

Is it possible to update multiple records from a detail page button with the help of a query? I know it's possible to do this with a list, but here's the scenario:

 

User recommends child record - changes a status and a boolean. Other child records also need to have their boolean(s) toggled to true. However, the button is on the detail page - NOT a list. 

 

The following works great:

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);

result = sforce.connection.update(newRecords);

location.reload(true);

 

 

However, I'm trying to introduce this, where Ideally i'd like to update other child records (with the same parent (Order__c) lookup)

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var otherP = sforce.connection.query("Select Id from Proposal__c where Order__c = '{!Proposal__c.OrderId__c}'  ");
otherP.test__c = true;
newRecords.push(otherP);  //Add all other records to array?

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);   //Add current detail page record to array

result = sforce.connection.update(newRecords);

location.reload(true);
 

 

  • April 23, 2012
  • Like
  • 0

I have an existing search (contacts) page, but wanted to add booleans to filter out results. So, if boolean A is ticked, i only want accounts with a picklist value of "A" and if B is ticked, only accounts with picklist values of B. If both ticked, both sets.

 

With the help of a peer, I've gotten a little further on this - but I'm wondering why this throws the following error:

 

caused by: System.NullPointerException: Attempt to de-reference a null object

External entry point

Class.ProposalExtension.vendorSearch: line 325, column 1

 

Visualforce page snippet: Extensions = ProposalExtension

 

            <apex:pageBlockSection title="Vendor Panel Options">
            	<apex:pageBlockSectionItem >
            		<apex:outputLabel for="civasPanel" value="Enable Shared Panel"/>
            		<apex:inputCheckbox id="civasPanel" value="{!includeA}"/>
            	</apex:pageBlockSectionItem>
            	<apex:pageBlockSectionItem >
            		<apex:outputLabel for="civasPanel2" value="Enable Private Panel"/>
            		<apex:inputCheckbox id="civasPanel2" value="{!includeB}"/>
            	</apex:pageBlockSectionItem>
            </apex:pageBlockSection>

 

ProposalExtension line 325 highlighted below

 

public with sharing class ProposalExtension {

    public Boolean includeA {get; set;} //Experimenting with vPanel toggle
    public Boolean includeB {get; set;}
    
    private final Proposal__c p;
    
    public ProposalExtension(ApexPages.StandardController pCon) {
        this.p = (Proposal__c)pCon.getRecord();
    }
    
    //Used to create lookup fields for Vendor Search
    Contact con;
    public Contact getCon() {
      if(con == null) con = new Contact();
      con.RecordTypeId = '012A00000007dJ4'; //Set the Record Type to "Vendor"   
      return con;
    }
    
    //Create a Wrapper/Container class for Vendors to be used in implementing a checkbox list
    public class checkedVendor{
    	public Contact ven {get;set;}
    	public Boolean checked {get;set;}
    	
    	//Constructor method for checkedVendors class
    	public checkedVendor(Contact v){
    		ven = v;
    		checked = false;
    	}
    }

	//Create a list of new wrapper class/container object checkedVendors 
	public List<checkedVendor> vendorList {get;set;}
	
	//Create a PageReference to execute the Vendor Search
	public PageReference vendorSearch() {
		vendorList = new List<checkedVendor>();
		
		List<String> picklistVals = new List<String>();
		if(includeA) {
			picklistVals.add('Shared');
		}
		if(includeB) {
			picklistVals.add('Private');
		}
				
		if(radius == 0) {
			radius = 1;
		}
		//Creates an instance of Vendor Search
		VendorSearch vs = new VendorSearch();
		
		try {			
			//Query for Vendors within the selected Radius, matching Type, and Primary Specialty
//LINE 325	for(Contact v : vs.searchVendors(con.Primary_County__c, radius, con.Type__c, con.Primary_Specialty__c, picklistVals)){
				//Add a checkbox to each Vendor that is returned in the search
				vendorList.add(new checkedVendor(v));
        	}
		}
		catch(QueryException q) {
		}
		return null;
	}

}

 VendorSearch, i've highlighted the problem line.

 

public with sharing class VendorSearch {

    public Id countyId; //County to be used as starting point
    public Integer radius = 1; //Desired radius in miles from starting point
    public String vType; //Desired Vendor Type
    public String specialty; //Desired Vendor Specialty
    public String noSpecialty; //No Vendor Specialty place holder
    public List<String> picklistVals; //experimenting with panel pickval
    
    public VendorSearch() {
    }   
 	 	
    //Create a list of Contacts to hold available Vendors 
	public List<Contact> searchVendors(Id startingCounty, Integer searchRadius, String vendorType, String vendorSpecialty, List <String> pVals) {
		
		countyId = startingCounty;
    	radius = searchRadius;
    	vType = vendorType;
    	specialty = vendorSpecialty;
    	noSpecialty = vendorSpecialty;
    	pVals = picklistVals;
    	
    	if(noSpecialty == NULL){
    		noSpecialty = '%';
    	}
		
		List<Contact> vendors;
						
		try {						
			//Get the County Ids from the map and create Set for the search query
			Set<Id> radiusSet = radiusMap().keySet();  
			
			//Query for Vendors within the selected Radius, matching Type, and Primary Specialty
			vendors = (List<Contact>)[SELECT Id, Name, Account.Name, Account.Revos_Status__c, Designation__c, Phone, Email,
									 Primary_County__c, Type__c, Status__c, Status_Sort__c,
									 Overall_Rating__c, RecordTypeId, Minority_Status__c
			FROM Contact 
			WHERE Primary_County__c IN :radiusSet 
//PROBLEM	AND Account.Revos_Status__c IN :pVals  //Trying to filter out results from booleans on visualforce page
			AND Type__c INCLUDES (:vType) 
			AND (Primary_Specialty__c LIKE :noSpecialty OR Primary_Specialty__c LIKE :specialty)
			ORDER BY Status_Sort__c ASC, Overall_Rating__c DESC];
		}
		catch(QueryException q) {
		}	
		return vendors;
	}    

}

 

 

 

  • April 18, 2012
  • Like
  • 0

I'm having trouble wrapping my head around passing a variable to an extension, which calls to another extension and the variable has to actually be used in that 2nd extension.

 

What I'm trying to do is allow for my search page to have a "toggle". If a boolean is ticked, to include an entire list of (specific) Accounts to be returned (REVOS_Status__c = "Shared") and if it's not toggled, to exclude that list. I'm not really sure how best to approach this.

 

The business scenario is that we are querying a list of Accounts and Contacts - Let's say Account 1 has a status of "Shared", it should be included in this query if {!vendorPanel} boolean is ticked. 

 

If Account 2 has a status of "Shared 2", and the related toggle (Example: {!shared2}) on the VFpage is toggled, the query would need to incldue al ist of all Accounts with that status.

 

Ideally, if the boolean is true on the VFpage, it's to be included in the final query. Does this use case make sense?

 

 

Here's the rub.

 

Visualforce Page, extensions="ProposalExtension"

            <apex:pageBlockSection title="Vendor Panel Option">
            	<apex:pageBlockSectionItem >
            		<apex:outputLabel for="civasPanel" value="Enable VMS Panel"/>
            		<apex:inputCheckbox id="civasPanel" value="{!vendorPanel}"/>
            	</apex:pageBlockSectionItem>
            </apex:pageBlockSection>

 

ProposalExtension: (trimmed to relevent code)

public with sharing class ProposalExtension {

    public String rfpId = ApexPages.currentPage().getParameters().get('rfpId'); 
    public String vendorId = ApexPages.currentPage().getParameters().get('vendorId');
    public String orderId = ApexPages.currentPage().getParameters().get('orderId');
    public String orderType = ApexPages.currentPage().getParameters().get('orderType');
    public Integer radius {get; set;} //Set the radius for the Vendor Search
    public Boolean vendorPanel {get; set;} //Experimenting with vPanel toggle //this is what i want to pass to VendorSearch
    
    private final Proposal__c p;
    
    //Constructor for ProposalExtension	
    public ProposalExtension(ApexPages.StandardController pCon) {
        this.p = (Proposal__c)pCon.getRecord();
    }

    //Used to create lookup fields for Vendor Search
    Contact con;
    
    public Contact getCon() {
      if(con == null) con = new Contact();
      con.RecordTypeId = '012A00000007dJ4'; //Set the Record Type to "Vendor"   
      return con;
    }
    
    //Create a Wrapper/Container class for Vendors to be used in implementing a checkbox list
    public class checkedVendor{
    	public Contact ven {get;set;}
    	public Boolean checked {get;set;}
    	
    	//Constructor method for checkedVendors class
    	public checkedVendor(Contact v){
    		ven = v;
    		checked = false;
    	}
    }
	//Create a list of new wrapper class/container object checkedVendors 
	public List<checkedVendor> vendorList {get;set;}
	
	//Create a PageReference to execute the Vendor Search
	public PageReference vendorSearch() {
		try {			
			vendorList = new List<checkedVendor>();
			
			//Check to see if Radius is 0 and set to 1
			if(radius == 0) {
				radius = 1;
			}
			
			//Creates an instance of Vendor Search
			VendorSearch vs = new VendorSearch();
			
			//Query for Vendors within the selected Radius, matching Type, and Primary Specialty
			for(Contact v : vs.searchVendors(con.Primary_County__c, radius, con.Type__c, con.Primary_Specialty__c)){
				//Add a checkbox to each Vendor that is returned in the search
				vendorList.add(new checkedVendor(v));
        	}
		}
		//Catch any query exceptions
		catch(QueryException q) {
		}
		return null;
	}
}

 

VendorSearch (trimmed to relevant code)

public with sharing class VendorSearch {

    public Id countyId; //County to be used as starting point
    public Integer radius = 1; //Desired radius in miles from starting point
    public String vType; //Desired Vendor Type
    public String specialty; //Desired Vendor Specialty
    public String noSpecialty; //No Vendor Specialty place holder
    public Boolean vendorPanel = false; //testing - do not keep false in...      //Not sure how to get this from the ProposalExtension
    public Double lat; //Latitude for starting point
    public Double lon; //Longitude for starting point
    
    //Constructor for ContactRadiusSearch
    public VendorSearch() {
    }   
 	 	
    //Create a list of Contacts to hold available Vendors 
    public List<Contact> searchVendors(Id startingCounty, Integer searchRadius, String vendorType, String vendorSpecialty) {
	countyId = startingCounty;
	radius = searchRadius;
	vType = vendorType;
	specialty = vendorSpecialty;
	//Used to return Vendors with or without Primay Specialties
	noSpecialty = vendorSpecialty;
	
	if(noSpecialty == NULL){
		noSpecialty = '%';
	}
    	
	lat = double.valueOf([SELECT Latitude__c FROM County__c WHERE Id = :countyId].Latitude__c); 
	lon = double.valueOf([SELECT Longitude__c FROM County__c WHERE Id = :countyId].Longitude__c);
		
	List<Contact> vendors;
	
        if(vendorPanel = true){					
	   try {						
		//Get the County Ids from the map and create Set for the search query
		Set<Id> radiusSet = radiusMap().keySet();  	
		//Query for Vendors within the selected
		vendors = (List<Contact>)[SELECT Id, Name, Account.Name, Account.Revos_Status__c, Designation__c, Phone, Email,
			FROM Contact 
			WHERE Primary_County__c IN :radiusSet 
			AND Account.Revos_Status__c = 'Shared'          //Trying to get different list
			AND Type__c INCLUDES (:vType) 
			ORDER BY Status_Sort__c ASC, Overall_Rating__c DESC];
	    }
	    catch(QueryException q) {
	    }
	
        }else if(vendorPanel = false){
	    try{
	 	Set<Id> radiusSet = radiusMap().keySet();  
		vendors = (List<Contact>)[SELECT Id, Name, Account.Name, Account.Revos_Status__c, Designation__c, Phone, Email,
			FROM Contact 
			WHERE Primary_County__c IN :radiusSet 
			AND Account.Revos_Status__c = 'Private'        //trying to get different list
			AND Type__c INCLUDES (:vType) 
			ORDER BY Status_Sort__c ASC, Overall_Rating__c DESC];
	    }
	    catch(QueryException q) {	
	    }
        }
	return vendors;
    }

 

  • April 17, 2012
  • Like
  • 0

Are there any tools that are designed specifically to aid in the migration of exporting sharepoint documents (with metadata) and restructure them so they are stored in Amazon S3?

Or, has anyone done such a migration and can highlight the tool(s) used to do it? Maybe first exporting the SP Files + Metadata, and another tool that renames them all (with the metadata used as a template for file renaming) so re-uploading it to S3 would just be copy paste?

I've found a couple tools that does the first half (export with metadata) such as SPLIST - but nothing that's all encompassing yet.

 

The last piece of this is that my SF org already has an integration with AWS S3, and i'll need to somehow....get that Sharepoint metadata to help with recreating all the File (S3) records in salesforce...so the records all point back to their respective AWS S3 bucket file(s).

 

This is a doozy. 

  • April 10, 2012
  • Like
  • 0

How would I make it so that one radio selector shows up (one on left, one on right) column? The actual radio works fine, it's just a layout issue at this point if it's even possible.

 

Example

 

This the visualforce:

 

    <tbody>
         <tr>
            <td width="90%">
                <b>General Information</b> (Explain all Yes Responses)</td>
            <td>
                Yes</td>
            <td>
                No</td>
        </tr>
        
        <tr>
            <td width="90%" height="60px">
                1. TEST QUESTION ONE <br/>
                <apex:inputTextArea style="width:100%; height:40px;" value="{!Submissions__c.q1e__c}" id="q1e"/></td>
            <td>       
                <apex:selectRadio value="{!Submissions__c.q1__c}" layout="lineDirection" required="true">
           			<apex:selectoption itemValue="true"></apex:selectoption>
           			<apex:selectoption itemValue="false"></apex:selectoption>
       			</apex:selectradio></td>
           	<td>		  
			</td>
        </tr>

 I tried just putting the second option and the closing </apex:selectRadio> tag in the other column - but that's no go.

 

  • March 15, 2012
  • Like
  • 0

I basically copied the functionality for the original trigger (maps an external id field from one record, to another external id field, and changes the lookup value to that - this is for Salesforce to Salesforce)

 

I added AccountIds modelled after CountyIds - i just added another set of queries/fields/maps etc. Is there a better way to do this other than what i have below?

 

trigger AddCountyId on Contact (before insert, before update) {
	
	//Create a unique list of Counties
    Set<String> CountyIds = new Set<String>();
    Set<String> AccountIds = new Set<String>();
    
    for(Contact c : Trigger.new) {       
       CountyIds.add(c.fdicCountyID__c);
       AccountIds.add(c.fdicAccountID__c); 
    }       
    
  	//Create a Map to match up Contact FDIC County Id and FDIC County Id
    Map<String, Id> countyMap = new Map<String,Id>();
    Map<String, Id> accountMap = new Map<String,Id>();

	//Add both sets of IDS to above Map
	for(County__c cty : [SELECT cty.Id, cty.fdicCountyID__c
		FROM County__c cty
		WHERE cty.fdicCountyID__c != null AND cty.fdicCountyID__c IN :CountyIds]) {
    		countyMap.put(cty.fdicCountyID__c, cty.Id);
	}
	
	for(Account acct : [SELECT acct.Id, acct.fdicAccountID__c
		FROM Account acct 
		WHERE acct.fdicAccountID__c != null AND acct.fdicAccountID__c IN :AccountIds]) {
			accountMap.put(acct.fdicAccountID__c, acct.Id);	
	}    
  
  	//Update Primary County on the Contact with County ID
        for(Contact updateC : Trigger.new) {
	    try {    
	          if(updateC.fdicCountyID__c != null || updateC.fdicAccountID__c != null) {
	  			  //Update Primary County with County Id from Map
	              updateC.Primary_County__c = countyMap.get(updateC.fdicCountyID__c);
	              updateC.AccountId = accountMap.get(updateC.fdicAccountID__c);
	          }
	    }  
	    catch (Exception e) {
	   	}
	}

}

 

  • March 07, 2012
  • Like
  • 0

I have an established connection between two orgs, and forwarding Accounts brings over the account attachments, and all the the Contacts - however NOT the contact attachments. 

 

Is it not possible or have i configured something incorrectly?

  • March 06, 2012
  • Like
  • 0

I need some help wrapping my head around testing this trigger - I seem to have prepared and inserted my dataset correct, but I'm not sure why it's giving me an error of "Expected:Null".

 

My Trigger (working in sandbox, manually inserting records)

 

trigger AddCountyId on Contact (before insert, before update) {
	
    Set<String> CountyIds = new Set<String>();
    
    for(Contact c : Trigger.new) {       
       CountyIds.add(c.fdicCountyID__c);       
    }       
    
    Map<String, Id> countyMap = new Map<String,Id>();

	//Add both sets of IDS to above Map
	for(County__c cty : [SELECT cty.Id, cty.fdicCountyID__c
		FROM County__c cty
		WHERE cty.fdicCountyID__c != null AND cty.fdicCountyID__c IN :CountyIds]) {
    		countyMap.put(cty.fdicCountyID__c, cty.Id);
		}    
  
  	//Update Primary County on the Contact with County ID
    for(Contact updateC : Trigger.new) {
	    try {    
	          if(updateC.fdicCountyID__c != null) {
	  			  //Update Primary County with County Id from Map
	              updateC.Primary_County__c = countyMap.get(updateC.fdicCountyID__c);
	          }
	    }  
	    catch (Exception e) {
	   	}
	}

}

 

Stripped down test method in my test class

 

	static testMethod void verifyCountyId() {
		
		//Create Test County
  		County__c cty = new County__c(Name='Test County', Latitude__c = 1, Longitude__c = 1, fdicCountyId__c ='abcd1234');
  		insert cty;
		
		//Create Test Vendor
		Account vAcct = new Account(Name = 'Test Vendor Account');
		insert vAcct;
		Contact v = new Contact(LastName = 'Vendor Demo', last_engaged_date__c = Date.today(), AccountId = vAcct.Id, fdicCountyId__c = 'abcd1234');
		insert v;
		
		System.assertEquals (v.Primary_County_ID__c, cty.Id);
	}

 I get a System.AssertException: Assertion Failed: Expected:null Actual: a0hJ000000FymvMac 

 

Does anyone have any insight as to what i'm doing wrong?

  • February 27, 2012
  • Like
  • 0

I need some help taking this SOQL outside of the for loop - but i'm having trouble constructing a query (I usually use __r notation within the SOQL) to traverse to related objects - I'm nto sure how to do this for Users since it's not really a related object - not unless they've been enabled on the contact.

 

Requestor__c is a lookup to a contact, which may or may not be an active customer portal user. This is an old piece of code I'm trying to update and make more efficient.

 

trigger changeOrderOwner on Order__c (before insert, before update) {

	try {
		for(Order__c o : Trigger.new) {
			o.OwnerId = [SELECT u.Id FROM User u WHERE u.ContactId = :o.Requester__c].Id;
		}
	}
	catch(Exception e) {
		
	}	

}

 

  • February 22, 2012
  • Like
  • 0

Another board member helped me develop this trigger - but I need a little advice on where to head for testing this trigger. I Read through http://teachmesalesforce.wordpress.com/2011/05/07/how-to-write-a-trigger-test/ but had some hard time understanding...

 

From what I can understand, I'd have to create a contact, an order, and then try to populate the fields and do testing? Can anyone provide some guidance?

 

Edit - cleaned up my trigger a bit.

 

trigger lastEngagedDate on Order__c (after insert, after update) {

	set<id>must=new set<id>();
		for(Order__c o : Trigger.new) {
        	must.add(o.Vendor_Name__c);
        }
        
        Order__c o = [SELECT Valuation_Contracted_Date__c, Status__c, Vendor_Name__c
        		FROM Order__c
        		WHERE Vendor_Name__c IN:must 
        		ORDER BY Valuation_Contracted_Date__c DESC 
        		LIMIT 1];
            				
	List<Contact> vendor = new List<Contact>();
        if(o.Status__c=='Valuation Contracted' && o.Valuation_Contracted_Date__c!=null) {
	vendor.add(new Contact(Id = o.Vendor_name__c, Last_Engaged_Date__c = o.Valuation_Contracted_Date__c));
	update vendor;
        }

}

 

  • February 17, 2012
  • Like
  • 0

So here's the use case.

 

I have a custom object (Order__c) which has a lookup to a Contact (Vendor_Name__c, on the Order Object). Contacts do not have lookups to Order.

 

On the Order, there is a Valuation_Contracted_Date__c field. A contact can have multiple Orders (10, 50, 150) - and i'd like for this trigger to always set on the Contact (Last_Engaged_Date__c) to the latest Contracted Date.

 

So I think I have something...but it needs help. Right now the error is "Save error: Didn't understand relationship 'Order__c' in FROM part of query call."

 

 

tldr; query all orders on that contact, order by valuation contracted date descending, limit 1. take that date and update the contact with it.

 

trigger lastEngagedDate on Order__c (before insert, before update) {

	try {
		for(Order__c o : Trigger.new) {
			
			Contact c = [SELECT Last_Engaged_Date__c, 
				(SELECT Valuation_Contracted_Date__c FROM Order__c WHERE c.Id = :Vendor_Name__c ORDER BY                                        Valuation_Contracted_Date__c DESC LIMIT 1) 
				FROM Contact 
					WHERE Id = :o.Vendor_Name__c];
			
			if(o.Status__c == 'Valuation Received') {		
				c.Last_Engaged_Date__c = o.Valuation_Contracted_Date__c;
				update c;			
			} 
		}
	}
	catch(Exception e) {		
	}	
	
}

 

Attempt #2 - still doesn't work?

 

trigger lastEngagedDate on Order__c (before insert, before update) {

	try {
		for(Order__c o : Trigger.new) {
			Contact c = [SELECT Id, Last_Engaged_Date__c FROM Contact WHERE Id = :o.Vendor_Name__c];	
			Order__c o = [SELECT Valuation_Contracted_Date__c FROM Order__c WHERE c.Id =:o.Vendor_Name__c
							ORDER BY Valuation_Contracted_Date__c
							LIMIT 1];
			
			if(o.Status__c == 'Valuation Received') {
				c.Last_Engaged_Date__c = o.Valuation_Contracted_Date__c;
				update c;
			} 
		}
	}
	catch(Exception e) {
	}
	
}

 


 


  • February 17, 2012
  • Like
  • 0

Can Customer Portal Profile users create accounts - with a custom controller?

 

They do not have create or edit access to the Accounts object normally, but was wonderingn if I were to create a custom controller - can I bypass this?

 

The license type is Customer Portal Manager Custom (or Standard).

  • February 13, 2012
  • Like
  • 0

How would I update a lookup's field from this controller? The value is saved, but no DML is performed because I think my save method is incorrect.

 

Vendor_Name__c on Service_Request__c is a lookup to Contact.

 

public class VendorInvoiceController {

	private final Service_Request__c srf;
	public Contact vendor;
	
	public string orderId = ApexPages.currentPage().getParameters().get('orderId');
	public string vendorId = ApexPages.currentPage().getParameters().get('vendorId');
	public string rfpId = ApexPages.currentPage().getParameters().get('rfpId');

	//Constructor
	public VendorInvoiceController(){
		srf = [SELECT
			   Vendor_Name__r.Name, Vendor_Name__r.Id, Vendor_Name__r.MailingStreet,                                   Vendor_Name__r.Payment_Info__c,
			   Vendor_Invoiced_Received__c
			   FROM Service_Request__c WHERE Id =: orderId];
	}
	
	public Service_Request__c getSrf() {
		return srf;
	}
    
	public pageReference save(){
		vendor = [select Id from Contact where Id =: vendorId];
		//vendor.payment_info__c = 'test';
		update vendor;
		return null;
	}
	
	public pageReference updateMe() {
		update srf;
		return null;
	}

}

 

Page

<apex:page controller="VendorInvoiceController" showHeader="false" sidebar="false">

  <apex:form >
    <apex:pageMessages />
    <apex:pageBlock tabstyle="Service_Request__c">
    
      <apex:pageBlockSection title="Payment Information" id="test">
        <apex:outputfield value="{!srf.Vendor_Name__r.MailingStreet}"/>
        <apex:outputfield value="{!srf.Vendor_Name__r.Payment_Info__c}"/>
      </apex:pageBlockSection>
      
      <apex:pageBlockSection title="Update Me">
        <apex:inputField value="{!srf.Vendor_Name__r.Payment_Info__c}"/> //re-renders but no DML?
        <apex:inputField value="{!srf.Vendor_Invoiced_Received__c}"/>
      </apex:pageBlockSection>
      
      <apex:commandButton value="Update Address" action="{!save}" rerender="test"/>
      <apex:commandbutton value="Update Me" action="{!updateMe}"/>
      
    </apex:pageBlock>
  </apex:form>

</apex:page>

 

  • June 15, 2012
  • Like
  • 0

I've used a pretty awesome trigger template, and I've tested that the trigger behavior is working as expected (knock on wood). I took it from a peer's blog (http://blog.deadlypenguin.com/blog/2012/02/13/classifying-triggers-in-salesforce/) and it's working well.

 

The logic of the trigger automatically inserts child records (Vendor_Scorecard__c) lookup to the parent (Service_Request__c) if Service Request is in Status of 'In Review'.

 

I'm having trouble on the test class, I need to query for the existence of child VSCs and assert that they inserted properly, but i'm not sure how. I also have another issue from a pre-existing trigger (too many SOQL) but i'm not sure why it hits the limit.

 

This tests a lot of triggers...and some are poorly written so I can't set test data over 5 records or it fails (that's another problem, not for today). How would I query for the created Vendor_Scorecard__c for each of the srf's in the list?

 

static testMethod void addVendorIdTest() {   
	
	//Create test Task Order
	Task_Order__c t = new Task_Order__c(Name = 'Test Task Order');
	Insert t;	       
	
	//Create test Account
	Account a = new Account(Name = 'Test', Task_Order__c = t.Id, Lin__c = '9999');
	Insert a;
   
	//Create test Contact
	Contact c = new Contact(LastName = 'Test', AccountId = a.Id, Vendor_Id__c = '123ABC');
	Insert c; 
	
	//Create test Service Request BULK
	List <Service_Request__c> srfTestList = new List <Service_Request__c>();
	  for (integer i=0; i<5; i++) {
		Service_Request__c sr = new Service_Request__c(
			Task_Order__c = t.Id, 
			Vendor_Id__c = '123ABC', 
			Status__c = 'New'
		);
		  srfTestList.add(sr);
	  }
			
	  insert srfTestList;
	  
	  test.startTest();  
	  for(Service_Request__c srf: srfTestList) {
		srf.Status__c = 'In Review';
		update srf;  	
	  }
	  test.stopTest();
				
	List <Service_Request__c> insertedSRFs = [Select Vendor_Name__c, Id FROM Service_Request__c WHERE Id IN: srfTestList];
	
	String testVendor = [SELECT Vendor_Name__c FROM Service_Request__c WHERE Id = :srfTestList LIMIT 1].Vendor_Name__c;
	
	for (Service_Request__c s: insertedSRFs){
	  System.assertEquals(c.Id, testVendor);
	}
	
}

 

This is the method (classified trigger) that creates the Vendor_Scorecard__c objects for each srf in srfList. Ignore the excessive comments, that's for me...

 

public void doAwesomeness() {
	
	if (isUpdate) {
		
	  set<Id> objIds = new Set<Id>();
	  
	  for (Service_Request__c srf: newObjs) {
		if (
			oldMap.get(srf.ID) != null &&
			oldMap.get(srf.ID).Status__c != srf.Status__c &&
			srf.Status__c == 'In Review'
		) {
		  //Set for unique IDs for records that pass conditionals above 
			objIds.add(srf.Id);
		}
	  }
	  
	  //Maybe don't need where Status statement, since it's done above?
	  //List is to house records that have passed conditions above		  
	  List <Service_Request__c> srfList =
		[SELECT Status__c, Id, Vendor_Name__c
		 FROM Service_Request__c
		 WHERE Status__c = 'In Review'
		 AND Id IN: objIds];
	  
	  //List for update of VSCs added, for each of the srf in the list above
	  List<Vendor_Scorecard__c> vscList = new List<Vendor_Scorecard__c>();

	  //for records in list, iterate through and use values from those records to create new child VSCs
	  for (Service_Request__c srf: srfList){
		Vendor_Scorecard__c vsc = new Vendor_Scorecard__c (
			Service_Request__c = srf.Id, 
			Vendor__c = srf.Vendor_Name__c,
			RecordTypeId = '012800000007dww');
		vscList.add(vsc);
	  }
	  if (!vscList.isEmpty()) {
		try {
		  insert vscList;
		} catch (DmlException e) {}
	  }
	//End Routing Boolean, return necessary?     
	} else {
	  return;
	}
}

 

 

 

 

 

  • June 01, 2012
  • Like
  • 0

I have a really simple extension to override save behavior - but I can't get it to redirect to the object's lookup relationship record?

 

Hardcoding the Account__c (lookup ID) seems to work fine. Commenting out the pagereference redirects, and just updating sub works fine too. I'm still pretty new to Apex/Visualforce so what am I missing here?

 

public class SubmissionExtension {
	
	private final Submissions__c sub;
	
	//Controller
	public SubmissionExtension(ApexPages.StandardController sCon) {
    	this.sub = (Submissions__c)sCon.getRecord();
    }
	
	//Overrides default save method - no redirects (which default save does)
    public PageReference save() {
    	
        update sub;
        PageReference redirect = new PageReference('/' + sub.Account__c);
        //PageReference redirect = new PageReference('/001S000000WPXVR');
        return redirect;
        
    }
    
}

 

<apex:page standardController="Submissions__c" extensions="SubmissionExtension" showHeader="false" sidebar="false">

<apex:form >
<table border="1" cellpadding="5" cellspacing="0" frame="border" style="width:100%">
        <tr>
            <td width="98%" height="60px">
                1. TEST<br/>
                <apex:inputTextArea style="width:100%; height:40px;" value="{!Submissions__c.q1e__c}" id="q1e"/></td>
            <td colspan="2">       
                <apex:selectRadio value="{!Submissions__c.q1__c}" layout="lineDirection">
           			<apex:selectoption itemValue="true"></apex:selectoption>
           			<apex:selectoption itemValue="false"></apex:selectoption>
       			</apex:selectradio></td>
        </tr>

    </tbody>        
</table>

<apex:commandButton value="Save Accord Form" action="{!save}" id="thebutton"/>

</apex:form>

</apex:page>

 

  • May 18, 2012
  • Like
  • 0

I was wondering if something like this is possible through S controls and a JS button?

 

The attachment would need to be on the Service_Request__c object, but the Id for the visualforce page references a different object (Proposal__c)

 

I'm getting the error (Expected ';' ) and I can't tell where i'm going wrong...

 

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/24.0';

try {
	var strQuery="Select Id from Proposal__c where Status__c = 'Awarded' and Service_Request__c = '"+'{!Proposal__c.Service_RequestId__c}'+"'";
	var LoeID = sforce.connection.query(strQuery);
	PageReference savePDF = new PageReference('/apex/vendorloe?rfpId='+LoeID);
	Blob pdfBlob = savePDF.getContent();
	var thisOb = new sforce.SObject("Service_Request__c");
		thisOb.Id = "{!Service_Request__c.Id}";
	var Atch = new sforce.SObject("Attachment");
		Atch.ParentId = thisOb.Id;
		Atch.Name = 'Letter of Engagement'+'.pdf'; 
		Atch.ContentType = 'pdf';
		ATch.Body = pdfBlob;
	
	result = sforce.connection.insert([Atch]);
} 
catch(er) {
	alert(er);
}

 

 

 

  • May 17, 2012
  • Like
  • 0

I'm not sure how to get my page to appear as a standard page layout visualforce insert. When accessing the page normally via url (/apex/page?rfpId=<record id>) it works fine. However when accessing via the salesforce url (naX.salesforce.com/<record ID>) the page layout insert errors "Content cannot be displayed: List has no rows for assignment to SObject"

 

I know this is an extension issue, but I'm not clear on where to make my edits so that my standard layout can access my visualforce page. 

 

The record where the VFpage Insert (Standard Layout) is, is the record ID that needs to be passed. I know it has something to do with getRecord(); but I'm not sure where to apply it.

 

EDIT: Ah, I need to add that this Page is rendered as a PDF.

 

Proposal Extension:

 

public with sharing class ProposalExtension {

    public String rfpId = ApexPages.currentPage().getParameters().get('rfpId'); 
    private final Proposal__c p;
    
    //Constructor for ProposalExtension	
    public ProposalExtension(ApexPages.StandardController pCon) {
        this.p = (Proposal__c)pCon.getRecord();
    }
	
	//Proposal used for vendor pages 
    Proposal__c rfp;
	
    public Proposal__c getRFP(){
    	rfp = [SELECT 
	    //Proposal Fields Examples
	    Id, Name, Contracting_Manager_Email__c
	    //Vendor (Contact) Fields Examples
	    Vendor__r.Name, Vendor__r.Account.Name
		
		FROM Proposal__c WHERE Id = :rfpId];	
		
		return rfp;	
    }      

}

 

 Sample VF page content:

Company:<apex:outputField value="{!rfp.Vendor__r.Account.Name}"/><br/>

 

  • April 27, 2012
  • Like
  • 0

Is it possible to update multiple records from a detail page button with the help of a query? I know it's possible to do this with a list, but here's the scenario:

 

User recommends child record - changes a status and a boolean. Other child records also need to have their boolean(s) toggled to true. However, the button is on the detail page - NOT a list. 

 

The following works great:

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);

result = sforce.connection.update(newRecords);

location.reload(true);

 

 

However, I'm trying to introduce this, where Ideally i'd like to update other child records (with the same parent (Order__c) lookup)

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var otherP = sforce.connection.query("Select Id from Proposal__c where Order__c = '{!Proposal__c.OrderId__c}'  ");
otherP.test__c = true;
newRecords.push(otherP);  //Add all other records to array?

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);   //Add current detail page record to array

result = sforce.connection.update(newRecords);

location.reload(true);

 

  • April 23, 2012
  • Like
  • 0

Is it possible to update multiple records from a detail page button with the help of a query? I know it's possible to do this with a list, but here's the scenario:

 

User recommends child record - changes a status and a boolean. Other child records also need to have their boolean(s) toggled to true. However, the button is on the detail page - NOT a list. 

 

The following works great:

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);

result = sforce.connection.update(newRecords);

location.reload(true);

 

 

However, I'm trying to introduce this, where Ideally i'd like to update other child records (with the same parent (Order__c) lookup)

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}

var newRecords = [];

var otherP = sforce.connection.query("Select Id from Proposal__c where Order__c = '{!Proposal__c.OrderId__c}'  ");
otherP.test__c = true;
newRecords.push(otherP);  //Add all other records to array?

var thisP = new sforce.SObject("Proposal__c");
thisP.id = "{!Proposal__c.Id}";
thisP.Status__c = "Awarded";
thisP.test__c = true;
newRecords.push(thisP);   //Add current detail page record to array

result = sforce.connection.update(newRecords);

location.reload(true);
 

 

  • April 23, 2012
  • Like
  • 0

I have an existing search (contacts) page, but wanted to add booleans to filter out results. So, if boolean A is ticked, i only want accounts with a picklist value of "A" and if B is ticked, only accounts with picklist values of B. If both ticked, both sets.

 

With the help of a peer, I've gotten a little further on this - but I'm wondering why this throws the following error:

 

caused by: System.NullPointerException: Attempt to de-reference a null object

External entry point

Class.ProposalExtension.vendorSearch: line 325, column 1

 

Visualforce page snippet: Extensions = ProposalExtension

 

            <apex:pageBlockSection title="Vendor Panel Options">
            	<apex:pageBlockSectionItem >
            		<apex:outputLabel for="civasPanel" value="Enable Shared Panel"/>
            		<apex:inputCheckbox id="civasPanel" value="{!includeA}"/>
            	</apex:pageBlockSectionItem>
            	<apex:pageBlockSectionItem >
            		<apex:outputLabel for="civasPanel2" value="Enable Private Panel"/>
            		<apex:inputCheckbox id="civasPanel2" value="{!includeB}"/>
            	</apex:pageBlockSectionItem>
            </apex:pageBlockSection>

 

ProposalExtension line 325 highlighted below

 

public with sharing class ProposalExtension {

    public Boolean includeA {get; set;} //Experimenting with vPanel toggle
    public Boolean includeB {get; set;}
    
    private final Proposal__c p;
    
    public ProposalExtension(ApexPages.StandardController pCon) {
        this.p = (Proposal__c)pCon.getRecord();
    }
    
    //Used to create lookup fields for Vendor Search
    Contact con;
    public Contact getCon() {
      if(con == null) con = new Contact();
      con.RecordTypeId = '012A00000007dJ4'; //Set the Record Type to "Vendor"   
      return con;
    }
    
    //Create a Wrapper/Container class for Vendors to be used in implementing a checkbox list
    public class checkedVendor{
    	public Contact ven {get;set;}
    	public Boolean checked {get;set;}
    	
    	//Constructor method for checkedVendors class
    	public checkedVendor(Contact v){
    		ven = v;
    		checked = false;
    	}
    }

	//Create a list of new wrapper class/container object checkedVendors 
	public List<checkedVendor> vendorList {get;set;}
	
	//Create a PageReference to execute the Vendor Search
	public PageReference vendorSearch() {
		vendorList = new List<checkedVendor>();
		
		List<String> picklistVals = new List<String>();
		if(includeA) {
			picklistVals.add('Shared');
		}
		if(includeB) {
			picklistVals.add('Private');
		}
				
		if(radius == 0) {
			radius = 1;
		}
		//Creates an instance of Vendor Search
		VendorSearch vs = new VendorSearch();
		
		try {			
			//Query for Vendors within the selected Radius, matching Type, and Primary Specialty
//LINE 325	for(Contact v : vs.searchVendors(con.Primary_County__c, radius, con.Type__c, con.Primary_Specialty__c, picklistVals)){
				//Add a checkbox to each Vendor that is returned in the search
				vendorList.add(new checkedVendor(v));
        	}
		}
		catch(QueryException q) {
		}
		return null;
	}

}

 VendorSearch, i've highlighted the problem line.

 

public with sharing class VendorSearch {

    public Id countyId; //County to be used as starting point
    public Integer radius = 1; //Desired radius in miles from starting point
    public String vType; //Desired Vendor Type
    public String specialty; //Desired Vendor Specialty
    public String noSpecialty; //No Vendor Specialty place holder
    public List<String> picklistVals; //experimenting with panel pickval
    
    public VendorSearch() {
    }   
 	 	
    //Create a list of Contacts to hold available Vendors 
	public List<Contact> searchVendors(Id startingCounty, Integer searchRadius, String vendorType, String vendorSpecialty, List <String> pVals) {
		
		countyId = startingCounty;
    	radius = searchRadius;
    	vType = vendorType;
    	specialty = vendorSpecialty;
    	noSpecialty = vendorSpecialty;
    	pVals = picklistVals;
    	
    	if(noSpecialty == NULL){
    		noSpecialty = '%';
    	}
		
		List<Contact> vendors;
						
		try {						
			//Get the County Ids from the map and create Set for the search query
			Set<Id> radiusSet = radiusMap().keySet();  
			
			//Query for Vendors within the selected Radius, matching Type, and Primary Specialty
			vendors = (List<Contact>)[SELECT Id, Name, Account.Name, Account.Revos_Status__c, Designation__c, Phone, Email,
									 Primary_County__c, Type__c, Status__c, Status_Sort__c,
									 Overall_Rating__c, RecordTypeId, Minority_Status__c
			FROM Contact 
			WHERE Primary_County__c IN :radiusSet 
//PROBLEM	AND Account.Revos_Status__c IN :pVals  //Trying to filter out results from booleans on visualforce page
			AND Type__c INCLUDES (:vType) 
			AND (Primary_Specialty__c LIKE :noSpecialty OR Primary_Specialty__c LIKE :specialty)
			ORDER BY Status_Sort__c ASC, Overall_Rating__c DESC];
		}
		catch(QueryException q) {
		}	
		return vendors;
	}    

}

 

 

 

  • April 18, 2012
  • Like
  • 0

So here's the thing, I realize that salesforce does not support the running of getContentAsPDF from a trigger -- which consiquently, is a royal pain. That said, I decided to embark on a journey to accomplish the task anyway. I've gone a bit into it, and had some success, but wanted to share with some other apex coders that are more versed than I the result, hoping to see if anyone can lend some extra ideas/insight to accomplish this.

 

Thus far, I've been able to actually run the getcontentasPDF as the reslt of a trigger, however, I've been stonewalled in that the returned document is blank (it's a PDF with nothing in it). I've tried it two different ways, and have gotten the same result (blank PDF). So my question is, any ideas on how to make it so the returned PDF is not blank (when you view the VF page normally, it shows properly) or am I stuck?

 

The two ways I am able to run getContentAsPDF:

 

1) When the trigger runs, I have a class that has a function that runs the getContentAsPDF function as a @future method. This works but has the issue of returning a blank pdf.

 

2) Thinking that was their systems way of blocking it, I decided to do a more convoluted and tricky route. The second method is from the trigger I call a visualforce page that has an autorun function that calls getContentAsPDF. This also works successfully, but again, the returned PDF is blank.

 

Any one have any ideas as to why the PDF may be turning up blank?

 

Thanks for any input!

Hi All,

 

I am creating PDF attachments from custom object records. These PDFs are created from the VF page which is being rendered as PDF. This VF page shows the data from those records itself.

pdf = new PageReference('/apex/testVFpdf');
    
    
          pdf.getParameters().put('ID',<custom object record ID>);
          Blob pdfContent = pdf.getContent();
         
          temp_att = new attachment();
           
          temp_att.body = pdfContent;
          temp_att.ContentType = 'pdf';

          temp_att.

Name = 'test.pdf';

          temp_att.ParentId = <custom object record ID>;

          insert temp_att;

 

 

Now, the issue is , sometimes this attachment gets created correctly and sometimes not. Does anyone have any idea about it? How can the PDF file creates properly for most of the time and sometimes it is not able to open. When we try to open it in Adobe, it gives an error saying "either the file type is not supported or it got damaged due to incorrectly decoded". When I run my code again to create the same PDF file, it gets created correctly. So, the issue can not be in that record's content otherwise the PDF could not be created from it ever then.

 

Please share suggestions.

 

thanks!!

 

 

 

  • September 01, 2010
  • Like
  • 0