• Josh V
  • NEWBIE
  • 75 Points
  • Member since 2010

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 12
    Replies

Hi all,

 

I have a simple trigger which pulls data from the lead object and places it into a custom "Finance" object when the lead is created or updated.  For some reason, the Trigger.new[0].Id is returning NULL in the trigger which fires before insert.  

 

I'm going crazy because I can't see any reason why the Id would be NULL...  Here's my code:

 

 

 

trigger FinanceNew on Lead (before insert) {
	
	Map<String,User> userList = new Map<String,User>{};
	
	// Places each returned user into a map with their sfID as the key
	for(User tmp : [SELECT Id,Name,Email,Phone FROM User]){
	  userList.put(tmp.Id,tmp);
	}
	
	for(integer i = 0; i<Trigger.new.size(); i++){
	
		string leadName = null;
		
		if(Trigger.new[i].FirstName != ''){
			leadName = Trigger.new[i].FirstName + ' ' + Trigger.new[i].LastName;
		}else{
			leadName = Trigger.new[i].LastName;
		}
		
		User ownerInfo = userList.get(Trigger.new[i].OwnerId);
		
		ID leadId = Trigger.new[i].Id; // THIS IS RETURNING NULL!!
		
		Finance__c financeRecord = new Finance__c(
		
			Name = leadName,
			Lead__c = leadId,
			Lead_Email__c = Trigger.new[i].Email,
			Lead_Phone__c = Trigger.new[i].Phone,
			Lead_Owner_Name__c  = ownerInfo.Name,
			Lead_Owner_Email__c = ownerInfo.Email,
			Lead_Owner_Phone__c = ownerInfo.Phone
			
		);
	
		insert financeRecord;
	
	}

}

 

The Lead.Id assignment should be very straight forward.  Every other field pulling directly from the Trigger.new record inserts the correct information.

 

Thanks in advance for any help!

 

Josh

  • February 28, 2012
  • Like
  • 0

Hey all,

 

I'm trying to send some GET data to an external server after a product gets updated.  I have both the trigger and class created to the point that I think it should work, but something is going wrong.  I'm getting the error: Method is not visible: httpSendtoService.sendFunc(String). I realize this must mean that this has something to do with scope and the fact that my class is defined as global, but I was under the impression that this was the correct way to define it in order to declare a @future function.

 

Here's my trigger:

trigger httpTest on Product2 (after update) {
		
	string toSend = 'Product';
	
	httpSendtoService.sendFunc(toSend);
	
}

 

 

 And my Class:

global class httpSendtoService {
	@future (callout=true) static void sendFunc(string which){
		
		Http connect = new Http();
		HttpRequest req = new HttpRequest();
		
		req.setMethod('GET');
		req.setEndpoint('http://domain.com/tests/SalesForce-HTTP-Requests.php?Data=' + which);
		
		HttpResponse res = connect.send(req);
		
	}
}

 

 

On a related note, I would prefer to send this data via POST, rather than GET, but I can't seem to find how to structure the data.

 

Any Ideas?

 

Any help would be greatly appreciated,

Josh

 

  • December 28, 2011
  • Like
  • 0

Hey All,

 

I'm creating a custom visualforce page(s) which allows users to select a subset of pricebookentries and insert them into an existing quote.  Before I show the available products, I need them to select a pricebook.  I only want to show each user the pricebooks that they are allowed access to in a select list. Is there a way for me to get a List of all of the pricebooks that a user is allowed access to?  Is there an object that I can query which holds this data?  I read somewhere on the boards to query PriceBookShare, but that is an invalid ObjectId

 

Thanks for any help in advance!

 

Josh

  • November 11, 2011
  • Like
  • 0

Hey All,

 

I spent around 20 minutes making a trigger that runs flawlessly on my sandbox, and 9 hours trying to create a test class for it.  This is my first trigger and I need a little help moving past one point.

 

Here's the functional trigger:

 

