• sfdccoder1
  • NEWBIE
  • 135 Points
  • Member since 2009

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 27
    Replies

Hi,

 

- Sorry to bother, but I found no answer to this wuestion either on the web, or in the dev forum, or in the Apex documentation - 

 

I have a trigger, which detects error conditions and feeds errors to the class or field.

This gives a nice result interactively, in the GUI.

But how do I write test code to catch these errors ?  Is there a System.AssertException(), or the equivalent ? 

 

trigger createOrder on Asset (after insert, after update) {[...] if (price.get(a.Product2Id) == NULL) { System.debug(' error : no active price'); a.Product2Id.addError('no active price on the Product'); }[...]}

 

 

 

  • August 31, 2009
  • Like
  • 1

Hello,

I have a button which executes some javascript. I need to expose this function via the api. 

Could I call the javascript in a apex? and then could I call the apex function via the api?

Thanks 

Hi everybody,

 

maybe some one of you guys can help with this problem. I try to query all records from the WorkflowStep__c object where User = system.getUserInfo.getUserID() or the current user has an entry in the WorkflowResourceMember__c object

 

 

 

 

I tried the following query:

 

 

 

wsteplist = [

 

select

id,

Name

 

from WorkflowStep__c

 

where ShowInList__c = 'Open' AND

(User__c =: system.UserInfo.getUserId() OR

Ressource__c IN (select WorkflowResource__c from WorkflowResourceMember__c where Memeber__c =: system.UserInfo.getUserId() ) )

];

 

 but returned error: 

 

Error: Compile Error: Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions. at line 7 column 21 

 

I really appreciate your help

 

Cheers

Sebastian

 

 

Message Edited by GoodGroove on 07-03-2009 01:03 AM

I'm getting this error when trying to connect to the Sandbox API (cs4 service).

 

Any idea?

I am trying to implement this by creating an Account "After Insert" trigger that queries the ConvertedAccountId field on existing leads and checks if some of them match the new Accounts Ids.
This query returns an empty set.
 
1. Should this set contain values or do I have a bug somewhere?
2. I think this has worked in a similar trigger I did before.
    Is it possible that SF changed the conversion order of execution i.e. the new leads are not accesible via select in Account "after insert" queries.

I'm getting this error when trying to connect to the Sandbox API (cs4 service).

 

Any idea?

I am trying to implement this by creating an Account "After Insert" trigger that queries the ConvertedAccountId field on existing leads and checks if some of them match the new Accounts Ids.
This query returns an empty set.
 
1. Should this set contain values or do I have a bug somewhere?
2. I think this has worked in a similar trigger I did before.
    Is it possible that SF changed the conversion order of execution i.e. the new leads are not accesible via select in Account "after insert" queries.

Need a unique identifier(trx id) for a web service call out.  Any ideas?

 

 

The only thing I can think of involves using a custom object:

sql equiv example:  update table set lastid = lastid + 1  (creates a lock - and then select)

 

essentially:

 

obj seq = [Select nextId from obj];

seq.nextId = seq.nextId + 1;

update seq;

 

Integer trxId = seq.nextId;

 

Will this logic even work?  The counter code will reside within the 'callout' class.

I have a simple usecase of opening a new window while clicking a custom button in a detail page record, closing it immediately and then refreshing the parent window (from which the new window was opened).

This functionality works fine when I use javascript in S-Control for closing the current window and refreshing the parent window. The sample code below:

<html>
<script>
function reSizeWindow()
{
refreshWindow();
top.window.close();
}
function refreshWindow()
{
opener.location.reload();
}
</script>
body onload="reSizeWindow();">
<center>
<br><br><br>
<SPAN STYLE=" font-size: 75%; font-family: 'Arial', 'Helvetica', sans-serif;">
Updating Account and Contact Information... Please Wait.
</span><br><br>
<img src="/img /waiting_dots.gif " alt="Please wait..." title="Please wait..." height="20" width="196">
</center>
</body>
</html>

But when I convert this to a visualforce page, the javascript code to refresh the parent window doesn't work. The sample code for vf page below:

<apex:page standardController="<custom_obj__c">
<script>
window.onload = function()
{
refreshWindow();
top.window.close();
}
function refreshWindow()
{
opener.location.reload();
}
</script>
</apex:page>

If I remove the refreshWindow() function, then the closing of current window is working fine but the opener.location is not recognized in this page.

This usecase may look unnecessary, but the actual implementation would be some updation happening in the controller and returning back to the same page.

Any suggestion regarding any workaround to refresh a parent window in visualforce or let me know if I am missing something.

Regards,
Karthik.

Hi,

 

- Sorry to bother, but I found no answer to this wuestion either on the web, or in the dev forum, or in the Apex documentation - 

 

I have a trigger, which detects error conditions and feeds errors to the class or field.

This gives a nice result interactively, in the GUI.

But how do I write test code to catch these errors ?  Is there a System.AssertException(), or the equivalent ? 

 

trigger createOrder on Asset (after insert, after update) {[...] if (price.get(a.Product2Id) == NULL) { System.debug(' error : no active price'); a.Product2Id.addError('no active price on the Product'); }[...]}

 

 

 

  • August 31, 2009
  • Like
  • 1

I've confirmed that when inserting a new opportunity that has a workflow field update my before update trigger fires.  Can anyone think of a way to prevent this trigger from firing?

 

Here is my trigger:

 

 

