• teknicsand
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 37
    Replies

User opp_owner = [select id, username, Profile.Name, email from User where id = :opp.OwnerId];

 

How do I test for the above query in a test class? When I call the function to which the above line belongs, in the test class, I get a "List has no rows for assignment to SObject" error.

 

Any thoughts or suggestions?

 

Thanks in advance..

 

Sand

I have the following code, that works on most occasions, and fails on a few occassions for reasons I cannot figure out.

 

 

pricebook 1 if (pb_id == '01s30000000FkSlAAK')

{ store_link = 'https://www.mindstreamshealth.com/store/ADW9P2A';

system.debug('store link :' + store_link);

mail.setPlainTextBody(std_US_plain_txt);

mail.setHtmlBody(std_US_html);

system.debug('std_US_html');

}

 

pricebook 2

 

if (pb_id == '01s30000000FkHcAAK')

{ store_link = 'https://www.mindstreamshealth.com/store/MXDF71H-01';

system.debug('store link :' + store_link);

mail.setPlainTextBody(disc1_US_plain_txt);

mail.setHtmlBody(disc1_US_html);

system.debug('disc1_US_html'); }

 

pricebook 3

 

if (pb_id == '01s30000000FkHhAAK')

{ store_link = 'https://www.mindstreamshealth.com/store/N28Y43X-02';

system.debug('store link :' + store_link);

mail.setPlainTextBody(disc2_US_plain_txt);

mail.setHtmlBody(disc2_US_html);

system.debug('disc2_US_html'); }

 

pricebook 4

if (pb_id == '01s30000000FkHmAAK')

{ store_link = 'https://www.mindstreamshealth.com/store/PLI67WR-03';

system.debug('store link :' + store_link);

mail.setPlainTextBody(disc3_US_plain_txt);

mail.setHtmlBody(disc3_US_html);

system.debug('disc3_US_html'); }

 

pricebook 5

if (pb_id == '01s30000000FkHdAAK')

{ store_link = 'https://www.mindstreamshealth.com/store/QTXRK72-04';

system.debug('store link :' + store_link);

mail.setPlainTextBody(disc4_US_plain_txt);

mail.setHtmlBody(disc4_US_html);

system.debug('disc4_US_html'); }

 

pricebook 6

 

if (pb_id == '01s30000000FpbRAAS')

{ mail.setPlainTextBody(TP1_US_plain_txt);

mail.setHtmlBody(TP1_US_html);

system.debug('TP1_US_html'); }

 

pricebook 7

if (pb_id == '01s30000000Ff94AAC')

{ mail.setPlainTextBody(old_US_plain_txt);

mail.setHtmlBody(old_US_html);

system.debug('old_US_html'); }

 

else