trigger trgOppQuote on Quote (before insert) {

  // Pull the Parent Opportunity ID
  ID ParentOppRecordId = Trigger.new[0].OpptyID__c;
 	
  // Use the pulled Opportunity ID to select Tier, Model and HVAC fields from Parent Opportunity
    list<Opportunity> ParentRecord = 
    [SELECT Tier__c, Model_Name__c, HVAC__c FROM Opportunity WHERE id = :ParentOppRecordId ];
		
  String OppTier =  ParentRecord[0].Tier__c;
  String OppModel = ParentRecord[0].Model_Name__c;
  String OppHVAC =  ParentRecord[0].HVAC__c;
		
  // Checks if the user supplied form info, if they didn't the info is pulled from the Opportunity
  if(Trigger.new[0].Tier__c == null) 	Trigger.new[0].Tier__c = 	OppTier;
  if(Trigger.new[0].Model__c == null) Trigger.new[0].Model__c = 	OppModel;
  if(Trigger.new[0].HVAC__c == null) 	Trigger.new[0].HVAC__c = 	OppHVAC;
}

 and the faulty test class:

 

@isTest
private class TesttrgOppQuote {
	
  static testMethod void ValidQuoteInsert() {
		
    List<Opportunity> thisOpp = 
    [SELECT id, Name FROM Opportunity WHERE id = '006V0000002AQH0' ];
		
	Quote quote = new Quote(
	  Opportunity = thisOpp,
	  Delivery_Fee__c = 0.00,
	  Name = 'Test',
	  Turn_Key__c = 'Owner Managed',
	  Concrete_Pump__c = 600,
	  Foundation_Extra__c = 2000
	);
				
	insert quote;
  }
}

 

The test gets stuck at the "insert quote;" line, however it's not giving me any errors that I understand well enough to fix...  It says:

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trgOppQuote: execution of BeforeInsert

 

Does anyone have any ideas that could nudge me in the correct direction?  I've tried numerous different methods, none of which seem to get me past the insert.

  • November 04, 2011
  • Like
  • 0

I am creating a before insert trigger which pulls some parent fields into a new child record (Opportunity Fields into Quote).  I am pulling two custom fields custom1__c and custom2__c.  When creating the quote, the user can specify values that they would like for custom1__c and custom2__c.  However if the trigger is automatically pulling data from the opportunity for these fields, any input that the user inputs for either of these fields will be overwritten by the trigger.

 

So, I need to add some sort of conditional statement which checks for user input before overwriting.

 

In PHP there is a function named isset() which checks to see if a variable is set.  I'm wondering if there is something similar for APEX.  I think I've seen something about it before, but I can't seem to get the syntax correct.

 

Here's what I would like to do:

 

trigger trgOppQuote on Quote (before insert) {	
   ID ParentOppRecordId = Trigger.new[0].OpptyID__c;
   list<Opportunity> ParentRecord = 
     [SELECT Field1__c, Field2__c FROM Opportunity WHERE id = :ParentOppRecordId ];
	
    String Field1 =  ParentRecord[0].Field1__c;
    String Field2 = ParentRecord[0].Field2__c;
	
	
    for (Quote q : Trigger.new) {
        if(!isset(Trigger.new[0].custom1__c)) q.custom1__c = Field1;
        if(!isset(Trigger.new[0].custom2__c)) q.custom2__c = Field2;
    } 
}

 Thanks in advance for any help!

  • November 03, 2011
  • Like
  • 0

Hey all,

 

I'm having a weird issue with the query function of the toolkit.  I have almost the exact same code used in a different page, but for some reason it won't work on my current project....

 

Here's the code:

 

$query = "SELECT AccountId, OwnerId, Site_City__c FROM Opportunity WHERE Id = '0068000000XuflG' LIMIT 1";

$response = $mySforceConnection->query($query);

foreach ($response->records as $data){
  foreach($fields as $var){
    $FullVar = "$varname_$var";
    $$FullVar =	$data->$var; 	
  }
}

 The set of foreaches are something that I'm trying to test at the bottom, but I never get that far down.  Instead I get the PHP error:

 

