• teknicsand
  • NEWBIE
  • 25 Points
  • Member since 2008

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

I'm looking for offshore SFDC developers (preferably India) to work with ongoing projects periodically in future. Need a reliable and capable individual with at least 2 years of experience in customizing SF, writing triggers, building VF pages and also integration projects. I would prefer to deal with someone working independently as a freelancer or part-time. If interested, PM me, and we'll discuss further.

 

Cheers,

sand

Hi guys...

 

I need some help debugging this issue. I have an email apex class that I'm trying to test. 

 

 

global class sendPDFEmailClass
{

public string sendmy1Email(Opportunity opp, Blob pdf1, Blob pdf2, blob pdf3, String pb_id, String bc_email)
{

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
User user = [select id, username, Profile.Name, email from User where id = :Userinfo.getUserId()];
String[] toAddresses = new String[] {opp.Mindstreams_Account_Owner_Email__c, user.email, bc_email};
system.debug('user email' + user.email);

mail.setToAddresses(toAddresses);
mail.setReplyTo(user.Email);//sf user email add
mail.setSenderDisplayName(User.username);//sf user name

String subject1 = 'Purchase Details';
mail.setSubject(subject2);
mail.setBccSender(true);
mail.setUseSignature(true);
/Choosing approporiate email content(store links) based on pricebook name
String std_txt = 'W1';
String std__txt = 'W2';

if (pb_id == '01s30000000FgDWAA0')//01sR00000008ixAIAQ 01s30000000FgDWAA0
{
mail.setPlainTextBody(std_plain_txt);
mail.setHtmlBody(std_html_txt);
}

if (pb_id == '01s30000000FkWUAA0')//01sR00000008ixBIAQ
{
mail.setPlainTextBody(w2);
mail.setHtmlBody(w2);
}

//Attachments
try{
Messaging.EmailFileAttachment mailAttachment;
mailAttachment = new Messaging.EmailFileAttachment();
mailAttachment.setFileName('Order Items.pdf');
mailAttachment.setBody(pdf1);

Messaging.EmailFileAttachment mailAttachment1;
mailAttachment1 = new Messaging.EmailFileAttachment();
mailAttachment1.setFileName('Israeli Direct Bank Transfer.doc');
mailAttachment1.setBody(pdf2);

Messaging.EmailFileAttachment mailAttachment2;
mailAttachment2 = new Messaging.EmailFileAttachment();
mailAttachment2.setFileName('Mindstreams® Ongoing Billing options.pdf');
mailAttachment2.setBody(pdf3);

mail.setFileAttachments(new Messaging.EmailFileAttachment[] { mailAttachment, mailAttachment1, mailAttachment2});
}
catch (Exception e) {system.debug('error attaching files to the email' + e); return ('Email Not Sent because documents failed to attach');}

//Send email results
List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if (!results.get(0).isSuccess())
{
System.StatusCode statusCode = results.get(0).getErrors()[0].getStatusCode();
String errorMessage = results.get(0).getErrors()[0].getMessage();
system.Debug('email error:' + errorMessage);
ID d = results.get(0).getErrors()[0].getTargetObjectId();
return ('Email Not Sent: Check debug logs for error message or contact System Administrator');
}
else
{
if (opp.email_counter__c == null) {opp.email_counter__c = 0;}
opp.email_counter__c++;

update opp;
return ('Email Sent');

}
}

//US Email
public string sendmyEmail(Opportunity opp, Blob pdf, Blob pdf2, String pb_id, String bc_email)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

//String[] toAddresses = new String[] {'sandeep.kelvadi@neurotrax.com'};

User user1 = [select id, username, Profile.Name, email from User where id = :Userinfo.getUserId()];
User opp_owner = [select id, username, Profile.Name, email from User where id = :opp.OwnerId];
String[] toAddresses = new String[] {opp.Mindstreams_Account_Owner_Email__c,bc_email, opp.OwnerId, user1.Email};
system.debug('user email' + user1.email);
system.debug('opportunity owner email' + opp_owner.email);
mail.setToAddresses(toAddresses);

mail.setReplyTo(opp_owner.Email);//opportunity owner email add
mail.setSenderDisplayName(opp_owner.username);//opportunity owner user name

String subject2 = 'New Account Purchase Details';
mail.setSubject(subject2);
mail.setBccSender(true);
mail.setUseSignature(true);

//store Paypal links
String store_link;
system.debug('pb_id parameter passed from myopportunitycontroller: ' + pb_id);


String TP1_US_plain_txt='W1.';
String TP1_US_html='W2';

if (pb_id == '01s30000000FkSlAAK')//01s30000000FkSlAAK;01sR00000008ix5IAA
{
store_link = 'https://www';
system.debug('store link :' + store_link);
mail.setPlainTextBody(std_US_plain_txt);
mail.setHtmlBody(std_US_html);
system.debug('std_US_html');
}

else if (pb_id == '01s30000000FkHcAAK')//01sR00000008ix6IAA
{
store_link = 'https:';
system.debug('store link :' + store_link);
mail.setPlainTextBody(disc1_US_plain_txt);
mail.setHtmlBody(disc1_US_html);
system.debug('disc1_US_html');
}

else
{
system.debug('Email not Sent. Pricebook match not found' + pb_id);
return('Email Not Sent: Pricebook match not found');
}


//Attachments

try{
Messaging.EmailFileAttachment mailAttachment;
mailAttachment = new Messaging.EmailFileAttachment();
mailAttachment.setFileName('Mindstreams® Invoice.pdf');
mailAttachment.setBody(pdf);


Messaging.EmailFileAttachment mailAttachment1;
mailAttachment1 = new Messaging.EmailFileAttachment();
mailAttachment1.setFileName('Mindstreams® Ongoing Billing options.pdf');
mailAttachment1.setBody(pdf2);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { mailAttachment, mailAttachment1});
}
catch (Exception e) {system.debug('error attaching files to the email' + e); return ('Email Not Sent! Documents failed to attach');}