{ system.debug('Email not Sent. Pricebook match not found' + pb_id);

return('Email Not Sent: Pricebook match not found');

 

 pb_id is a string containing the pricebook id that is passed to the apex class containing the above code. I have checked to see if there is any error while passing the pricebook id, but pricebook id passed to this class is accurate. And yet, on occassion, it skips all if statements and goes to the else statement and I get the error stated there. The location of the if statement seems to affect the flow of code, which I don't understand why. For example, the pricebook 7, when placed above all the if statements, will not work even it matches the pricebook id, but by placing it at the end , it seemed to work.

 

Is there a flaw in the logic? If so, can anyone point it out to me? Also, I would like to know if there is a better way of writing this logic instead of the numerous if statements, something like a Select statement in C.

 

Thanks,

 

Sand 

 

Message Edited by teknicsand on 06-30-2009 01:47 PM
I have a query

public Pricebook2 getPricebook2()
{
Opportunity opp_info = getOpportunity();
Pricebook2 pricebook_info = [select Id, P.Name, P.IsActive, P.Description from Pricebook2 P
where P.id = : opp_info.Pricebook2Id];
return pricebook_info;

 

How would I test this in my test class?

 

This is what I have in my test class

 

Pricebook2 pb_info = new Pricebook2 (name='testbook',description='asdsdfsf', IsActive=true);
insert pb_info;
controller.getPricebook2();

 where controller is an object of the visualforce controller I'm trying to test.

 

But I get an error message that says

 

 

Class.myOpportunityController.getPricebook2: line 40, column 37 Class.myOpportunityTestClass.myControllerTest: line 67, column 10 System.QueryException: List has no rows for assignment to SObject

 

 

 

 

 

 

Message Edited by teknicsand on 04-02-2009 04:03 AM

I have a visualforce pdf as an attachment already. I need to add another static file to be added as an attachment. Should it be in the documents section or the static resource section?

 

 

PageReference opppdf = Page.opppdf; opppdf.getParameters().put('id',opp1.id); Blob pdf = opppdf.getContent();

 

 

Messaging.EmailFileAttachment mailAttachment; mailAttachment = new Messaging.EmailFileAttachment(); mailAttachment.setFileName('test1.pdf'); mailAttachment.setBody(pdf);

 

for the second attachment which is static file

 

 

Messaging.EmailFileAttachment mailAttachment1; mailAttachment1 = new Messaging.EmailFileAttachment(); mailAttachment1.setFileName('test2.pdf'); mailAttachment.setBody(pdf1); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { mailAttachment, mailAttachment1 })

 how do i access the content of the file and attach it to the email?

 

 

 

- Sand

 

 

 

I'm trying to access the current record id on the object on which the trigger is going to work. This will help me set the context, so that I can use that Id to obtain other fields from the object which I need to pass to other Apex clases/methods.I tried calling apex methods which used the currentPage() parameters to obtain the Id. But it gives me the following error. So I'm trying to get the current record information on the trigger itself and pass it onto relevant methods and classes

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

 

 

Can anyone show me how I would accomplish this?

 

Thanks!!!

Hi everyone,

 

I've been working on getting an quote sent out as a pdf to customer using visualforce. Here, for some context.

I nailed this down, but I'm unable to come up with a way for this email to be fired based on a field update in an object. I would like to have this whole process run in the background, i,e. no new window which prompts for user to click any button. I have created a custom link (last resort) to display on the opportunity page layout, which redirects to a visualforce page, where a send email button needs to be clicked to send the email out to that particular contact whose on the opportunity record. I would like to move this process to the background and have it run automatically when a particular field is updated.

 It would be great if I can write a trigger to run based on a field update, grab the context of the record in view (record id), and pass it to an apex class, where i can use it generate a link for pdf attachment using pagereference, and pass the parameters to my apex email class to send out the email.

Can this be done? If yes, any pointers, or else any alternatives.

 

Thanks

I'm looking to implement a VF email that will attach a pdf file generated dynamically from vf page. There is an app installed in the environment, which pulls data from an external source, and displays it using S-control, and also has an option of displaying the same information as a pdf(dynamically generated) using visualforce. I need to send this information, or the pdf file, as an email attachment to customers. I've gone through chapter 13 in the force.com cookbook and the Visualforce Email2pdf article. I'm a little confused as to how to approach this. If someone can point me in the right direction, I would appreciate it.

 

Thanks,

 

Cheers,

 

Sand

I have created an APEX class with a webservice function. This function should run from a custom button on a custom object.  However, I get errors when creating a testMethod. (It looks like I require a testMethod before I can use the APEX class)

Here is the APEX class I have created with the testMethod commented out. Can you let me know how I can test my APEX class?

Thanks,
Brian

global class ConvertDealReg{
webService static Boolean ConvertDealReg1(Deal_Registration__c d){
// this webservice receives a Deal Reg
// Creates an account for the End Customer, depending on whether or not it already exists
// Creates a Contact for the End Customer, depending on whether or not it already exists
// Creates an opportunity using Account and Contact

// 1: check for duplicate End User account
boolean cCreate = true; // default to true
Account a;
if (d.Full_Company_Name__c != null && d.Contact_City__c != null){
// query to find dupes
if ([select count() from Account where Name = :d.Full_Company_Name__c and Site = :d.Contact_City__c] >= 1) {
cCreate=false;
// set a to be the dupe account so we can get the Id value of the account later
a = [select Id from Account where Name = :d.Full_Company_Name__c and Site = :d.Contact_City__c limit 1];
}
}

// create a boolean to catch any errors in case we need to rollback
boolean err = false;

// create the account if necessary based off previous check
if (cCreate){
try{
a = new Account();
a.Name = d.Full_Company_Name__c;
a.Account_Type1__c = 'Customer';
a.Site = d.Contact_City__c;
a.BillingStreet = d.Contact_Street_Address__c;
a.BillingPostalCode = d.Contact_Zip_Postal_Code__c;
a.BillingState = d.Contact_State_Province__c;
a.BillingCountry = d.Contact_Country__c;
a.Phone = d.Contact_Phone__c;
a.Fax = d.Contact_Fax_Number__c;
a.Industry = d.Industry_Type__c;

insert a;
} catch (System.DmlException e) {
//update our err flag
err = true;
System.debug('error inserting new account record');
for (Integer k = 0; k < e.getNumDml(); k++) {
// Process exception here
System.debug(e.getDmlMessage(k));
}
}
}
//set Account ID in Deal Reg
d.Customer_Name__c = a.Id;

// 2: check for duplicate End User contact
cCreate = true; // default to true
Contact c;
String strFirstName = '';
String strLastName = '';

if (d.Primary_Contact__c != null){

String s = d.Primary_Contact__c;
if(s.indexOf(' ') > 0){
strFirstName = s.subString(0, s.indexOf(' ') - 1);
strLastName = s.subString(s.indexOf(' ') + 1);
}else{
strLastName = s;
}

// query to find dupes
if ([select count() from Contact where AccountID = :a.ID and Name = :d.Primary_Contact__c] >= 1) {
cCreate=false;
// set c to be the dupe contact
c = [select Id from Contact where AccountID = :a.ID and Name = :d.Primary_Contact__c limit 1];
}
}

// create the contact if necessary based off previous check
if (cCreate){
try{
c = new Contact();
c.AccountID = a.Id;
c.FirstName = strFirstName;
c.LastName = strLastName;
c.Contact_Type__c = 'End User';

c.Title = d.Contact_Title__c;
c.MailingStreet = d.Contact_Street_Address__c;
c.MailingPostalCode = d.Contact_Zip_Postal_Code__c;
c.MailingState = d.Contact_State_Province__c;
c.MailingCountry = d.Contact_Country__c;

c.Email = d.Contact_Email__c;
c.Phone = d.Contact_Phone__c;
c.Fax = d.Contact_Fax_Number__c;

insert c;
} catch (System.DmlException e) {
//update our err flag
err = true;
System.debug('error inserting new contact record');
for (Integer k = 0; k < e.getNumDml(); k++) {
// Process exception here
System.debug(e.getDmlMessage(k));
}
}
}
//set Contact ID in Deal Reg
d.Customer_Contact__c = c.Id;

//3. Create a New MSD Opportunity
Opportunity o;
try{
o.Name = d.Full_Company_Name__c + '-' + d.Primary_Contact__c + '-' + Date.Today();
o.AccountId = a.Id;
o.CloseDate = d.Estimated_Close_Date__c;
o.Amount = 1;
o.StageName = 'Prospecting';
o.Probability = 10;
o.Opportunity_Source__c = 'Deal Registration';
o.Deal_registration__c = d.Id;
insert o;
} catch (System.DmlException e) {
//update our err flag
err = true;
System.debug('error inserting new opportunity record');
for (Integer k = 0; k < e.getNumDml(); k++) {
// Process exception here
System.debug(e.getDmlMessage(k));
}
}

// check for errors and return the success flag
if (!err) {
return true;
} else {
// further error handling here
return false;
}
}

// The following is a simple unit test
//static testMethod void myTest() {
//Deal_Registration__c test_d;
//test_d = [select Id from Deal_Registration__c where Id = 'a0I70000000UCpk'];
//Boolean bnResult = ConvertDealReg1(test_d);
//System.assertEquals(true, bnresult);
//}
}
Since using the new release of the IDE (version 14) I get enormous amounts of debug output, no matter what log level are set. These settings seem to get ignored, the same seems to happen in the browser output when running tests.
I set the various log levels for each category, basically disabling everything except apex code, but each test case gets several thousand (!) lines of output. So the debug log only contains output for 3 test methods before all further output gets truncated.
This makes it pretty much impossible to use the output for debugging since it misses most of the other test methods and is totally bloated with information I didn't want to see in the first place.
Any ideas what's going on here? Are the log levels just broken? Anything I can do to get useful debug log output?
So I think the new system log is causing some of the test classes to fail. To test the "bulk" of my triggers most test classes process 200 records. Yet on opportunities we have tons of workflow, formulas, validations, etc. This is causing the Debug Log to explode on opportunity Triggers causing to many script statements.

I thought when salesforce.com updated instances it was going to run all the test classes to see if they pass?  If so what is going to happen when you update our production instance?

Also what can I do to fix this problem.

Thanks,
Jason

Message Edited by TehNrd on 11-06-2007 04:28 PM