Fatal error: Call to a member function query() on a non-object in /path/to/public_html/openhouse/query_test.php on line 3

 

I have almost exactly the same code in another page (located in the same directory), and it works fine.  The only difference is the query, which is structured the exact same, only it queries more fields...

 

The other code that works:

$query = "SELECT AccountId, OwnerId, Site_City__c, Site_Street__c, Site_State__c, Site_Zip__c, Model_Name__c, A7_Est_Comp_Date__c FROM Opportunity WHERE Id = '$OppID' LIMIT 1";

 

Here is the entire page of code:

<?php

  require('/path/to/sf_modules/credentials.php');
	
	function SFQuery($fields=array() , $object , $filter , $varname , $limit=1){
		
	  foreach($fields as $field){
		  $field_line .= $field.", ";
	  }
	  
	  // Removes extra comma and space from the end of the fields
	  $field_line = substr($field_line, 0, -2);
			  
	  $query = "SELECT $field_line FROM $object WHERE $filter LIMIT $limit";
	  
	  $response = $mySforceConnection->query($query);
	  
	  foreach ($response->records as $data){
		foreach($fields as $var){
		  $FullVar = "$varname_$var";
		  $$FullVar =		$data->$var; 	
		}
	  }
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php  SFQuery(array("AccountId","OwnerId","Site_City__c"),"Opportunity","Id = '0068000000XuflG'","TestVar",1); 

echo "$TestVar_AccountId, $TestVar_OwnerId, $TestVar_Site_City__c";

?>
</body>
</html>

 


 

 

Does anyone have any ideas about what could be wrong?

 

Josh

 

 


  • August 12, 2011
  • Like
  • 0

Hi, everyone

 

I need your help to understand and fix this problem:

I built an apex text class in a sandbox environment (i'm using eclipse) but when I run this apex test class I'm getting this error: System.QueryException: List has no rows for assignment to SObject. The problem is that the object really has records both in sandbox and in production environment !!!! I run that query in Force.com Explorer, salesforce.shema Explorer, etc. and there I can see the existing records but in the test all the time throws that error... Could anyone please guide me why is it happening and how can it be fixed?

Hi all,

 

I have a simple trigger which pulls data from the lead object and places it into a custom "Finance" object when the lead is created or updated.  For some reason, the Trigger.new[0].Id is returning NULL in the trigger which fires before insert.  

 

I'm going crazy because I can't see any reason why the Id would be NULL...  Here's my code:

 

 

 

trigger FinanceNew on Lead (before insert) {
	
	Map<String,User> userList = new Map<String,User>{};
	
	// Places each returned user into a map with their sfID as the key
	for(User tmp : [SELECT Id,Name,Email,Phone FROM User]){
	  userList.put(tmp.Id,tmp);
	}
	
	for(integer i = 0; i<Trigger.new.size(); i++){
	
		string leadName = null;
		
		if(Trigger.new[i].FirstName != ''){
			leadName = Trigger.new[i].FirstName + ' ' + Trigger.new[i].LastName;
		}else{
			leadName = Trigger.new[i].LastName;
		}
		
		User ownerInfo = userList.get(Trigger.new[i].OwnerId);
		
		ID leadId = Trigger.new[i].Id; // THIS IS RETURNING NULL!!
		
		Finance__c financeRecord = new Finance__c(
		
			Name = leadName,
			Lead__c = leadId,
			Lead_Email__c = Trigger.new[i].Email,
			Lead_Phone__c = Trigger.new[i].Phone,
			Lead_Owner_Name__c  = ownerInfo.Name,
			Lead_Owner_Email__c = ownerInfo.Email,
			Lead_Owner_Phone__c = ownerInfo.Phone
			
		);
	
		insert financeRecord;
	
	}

}

 

The Lead.Id assignment should be very straight forward.  Every other field pulling directly from the Trigger.new record inserts the correct information.

 

Thanks in advance for any help!

 

Josh

  • February 28, 2012
  • Like
  • 0

Hey all,

 

I'm trying to send some GET data to an external server after a product gets updated.  I have both the trigger and class created to the point that I think it should work, but something is going wrong.  I'm getting the error: Method is not visible: httpSendtoService.sendFunc(String). I realize this must mean that this has something to do with scope and the fact that my class is defined as global, but I was under the impression that this was the correct way to define it in order to declare a @future function.

 

Here's my trigger:

trigger httpTest on Product2 (after update) {
		
	string toSend = 'Product';
	
	httpSendtoService.sendFunc(toSend);
	
}

 

 

 And my Class:

global class httpSendtoService {
	@future (callout=true) static void sendFunc(string which){
		
		Http connect = new Http();
		HttpRequest req = new HttpRequest();
		
		req.setMethod('GET');
		req.setEndpoint('http://domain.com/tests/SalesForce-HTTP-Requests.php?Data=' + which);
		
		HttpResponse res = connect.send(req);
		
	}
}

 

 

On a related note, I would prefer to send this data via POST, rather than GET, but I can't seem to find how to structure the data.

 

Any Ideas?

 

Any help would be greatly appreciated,

Josh

 

  • December 28, 2011
  • Like
  • 0

Hey All,

 

I'm creating a custom visualforce page(s) which allows users to select a subset of pricebookentries and insert them into an existing quote.  Before I show the available products, I need them to select a pricebook.  I only want to show each user the pricebooks that they are allowed access to in a select list. Is there a way for me to get a List of all of the pricebooks that a user is allowed access to?  Is there an object that I can query which holds this data?  I read somewhere on the boards to query PriceBookShare, but that is an invalid ObjectId

 

Thanks for any help in advance!

 

Josh

  • November 11, 2011
  • Like
  • 0

Hey All,

 

I spent around 20 minutes making a trigger that runs flawlessly on my sandbox, and 9 hours trying to create a test class for it.  This is my first trigger and I need a little help moving past one point.

 

Here's the functional trigger:

 

trigger trgOppQuote on Quote (before insert) {

  // Pull the Parent Opportunity ID
  ID ParentOppRecordId = Trigger.new[0].OpptyID__c;
 	
  // Use the pulled Opportunity ID to select Tier, Model and HVAC fields from Parent Opportunity
    list<Opportunity> ParentRecord = 
    [SELECT Tier__c, Model_Name__c, HVAC__c FROM Opportunity WHERE id = :ParentOppRecordId ];
		
  String OppTier =  ParentRecord[0].Tier__c;
  String OppModel = ParentRecord[0].Model_Name__c;
  String OppHVAC =  ParentRecord[0].HVAC__c;
		
  // Checks if the user supplied form info, if they didn't the info is pulled from the Opportunity
  if(Trigger.new[0].Tier__c == null) 	Trigger.new[0].Tier__c = 	OppTier;
  if(Trigger.new[0].Model__c == null) Trigger.new[0].Model__c = 	OppModel;
  if(Trigger.new[0].HVAC__c == null) 	Trigger.new[0].HVAC__c = 	OppHVAC;
}

 and the faulty test class:

 

@isTest
private class TesttrgOppQuote {
	
  static testMethod void ValidQuoteInsert() {
		
    List<Opportunity> thisOpp = 
    [SELECT id, Name FROM Opportunity WHERE id = '006V0000002AQH0' ];
		
	Quote quote = new Quote(
	  Opportunity = thisOpp,
	  Delivery_Fee__c = 0.00,
	  Name = 'Test',
	  Turn_Key__c = 'Owner Managed',
	  Concrete_Pump__c = 600,
	  Foundation_Extra__c = 2000
	);
				
	insert quote;
  }
}

 

The test gets stuck at the "insert quote;" line, however it's not giving me any errors that I understand well enough to fix...  It says:

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trgOppQuote: execution of BeforeInsert

 

Does anyone have any ideas that could nudge me in the correct direction?  I've tried numerous different methods, none of which seem to get me past the insert.

  • November 04, 2011
  • Like
  • 0

I am creating a before insert trigger which pulls some parent fields into a new child record (Opportunity Fields into Quote).  I am pulling two custom fields custom1__c and custom2__c.  When creating the quote, the user can specify values that they would like for custom1__c and custom2__c.  However if the trigger is automatically pulling data from the opportunity for these fields, any input that the user inputs for either of these fields will be overwritten by the trigger.

 

So, I need to add some sort of conditional statement which checks for user input before overwriting.

 

In PHP there is a function named isset() which checks to see if a variable is set.  I'm wondering if there is something similar for APEX.  I think I've seen something about it before, but I can't seem to get the syntax correct.

 

Here's what I would like to do:

 

trigger trgOppQuote on Quote (before insert) {	
   ID ParentOppRecordId = Trigger.new[0].OpptyID__c;
   list<Opportunity> ParentRecord = 
     [SELECT Field1__c, Field2__c FROM Opportunity WHERE id = :ParentOppRecordId ];
	
    String Field1 =  ParentRecord[0].Field1__c;
    String Field2 = ParentRecord[0].Field2__c;
	
	
    for (Quote q : Trigger.new) {
        if(!isset(Trigger.new[0].custom1__c)) q.custom1__c = Field1;
        if(!isset(Trigger.new[0].custom2__c)) q.custom2__c = Field2;
    } 
}

 Thanks in advance for any help!

  • November 03, 2011
  • Like
  • 0

Hey all,

 

I'm having a weird issue with the query function of the toolkit.  I have almost the exact same code used in a different page, but for some reason it won't work on my current project....

 

Here's the code:

 

$query = "SELECT AccountId, OwnerId, Site_City__c FROM Opportunity WHERE Id = '0068000000XuflG' LIMIT 1";

$response = $mySforceConnection->query($query);

foreach ($response->records as $data){
  foreach($fields as $var){
    $FullVar = "$varname_$var";
    $$FullVar =	$data->$var; 	
  }
}

 The set of foreaches are something that I'm trying to test at the bottom, but I never get that far down.  Instead I get the PHP error:

 

Fatal error: Call to a member function query() on a non-object in /path/to/public_html/openhouse/query_test.php on line 3

 

I have almost exactly the same code in another page (located in the same directory), and it works fine.  The only difference is the query, which is structured the exact same, only it queries more fields...

 

The other code that works:

$query = "SELECT AccountId, OwnerId, Site_City__c, Site_Street__c, Site_State__c, Site_Zip__c, Model_Name__c, A7_Est_Comp_Date__c FROM Opportunity WHERE Id = '$OppID' LIMIT 1";

 

Here is the entire page of code:

<?php

  require('/path/to/sf_modules/credentials.php');
	
	function SFQuery($fields=array() , $object , $filter , $varname , $limit=1){
		
	  foreach($fields as $field){
		  $field_line .= $field.", ";
	  }
	  
	  // Removes extra comma and space from the end of the fields
	  $field_line = substr($field_line, 0, -2);
			  
	  $query = "SELECT $field_line FROM $object WHERE $filter LIMIT $limit";
	  
	  $response = $mySforceConnection->query($query);
	  
	  foreach ($response->records as $data){
		foreach($fields as $var){
		  $FullVar = "$varname_$var";
		  $$FullVar =		$data->$var; 	
		}
	  }
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php  SFQuery(array("AccountId","OwnerId","Site_City__c"),"Opportunity","Id = '0068000000XuflG'","TestVar",1); 

echo "$TestVar_AccountId, $TestVar_OwnerId, $TestVar_Site_City__c";

?>
</body>
</html>

 


 

 

Does anyone have any ideas about what could be wrong?

 

Josh

 

 


  • August 12, 2011
  • Like
  • 0

I have the wsdl file for enterprise edition but while creating the apex classes, its giving the following error:

Apex Generation Failed
Why is this error coming? Are there any workarounds?