List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if (!results.get(0).isSuccess())
{
System.StatusCode statusCode = results.get(0).getErrors()[0].getStatusCode();
String errorMessage = results.get(0).getErrors()[0].getMessage();
system.Debug('email error:' + errorMessage);
ID d = results.get(0).getErrors()[0].getTargetObjectId();
return ('Email Not Sent: Check debug logs for error message or contact System Administrator');
}
else
{

if (opp.email_counter__c == null) {opp.email_counter__c = 0;}
opp.email_counter__c++;
try{
update opp;
return ('Email Sent');
}
catch (Exception e) { system.debug('update failed'); return ('Email not sent. Email Counter update failed.');}
}
}
}

 There are 2 functions each meant to send out an email for a specific target of customers. In my case, I'm trying to test, for now, for the second function. The following lines of code in the 2nd function is where I'm hitting the brick wall:


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

 

My rudimentary test class looks like this

 

 

@isTest

private class sendPDFEmailTestClass {

public static testMethod void sendmyEmailTest()
{
//Data, variables etc
Blob pdf1, pdf2, pdf3;

Opportunity testopp = new Opportunity (name='test opp');
testopp.StageName = 'Closed Won';
testopp.CloseDate = date.today();
insert testopp;

system.debug('testopp stage: ' + testopp.StageName);
system.debug('testopp name: ' + testopp.Name);
system.debug('testopp ownerId: ' + testopp.OwnerId);
PageReference opportunityinvoice = Page.opportunityinvoice;
opportunityinvoice.getParameters().put('id',testopp.id);
pdf1 = opportunityinvoice.getContent();
pdf2 = opportunityinvoice.getContent();
pdf3=opportunityinvoice.getContent();


//testing getpricebook2()
Product2 testpd = new Product2 (name='test product');
testpd.productcode = 'test pd code';
insert testpd;
Pricebook2 s = [select id, name from Pricebook2 where IsStandard = true];
system.debug('test price book name: ' + s.name);
PricebookEntry testpbe = new PricebookEntry ();
testpbe.pricebook2id = s.id;
testpbe.product2id = testpd.id;
testpbe.UnitPrice = 100;
testpbe.IsActive=true;
insert testpbe;

testopp.Pricebook2Id = s.Id;
update testopp;

String bc_email = 'test@test.com';
String pb_id = s.Id;

Opportunity queryopp = [select stageName, name, pricebook2id, ownerid from Opportunity where id =: testopp.Id];
system.debug(queryopp.StageName);
system.debug(queryopp.Pricebook2Id);
system.debug(queryopp.OwnerId);


// testopp.OwnerId
//user & profile testing
Profile p = [select id from profile where name='Standard User'];
User u = new User(alias = 'standt', email = 'stduser@test.com', emailencodingkey='UTF-8', lastname='Testin', languagelocalekey='en_US', localesidkey='en_US', profileid=p.Id, timezonesidkey='America/Los_Angeles', username='stduser@test.com');



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

sendPDFEmailClass testemail = new sendPDFEmailClass();
testemail.sendmyEmail(testopp, pdf1, pdf2, pb_id, bc_email);
// testemail.sendmyEmail1(opp, pdf1, pdf2, pdf3, pb_id, bc_email)

}

}

 I get the error that list has no rows for assignment for this linein the Apex Class

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

 

 

 

 I tried assigning the opportunity owner with the user created in the test class, but I got a cross reference error. 

 