trigger opportunity_ae_required on Opportunity (before update) { Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.isUpdate && Trigger.new[i].ae_required__c == 1) { oppy_contact.put(Trigger.new[i].id,Trigger.new[i]); system.debug('Trigger.new[i]: ' + Trigger.isUpdate); } } map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>(); for (OpportunityContactRole ocr : [select OpportunityId, Role from OpportunityContactRole where (OpportunityContactRole.Role = 'Account Executive' and OpportunityContactRole.OpportunityId in :oppy_contact.keySet())]) { oppycontactroles.put(ocr.OpportunityId,ocr); } for (Opportunity oppy : system.trigger.new) { system.debug('trigger.isUpdate: ' + Trigger.isUpdate); if (Trigger.isUpdate) { if (oppycontactroles.containsKey(oppy.id) || oppy.ae_required__c == 0) { // Do nothing } else { oppy.addError('Cannot make changes to this Opportunity until an Account Executive has been Selected in the Contact Roles section.'); } } } //for }

 

Hi,

 

I am trying to generate apex class from fedex RATE webservice but finding an error

 

Failed to generate apex code, operation 'getRates' has more than one outout element

 

 

download wsdl from here

 

https://www.fedex.com/wpor/web/jsp/drclinks.jsp?links=downloads/wsdl/Aug09/Standard/RateService_v7.zip

 

 

 

  

  • August 28, 2009
  • Like
  • 0

Hello,

I have a button which executes some javascript. I need to expose this function via the api. 

Could I call the javascript in a apex? and then could I call the apex function via the api?

Thanks 

My client built their site with Joomla, we are looking for some required field scripting for Joomla (Name, Email, Phone and Business Status to be specific) so that we can connect Web to Lead functionality in their new SF instance. Can anyone help?? Thanks!

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

Hi everybody,

 

maybe some one of you guys can help with this problem. I try to query all records from the WorkflowStep__c object where User = system.getUserInfo.getUserID() or the current user has an entry in the WorkflowResourceMember__c object

 

 

 

 

I tried the following query:

 

 

 

wsteplist = [

 

select

id,

Name

 

from WorkflowStep__c

 

where ShowInList__c = 'Open' AND

(User__c =: system.UserInfo.getUserId() OR

Ressource__c IN (select WorkflowResource__c from WorkflowResourceMember__c where Memeber__c =: system.UserInfo.getUserId() ) )

];

 

 but returned error: 

 

Error: Compile Error: Semi join sub-selects are only allowed at the top level WHERE expressions and not in nested WHERE expressions. at line 7 column 21 

 

I really appreciate your help

 

Cheers

Sebastian

 

 

Message Edited by GoodGroove on 07-03-2009 01:03 AM

I've got a Opp trigger which sends an email, and chooses one of a number of templates, based on details in the triggering Opportunity.

 

This works fine in general.  And I've written unit tests that make sure the code completes without error, and that the proper data gets written back to the Opp after the email goes out.

 

But I'd also like to test that the correct template gets used.  I don't see any way to test this directly, unless I write the template ID or some other detail to the database somwhere, because the unit test has no access to the Messaging object that contains the email details.  Am I understanding this correctly?

 

I know I could fake it by inspecting the Task records that get recorded.  But that's less than ideal, because the only details about the templates recorded in the Task are the subject lines and the email body, not the ID or template name.  In my case, the subject lines are identical for a few of the templates, and the email bodies are subject to constant change.  So neither is good for use in a permanent unit test.

 

So I'm faking it even worse by just using debug statements in the trigger to test this manually.  But I'd really like to be able to do it in a real unit test.

 

 Any bright ideas out there?

 

Thanks, y'all!

Hi All,

 

We have a custom application that makes use of an auto increment field. It's critical that the numbers are sequential and accounted for. The problem is that every time the unit tests get run they affect the auto increment number. This shouldn't happen, tests should not affect production data including auto incremented numbers.

 

In the idea exchange there a few others that ran into this same problem and apparently salesforce turned something on to fix it for them. Salesforce support has told me twice that it's not available. Any ideas on how I can fix this other than reseting the number every time an application is installed or updated? 

 

Thanks!

Scott 

Hi all,

 

i am struggling with delete trigger.If am clicking delete link or button for the record of the object,it should check whether ithe record has child records.If the record has child records,want to display the message.

I tried the below coding.but its not displaying error message.its getting deleted eventhough it has child records.

 

plz provide me coding.

 

Thanks,

Dhana

  • June 12, 2009
  • Like
  • 0

We are extracting the User Object using Informatica. We are able to see all the User fields except CommunityNickName(std field) , Manager (std Field), SAML Federation Id (Added for SSO).

There is no field level security enabled for these fields. Also, the username and password used by Informatica has System Admin privileges.

 

We face the same problems in different instances - my dev org, the client dev env, client sandbox env.

 

It would be helpful if someone could explain where am I going wrong with the extract? 

 

Thanks a lot for your help. Appreciate it.

 

 

 

 

Pooja

Issue:

 

What I need is to sync every updates of case to another system(ASAP), firstly I tired to call an outside webservice in a after update trigger, But got following err message: "Callout from triggers are currently not supported."

 

After some research, it seems there are two ways as workaround. I've not tried them, please advise if my understanding is wrong:

 

1. use @future (callout=true) to mark the call out method.

2. Outbound Messaging feature

 

Question:

 

1. Both of above two workaround ways are asynchronous. Anyone know how long will it take to invoke outside webservice? will the @future one instantly call outside webservice?

2. Is there any other good solution, what I need is sync updates of case to outside system instantly?

 

Thanks a lot!

Hello everyone,

I wanted to know if it's possible to customize the Customer Portal login page to include, for example a combo box or buttons. Thank you.