Can someone help me here? Really need to get this fixed. It's not allowing me to create any code code since the apex coverage is below 75%.

 

Thanks in advance!

 

Message Edited by teknicsand on 08-26-2009 07:26 AM
Message Edited by teknicsand on 08-26-2009 07:28 AM

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

Is there a way to display items in a htmlBody of an email. I know it accepts only strings, but if there is a workaround to getting list items to display in the email, it would great.

 

Any suggestions?

 

thanks

 

cheers

sand

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 have a trigger which makes a callout to a controller which is using @future annotation. The controller then call a email class to send out the email with the pdf attachment. But I get the following error in the debug logs:

 

Status java.lang.NullPointerException Application Browser
Request Type Api Operation FutureHandler
Duration (ms) 528 Log Length 887
Log

20090225222643.115:Class.myOpportunityController.createSamplevfpdf: line 8, column 5: controller method called
20090225222643.115:Class.myOpportunityController.createSamplevfpdf: line 10, column 5: vf opp id: 0068000000M1lOCAAZ
20090225222643.115:Class.myOpportunityController.createSamplevfpdf: line 11, column 5: vf opp name: United Oil Installations
20090225222643.115:Class.myOpportunityController.createSamplevfpdf: line 12, column 5: vf con id: 0038000000UJtnFAAT
20090225222643.115:Class.myOpportunityController.createSamplevfpdf: line 13, column 5: vf con name: Stella Pavlova
20090225222643.115:Class.myOpportunityController.createSamplevfpdf: line 14, column 5: vf con email: spavlova@uog.com
System.VisualforceException: java.lang.NullPointerException

Class.sendPDFEmailClass.sendmyEmail: line 8, column 20
Class.myOpportunityController.createSamplevfpdf: line 16, column 5

 

Trigger:

 

 

trigger OpportunityVFEmail on Opportunity (after insert, after update)
{

for(Opportunity a: Trigger.new){

System.debug('id is: ' + a.Id);

System.debug('name is : ' + a.Name);

System.debug('same custom field: ' + a.same__c);

if (a.stageName == 'Closed Won')
{
Contact con1 = [select id, name, email, accountid from Contact
where accountid = :a.accountid limit 1];

System.debug('contact id: ' + con1.id);
System.debug('contact name: ' + con1.name);
System.debug('contact email: ' + con1.email);
String con_id = con1.id;
String con_name = con1.name;
String con_email = con1.email;
System.debug('s contact id: ' + con_id);
System.debug('s contact name: ' + con_name);
System.debug('s contact email: ' + con_email);

String opp_id = a.id;
String opp_name = a.name;
System.debug('S opp name: ' + opp_id);
System.debug('S opp name: ' + opp_name);

myOpportunityController.createSamplevfpdf(a.id, a.name, con1.id, con1.name, con1.email);
}
}
}

 

 

Controller:

 

 

global class myOpportunityController {

@future (callout=true)
public static void createSamplevfpdf(ID id, String Opp_name, String Con_id, String Con_name, String Con_email)
{
Opportunity opp;
Contact con1;
System.debug('controller method called');

System.debug('vf opp id: ' + id);
System.debug('vf opp name: ' + Opp_name);
System.debug('vf con id: ' + Con_id);
System.debug('vf con name: ' + Con_name);
System.debug('vf con email: ' + Con_email);

sendPDFEmailClass.sendmyEmail(id,Opp_name, Con_id, Con_name, Con_email);
}

}

 

 Email Apex Class:

 

 

global class sendPDFEmailClass
{
public static void sendmyEmail(ID EOpp_id, String EOpp_name, String ECon_id, String ECon_name, String ECon_email)
{

PageReference samplevfpdf = Page.samplevfpdf;
samplevfpdf.getParameters().put('id',EOpp_id);
Blob pdf1 = samplevfpdf.getContent();


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

String[] toAddresses = new String[] {ECon_email}; //get it from contacts
mail.setToAddresses(toAddresses);
mail.setReplyTo('user@salesforce.com');//sf user email add
mail.setSenderDisplayName('xxxxxxxxxx');//sf user name

mail.setSubject(' New Account Purchase Details' + 'Invoice no' + ': ' + ECon_name + ' ' + EOpp_name + ' : ' + EOpp_id);

mail.setBccSender(true);
mail.setUseSignature(true);

mail.setPlainTextBody('This is a test email');
mail.setHtmlBody('Welcome to ');

//Attachments

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

//mail.setFileAttachments(fileAttachments);

//send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}

}

 

 I'm not sure why I get this error? Is it related to the use of @future? Can anyone let me know how I should resolve it?

 

Thanks

 

 

Message Edited by teknicsand on 02-25-2009 02:52 PM

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

sforce.connection.query(
"Select o.Opportunity.StageName, o.OpportunityId, o.Contact.Name, o.Contact.Email From OpportunityContactRole o where o.OpportunityId = {!Opportunity.Id}}",
callback);

Can someone tell me what the error is with the above query? I'm trying to get the contact information ( email in particular) of the current opportunity being viewed with the use of OpportunityContactRole.
Can I use workflow rules to trigger a snippet s-control? I need the s-control to trigger when the field stages in the opportunity tab are changed from one value to another. I know triggers as such cannot be implement by code on the client side, so I'm wondering if workflow can achieve this. OR if it can't, is there a workaround or a hack to trigger the scontrol based on changes in values of a field.
Any ideas??

Thanks

-sand
Hi,

The problem I'm faced with is as described below.

In the opportunity tab, when the stage field is changed from one stage to another, for example, from Negotiating to Closed/Won, the workflow is setup to send out emails to the Salesforce users from an email template automatically. But the workflow, to the best of my knowledge, does not allow an email to be also sent out to an external user, the customer in this case.

Can S-Controls be used to solve this issue? If so can anyone point me in some direction. I've been reading on how to send emails using the Email API and S-controls, but I don't seem to understand how a contact s email address associated with the opportunity that is being currently viewed can be extracted and then used to fire out an automatic email when the field stages are changed.

If anyone has any ideas, please let me know. I would greatly appreciate it.

Thanks.

-Sand

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

  • November 07, 2007
  • Like
  • 0