• micwa
  • NEWBIE
  • 165 Points
  • Member since 2007

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 116
    Replies

I would like to use a variable to define the where clause in a query.

 

I have defined a variable SLName with:

 

SLName=[select id, LastName, spouse_last_name__c from contact

where id = :ApexPages.currentPage().getParameters().get('id')].spouse_last_name__c;

 

How do I make something like the following work?

 

public Contact getSpouseCon(){

if(iscon == null)iscon = [

select FirstName, LastName, spouse_converted__c from contact where Lastname = SLName];

iscon.spouse_converted__c = SLName; //SLName value set properly

return iscon;

 

I am trying to see if a contact exists with the LastName = SLName.

 

Thanks, Mark

I am trying to send a single email to upto ten contacts.  The email may have an attachment, if selected, so that is why I'm not using MassEmail.  I am getting an error message 'System.NullPointerException: Script-thrown exception'.  Below is the code and debug statements:

 

Thanks.

 

20090508211339.922:Class.CandidateBiddersListClass.sendEmail: line 162, column 17: *****CB: sendEmail: mail=Messaging.SingleEmailMessage[getBccAddresses=null;getCcAddresses=null;getCharset=null;getDocumentAttachments=(00P80000003ZJc7EAG);getFileAttachments=null;getHtmlBody=null;getPlainTextBody=null;getTargetObjectId=00580000001mU0tAAE;getTemplateId=00X800000017ZI4EAM;getToAddresses=null;getWhatId=null;isUserMail=false;]20090508211339.922:Class.CandidateBiddersListClass.sendEmail: line 171, column 21: ERROR-eScript-thrown exception
20090508211339.922:Class.CandidateBiddersListClass.sendEmail: line 172, column 21: ERROR-r2null
20090508211339.922:Class.CandidateBiddersListClass.T1: line 445, column 35:     returning NULL from method public System.PageReference sendEmail() in 1952 ms
System.NullPointerException: Script-thrown exception
public PageReference sendEmail() { //SEND OUT EMAILS TO CONTACT LIST if (selectedEmailTemplateId != null) { for (Contact selC : selectedContacts ) { if (selC.email != null) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId (u.Id); mail.setTemplateId(selectedEmailTemplateId); mail.setSaveAsActivity(false); if (selectedAttachmentId != null ) mail.setDocumentAttachments(new Id[]{selectedAttachmentId});  

system.debug ('*****CB: sendEmail: mail=' + mail);

Messaging.SendEmailResult [] r; try { r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } catch (NullPointerException e) { system.debug ('ERROR-e' + e.getmessage()); system.debug ('ERROR-r2' + r); } } } } return null; }

 

  • May 08, 2009
  • Like
  • 0

Usually the Forecast Category field is driven by the Stage picklist but a user can override this value with the Forecast tab. With Apex is there any way to identify if the Forecast Category field has been overridden?

 

Thanks.

  • April 13, 2009
  • Like
  • 0
I am trying to set the case origin field to a value on the edit page right after you click the new button. I have been trying several different ways but have had no luck so far.
 
Trigger: 
 

trigger setOriginTrigger on Case (before insert) {Case[] accs = Trigger.new;setOrigin.addOrigin(accs);}

 

 Class:
 

public class setOrigin { public static void addOrigin(Case[] accs){ for (Case c:accs){ if (c.Origin != 'Customer Portal') { c.Origin = 'Customer Portal' ; } } } static testMethod void runPositiveTest() { string mySubject = ''; string validateNewSubject = 'Customer Portal'; System.debug('Create test case and insert it into the database'); Case c = new Case(Subject = '', Due_Date__c = System.today(), new_subject__c = 'Customer Portal' ); insert c; for(Case c1: [select Subject, new_subject__c from Case where Due_Date__c = TODAY and Subject = null ] ) { mySubject += c1.new_subject__c; } System.assertEquals(validateNewSubject, mySubject); } }

 

 Thank you.

Hey everyone,

 

I've been dabbling in apex code for a while. I've always used system.assert to check my code and view the apex error in my triggers. Once I confirmed I've gotten the right output/input I comment out the system.assert.

 

I've been seeing a lot of board messages suggesting using system.debug. I've looked at the dev. manual and I'm a bit confused. How and when do I use system.debug? Why use system.debug over system.assert?

 

Any real life examples including the system.debug and the output of system.debug would be appreciated as well.

 

Thanks!

Is there a way how to find out which contact the currently logged in user from a partner portal is? Something like a contactId on the user object or a partnerId field on the contact object?

  • July 23, 2010
  • Like
  • 0
I would like to make a dropdown field required but it doesn't display the red line.

Why does this not work?

 

<apex:pageBlockSectionItem > <apex:outputlabel>x</apex:outputlabel> <apex:selectList value="{!nam}" size="1" required="true"> <apex:selectOptions value="{!options}"/> </apex:selectList> </apex:pageBlockSectionItem>

 

 

 

  • March 24, 2009
  • Like
  • 0

I would like to call an apex script when a user clicks a button. How can I do that without using an S-Control?

I know how it works with defining an apex method as a webservice and call it from a s-control but I would like to avoid using s-controls.

 

thanks for any help

  • March 19, 2009
  • Like
  • 0

I would like to clone an opportunity including products. If I do the following call:

 

Opportunity cloneOpp = myOpp.clone(false, true);

 

 Not all the fields are copied and also none of the products. Has this something todo with RecordTypes? But even if I set the Recordtype manually (because otherwise it takes the wrong one) it doesn't work.

 

Any idea?

 

  • March 13, 2009
  • Like
  • 0

I have a webservice method that makes a count soql statement and and an other query.

 

Altough I limit all the queries by 100, I get an exception. Sometimes even on the count statement where rows shouldn't matter.

 

Here is part of the debug log:

 

: Query result size: 100

: All records size: 101

 

System.Exception: Too many query rows: 501

 

Any ideas why this happens?

  • February 27, 2009
  • Like
  • 0
I have a problem using inputText. I know that you can save and use the value entered in an input field in a member variable of the associated control class. But what happens if I don't know how many input fields I need? Is there another possibility ex. using url parameters passing as many values as needed to the form controler?

Thanks for your help.
  • December 10, 2008
  • Like
  • 0
Is it possible to edit security in an Apex Trigger?
There's an object "Profile" but there is no object / field security implemented.

Any idea how we could edit profiles within Apex?
  • November 24, 2008
  • Like
  • 0
Is it possible to delete an attachment (or object in general) permanently without put it in the recyle bin?
Does the recyle bin always use a fixed size or does it increase its size with more objects?
  • July 02, 2008
  • Like
  • 0
Im new to .Net...

Isn't it possible to cast the QueryResult to an SObject where I can access the properties with dot notation instead of using case?

What  I did
Code:
apex.QueryResult all = binding.query("Select a.Id, a.Name from Account");
foreach (var item in all.records)
{
  foreach (XmlElement col in item.Any){
     switch (col.LocalName.ToLower())
     {
         case "id":
            //to something
     }
  }
}

 Is that the only possibility? I would like to have something like:
String accountName = item.Name;

Thanks for your help.

  • June 24, 2008
  • Like
  • 0
Is there a mechanism to lock salesforce for all users except systemadministrator?
If I would like to do some significant changes and would like that salesforce is not accessible, can I some settings that there is a maintenance windows coming up?
  • June 11, 2008
  • Like
  • 0
I need to automatically name opportunities in this format:
AccountName - Autonumber {000000}

How can I implement that? If I create a helping field of type auto number the field is not set in the before insert trigger. In the after insert trigger I can't rename the opportunity.

Any help appreciated.
  • May 30, 2008
  • Like
  • 0
We try to implement a werbservice in Apex that will be accessed by another system.
We would like to return custom objects that were modified in a certain timeperiod. The problem is what do we do if there are more than 1000 records?

We can't return a list beause list can only have the maximum size of 1000 records. Any idea what we could return? Is there something similar to a queryiterator that we can return?

Thanks for your help.
  • May 21, 2008
  • Like
  • 0
Hi

I need to convert a contact back to a lead. The contact object has a picklist "Gender__c" and the leadobject has a picklist "Gender__c" too. When I try to create a new leadobject and asign the gender to it I get an "System.StringException: Invalid id: male" error.

Code:
Contact contact = [Select c.Gender__c from Contact c where c.Id = ... limit 1];
Lead createdLead = new Lead(Gender__c = contact.Gender__c);

 How do I have to assign that?
  • May 20, 2008
  • Like
  • 0
I would like to display a default name in the opportunity edit view. Normally I do overwrite the new button with a S-Control and set the opp3 Parameter to that name.
But what if the Opportunity has different RecordTypes? Because I need the RecordType to pass along I tried to access the url in the S-Control with window.location.href but this gives me a "/servlet/servlet.Integration..." URL instead of the "...&RecordType=....".

Any idea how to solve this problem?
  • May 07, 2008
  • Like
  • 0
Im trying to find out which field values have changed within a "after update" trigger. Because there're a lot of fields I would like to have all field names in a list and loop the list. But this doesn't seem to work.

Dot notation: Account.name
my way: Account['name'] (doesn't work)

Any idea how I could loop all fields of an object?


  • April 22, 2008
  • Like
  • 0

I have a problem: we should fire a trigger after a file was attached to a custom object. Unfortunately the “after insert” and the “before insert” event on the Attachment object doesn’t get fired (but the after delete event does but we don't need that).

Does anybody has an  idea why? It can't be the code, it's just debugoutput. Or any workaroung?


  • April 17, 2008
  • Like
  • 0
Does anybody know anything about the API performance?
How is the performance if the query contains for example 25'000 record? Anybody has any experience? Does Salesforce says anything about that issue?

Thanks for your help.
  • April 15, 2008
  • Like
  • 0
If I have a Trigger on Acccount I can make:
Map<Id, Account>  m = Trigger.new;

and than I can select all Opportunities of those Accounts like that:
List<Opportunity> = [select o.Id from Opportunity where o.AccountId IN : m.keySet()];

But what do I do if I can't use the id of the trigger object, ex.

I have a trigger on Contracts and I want to select all the Accounts, i need something like:
Map<Id, Contract>  s = Trigger.new;
[select a.Id from Account c where a.Id IN :s.values().AccountId]
but this doesn't work, can someone help?
  • April 02, 2008
  • Like
  • 0
I'm looking for a way to update an Opportunity (calculate something and update some fields) whenever an Opportunity was modified.
Is there a way to implement an s-ontrol that does this and attach it to the opportunity? I heard something about inline s-controls but couldn't figure out if that's what I need.

I know that I can do that with triggers (appex code) but I would like to use an s-control.

Can someone helpe me?
  • January 29, 2008
  • Like
  • 0
With the "Professional Edition" you do not have access to the Ajax API (api_disabled_for_org). Is there any other possibility to update custome fields in an Opportunity? e.x. to look up an address from an account and past it in a custom field in the opportunity.
  • December 17, 2007
  • Like
  • 0

Is there a way how to find out which contact the currently logged in user from a partner portal is? Something like a contactId on the user object or a partnerId field on the contact object?

  • July 23, 2010
  • Like
  • 0

Hi ,

 

 I want to write test cases for Event related functionality. I am stuck at creating test data for

  EventAttendees. as EventAttendees are child to Event. and they can be either Contacts, Users or Leads.

 

anyone help me with this?

 

regards,

Sandip  

Hi:

   I have override the new button on the Opportunity with a VF page.

If the User Profile is not XX profile then it will take the user to the regular Opportunity page.

The thing is the User is creating the new opportunity page off the Contact. So the user is on the contact and then from the related opportunity list click on New Opportunity.

 

So if it is a regular user, does anyone know the URL 

so far I have:

 '/006/e?'

but I need to place in the Contact in the URL so it follows through on the Opportunity Record...

 

Thanks

 

Salesforce released a video a while ago showing the capabilities of batch apex:

 

batch video

 

In the video they show a progress bar that auto updates, and the ability to come back to the batch request and view the status. Does any SF developer have the code to handle this in VF and apex? Most documentation says to go to Setup to view the status...seeing this happen in VF is sweet if only they showed how they did it in the video.

 

anyone?

 

James

  • November 11, 2009
  • Like
  • 0

Hello,

 

I have a trigger (before insert, before update) to update some number fields. The field to update depends on the case owner role. This is the code that is getting the error:

 

 

for (Case updatedCase:System.Trigger.new) { Case oldCase = System.Trigger.oldMap.get(updatedCase.Id); User usr = [select Id,UserRoleId from User where Id =:oldCase.OwnerId]; UserRole role = [select Id,Name from UserRole where Id =:usr.UserRoleId];

 Is errors when the owner is a Queue. Is there a easy way to solve this?

 

thanks!

 

Miguel

 

 

Hi,

 

Please help!

I’ve created a veeeeery simple APEX class:

 

 

public class test { public boolean testMethod(){ return true; } }

 


 

The testMethod needs to be called when I press a button (custom button) with JavaScript Behaviour:

 

{!requireScript("/js/functions.js")}
{!requireScript("/soap/ajax/13.0/connection.js")}
{!requireScript("/soap/ajax/13.0/apex.js")}
var answer = confirm("Are you sure you want get Open Positions for this epic?")
if (answer){
alert(sforce.apex.execute("test","test", {}));
} else {}

 

But I have got the following error:

 

 

No operation available for request

{http://soap.sforce.com/schemas/class/test}testMethod.

 

 


 

 

 

  • August 04, 2009
  • Like
  • 0

I just installed CMSForce in development as a trail before I go forth with production...

The first 6 steps of the installation process are concerning. We have way too many documents, dashboards, letterheads, workflows etc that we already have set up in Salesforce. I do not want any existing settings changed that would impact their current function.  Can you verify before I install to production? Thanks!

  1. Change the visibility settings for any installed documents, reports, dashboards, letterheads, email templates, and custom fields on standard objects. By default, these components are visible to all users. Set the Running User for any installed dashboards or analytic snapshots; by default, it is set to you.
  2. Set the Running User for any installed dashboards or analytic snapshots; by default, it is set to you.
  3. Specify the appropriate recipients for any installed workflow tasks.
  4. Specify the appropriate assignees for any installed workflow alerts.
  5. Specify the appropriate user for workflow field updates that modify the Owner field or user lookups; by default, it is set to you.
  6. Create a schedule for any installed analytic snapshots.
  7. Configure any additional settings for this package from the package detail page.
  8. Deploy the package by clicking Deploy Now below. You can also do this at any time in the future from the package detail page.

Hi

 

I am trying to execute the SOSL query with in Developer Edition of SalesForce.

This is my 3rd post still it is not answered.

 

Here is the code I am trying to execute

 

try

{

 

List<List<SObject>> searchList = [FIND 'Levis' IN NAME FIELDS RETURNING Opportunity(Amount, CloseDate, Name, OwnerId, StageName) LIMIT 1];

Opportunity[] records = (List<Opportunity>)searchList[0];

System.debug('@@@@@ In the test1SOSL.....'+records.size());

 

Opportunity opp = [select id from Opportunity where name = 'Levis' limit 1];System.debug('##### Opportunity ID is.....'+opp.id);

 

}catch (Exception ex) {

System.debug(ex);

}

 

I am able to execute the SOQL query but when executing the SOSL query I get the size of the List as 0.

 

please tell me why it is happening with SOSL and help me go forward

 

 

regards

Sunil

 

 

Hi Guys,

Hope somebody has come across this and can provide some help.

 

On the OpportunityLine Item i need to calculate the Total price depending on some formula.

eg: quantity is 1000

      Sales Price is  $ 25

  The customer gets only 50% of the total revenue so i have created a custom field which holds the gross value

25*1000=25000

The net value is 50% of gross value,which is equal to 12500.

 

Now i need to capture this Net value in the Total price field of the OpportunityLine Item(since i need the correct value of the deal for forecasting on the opportunity).

 

I tried doing this using trigger .But it doesnt work.Pls find my code below.

 

 

 trigger AC_OpportunitylineitembeforeUpdate on OpportunityLineItem (before insert, before update) {
    List<OpportunityLineItem> opprs = new List<OpportunityLineItem>();
    for (Integer i=0;i<trigger.new.size();i++) {
        if(trigger.new[i].Net_Campiagn_Value__c != null && trigger.new[i].Revenue_Share__c != null){
            trigger.new[i].TotalPrice = (trigger.new[i].Net_Campiagn_Value__c*trigger.new[i].Revenue_Share__c)/100 ;
        }
    }
}

 

 

 

I also tried this:

 

trigger AC_OpportunitylineitembeforeUpdate on OpportunityLineItem (before insert, before update) {
    List<OpportunityLineItem> opprs = new List<OpportunityLineItem>();
    for (Integer i=0;i<trigger.new.size();i++) {
        if(MyWebService.UpdateCall == false){
            MyWebService.OpportunityLineItemAmount(trigger.new[i]);
        }
    }
}

 

 

But unfortunetly none of it seems to work .

This link tells me that it can be updated:

http://www.salesforce.com/us/developer/docs/sforce70/wwhelp/wwhimpl/common/html/wwhelp.htm?context=sforceAPI_WWHelp&file=sforce_API_objects_OpportunityLineItem.html

 

But i really dont know how.

 

If somebody has come across this problem and has found a solution pls help.

Thanks in advance.

Cheers

 

 

 

Hi All,

 

I explored various docs and came to know that Force.com has introduced one more facility to add

'From Address' to send Email ,Using setOrgWideEmailAddressId(ID) method of SingleEmailMessage Object.

 

But I Could not found any code how to use it. I am trying to set the OrgWideEmailAddressId  by fetching the ID from OrgWideEmailAddress Sobject Using SOQL.But It gives me  'Sobject OrgWideEmailAddress is Not Supported' Error.

 

When I am trying to run the same SOQL query on SystemLog it gives me the result.

 

I also read that we need to do some setting to use the OrgWideEmailAddress facility.

 

Please tell me with code and settings. How to enable the OrgWideEmailAddress Facility and also how to use it in Apex code.

 

Thanks in Advance,

Brijesh Thakur

 

 

I would like to use a variable to define the where clause in a query.

 

I have defined a variable SLName with:

 

SLName=[select id, LastName, spouse_last_name__c from contact

where id = :ApexPages.currentPage().getParameters().get('id')].spouse_last_name__c;

 

How do I make something like the following work?

 

public Contact getSpouseCon(){

if(iscon == null)iscon = [

select FirstName, LastName, spouse_converted__c from contact where Lastname = SLName];

iscon.spouse_converted__c = SLName; //SLName value set properly

return iscon;

 

I am trying to see if a contact exists with the LastName = SLName.

 

Thanks, Mark

Hi all-

 

I'm curious if anybody knows what I might be doing wrong here...

 

I'm trying to run this test as a different user, and it's setting the correct user, but the "CreatedById" isn't being populated when inserting.

 

Is there something I'm missing in the code?  

 

Cheers!!

 

 

// this tests trgCreateOpptyTask
// create a couple opptys and then update them with a unit_id
test.starttest();

Profile p = [SELECT Id FROM profile WHERE name='API'];

User u1 = new User(alias = 'newUser', email='user@mydomain.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='user@mydomain.com');

system.debug('###### the user is: ' + u1.Email);

System.runAs(u1)
{

List<Opportunity> opportunities = new List<Opportunity>();

Opportunity o1 = new Opportunity();
o1.Name = 'Test Oppty 1';
o1.CloseDate = Date.today();
o1.StageName = 'Reservation';
o1.Rental_Rate__c = 100;
opportunities.add(o1);

Opportunity o2 = new Opportunity();
o2.Name = 'Test Oppty 2';
o2.CloseDate = Date.today();
o2.StageName = 'Appointment';
opportunities.add(o2);

Opportunity o3 = new Opportunity();
o3.Name = 'Test Oppty 3';
o3.CloseDate = Date.today();
o3.StageName = 'Lead';
opportunities.add(o3);


insert opportunities;

 }

 

 

 

 

Message Edited by savvyboarder on 06-02-2009 09:27 AM
Message Edited by savvyboarder on 06-02-2009 09:29 AM

I have created a Trigger and a workflow rule (After Update or Insert) against the case comment object.

 

Could you please let me know which one fire first?

 

Thanks

 

Stephen

HI,

 

We have a visualforce page with 3 multi select picklists for the user to select from. We construct the search query in the controller and 'includes', but we get the following error on submission:

 

System.QueryException: expecting a left parentheses, found ':'

Class.searchContact.doSearch: line 175, column 21 External entry point

 

Here is the code for the controller:

 

public class searchContact {
   public String API { get; set; }
   public String apiSessionId {get;set;} 
   public String apiServerURL {get;set;}

  string selectedrating;
  string searchString;
  string recType = 'Candidate';
  string[] grades;
  string[] specialities;
  string[] locations;
  string gmcreg;
  string segment;
  boolean w4f;
  boolean hotdoc;
 
  List<Contact> results;
 
  private final Contact contact;
 
  public searchContact() {
     contact = [SELECT Id, LastName, FirstName, Salutation, Name, MobilePhone, LastModifiedDate, LastActivityDate, a__Rating__c, Doc_Rating__c,
                GMC_reg__c, Grade_s__c, Hot_doc__c, Locations__c, Nationality__c, Speciality__c, Worked_4_Fresh__c, Avail_W_E__c,
                Avail_F_T__c, Avail_from__c, Avail_Updated__c, Segment__c, Job_Ends__c, Current__c, Account.Type, RecordType.Name,
                RecordType.Description, Owner.Username, Owner.LastName, Owner.FirstName, LastModifiedBy.Username, LastModifiedBy.LastName,
                LastModifiedBy.FirstName FROM Contact where RecordType.Name='Candidate' limit 1];
  }
 
  public Contact getContact() {
    return contact;
  }
 
  public String[] getGrades() {
     if (contact.Grade_s__c == null || contact.Grade_s__c == '') {     
       //apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Please select one or more grade first.'));     
        grades = null;     
     }
     else
     {   
     grades = contact.Grade_s__c.split(';',0);   
     }
     return grades; 
  }
 
   public String[] getSpecialities() {
    
       if (contact.Speciality__c == null || contact.Speciality__c == '') {     
        specialities = null;     
     }
     else
     {     
     specialities = contact.Speciality__c.split(';',0);  
     }
     return specialities;
  }
 
    public String[] getLocations() {
    
       if (contact.Locations__c == null || contact.Locations__c == '') {     
        locations= null;     
     }
     else
     {     
     locations= contact.Locations__c.split(';',0);  
     }
     return locations;
  }
 
  public String getSegment() {
    
       if (contact.Segment__c == null || contact.Segment__c == '') {     
        segment= null;     
     }
     else
     {     
     segment= contact.Segment__c;  
     }
     return segment;
  }

  public String getGMCReg() {
    
       if (contact.GMC_reg__c == null || contact.GMC_reg__c == '') {     
        gmcreg= null;     
     }
     else
     {     
     gmcreg= contact.GMC_reg__c;  
     }
     return gmcreg;
  }
 
    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
   
    options.add(new SelectOption('0','--None--'));
    options.add(new SelectOption('1','1'));
    options.add(new SelectOption('2','2'));
    options.add(new SelectOption('3','3'));
    options.add(new SelectOption('4','4'));
    //options.add(new SelectOption('5','5'));
   
    return options;
  }
 
  public String getSelectedRating() {
    return selectedrating;
  }
 
  public void setSelectedRating(String selectedrating) {
    this.selectedrating = selectedrating;
  }   
     
  public Boolean getW4F() {  
     w4f = contact.Worked_4_Fresh__c;  
     return w4f ;
  }
 
    public Boolean getHotDoc() {  
     hotdoc= contact.Hot_doc__c;  
     return hotdoc;
  }
 
  public List<Contact> getResults() {   
    return results;
  }
 
  public PageReference doSearch() {
     results=null;
    
    searchString = 'SELECT Grade_s__c, Speciality__c, Locations__c, Segment__c, GMC_reg__c, a__Rating__c, Worked_4_Fresh__c, Contact_Link__c, Id, Name, LastName, FirstName, MobilePhone, Doc_Rating__c, Current__c, Hot_doc__c, Avail_F_T__c, Avail_W_E__c, Avail_from__c, Job_Ends__c, Avail_Updated__c, LastModifiedBy.Username, LastModifiedDate, Owner.Username, LastActivityDate, Nationality__c FROM Contact where RecordType.Name=:recType';

     getGrades(); 
     getSpecialities();
     getLocations();
     getSegment();
     getGMCReg();
     getSelectedRating();
     getW4F();
     getHotDoc();
    
    
     if (grades != null && grades.size() > 0)    {            
             searchString += ' and Grade_s__c includes :grades';
     }
    
     if (specialities!= null && specialities.size() > 0)    {
       searchString += ' and Speciality__c includes :specialities';
     }
          
      if (locations!= null && locations.size() > 0)    {
       searchString += ' and Locations__c includes :locations';
     }
    
       if (segment!= null)    {
              searchString += ' and Segment__c = :segment';
     }
       if (gmcreg!= null)  {
              searchString += ' and GMC_reg__c = :gmcreg';
     }         
    
     if (selectedrating != null && selectedrating != '0')    {
              searchString += ' and Doc_Rating__c  = :selectedrating';
     }        
     
      if (w4f != false)    {
              searchString += ' and Worked_4_Fresh__c  = :w4f';
     }
      if (hotdoc != false)    {
              searchString += ' and Hot_doc__c  = :hotdoc';
     }
         
          apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, searchString));
 
          results = Database.query(searchString);
          if (results.size() == 0) {
            apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Sorry, no results for current selected criteria')); 
          }
          else
          {
            apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Count : '+ results.size())); 
          }
     return null;      
  }
 
  public PageReference doSend() {
    return null;
  }    
 
 
}

 

Please Help!!

 

Thanks,

 

Rudster

 

At what point does the auto-number field get generated during an insert, and is it available in the record prior to the first Before Insert trigger (that is before the Workflows are evaluated and field updates are fired)?

Can anyone confirm whether this is a bug or a misunderstanding.

 

I cannot create workflow rules on the Attachment or Note objects to notify that they have been added/changed. Therefore I have created a trigger to update a field on the parent custom object, so that the field can be used for the workflow rule. My trigger for notes works fine, but the trigger for attachments (almost identical to the Notes trigger) only fires for undates, not for inserts, whether these are before or after insert. I've looked in the debug log and the trigger is not called at all if an attachment is inserted.


I think this must be a bug. Can't think of any logical reason why Attachments would behave differently to Notes. 

 

My code looks like this:

 

trigger Attachment_BeforeInsertUpdate on Attachment (before insert, before update) {	Attachment[] att = Trigger.new;	for (Attachment item : att ){				//Ignore if no PCR linked to CSR			PCR__c[] pcrs = [select Id, attachment_change__c from PCR__c where Id = :item.parentid];		System.assert(pcrs.size() > 0);		for (PCR__c pcr : pcrs) {				pcr.attachment_change__c = System.now();			update pcr;		}	}}

 Any thoughts anyone?

 

Roger England 

The Apex Developer Guide says the setWhatID method requires an id, and'The value must be one of the following types:"

 

It then lists standard Objects as well as Custom. 

 

Is the expected value the 3 character prefix? the prefix with 12 '0's

behind it, or the Record ID, or what?

 

 

I am trying to send a single email to upto ten contacts.  The email may have an attachment, if selected, so that is why I'm not using MassEmail.  I am getting an error message 'System.NullPointerException: Script-thrown exception'.  Below is the code and debug statements:

 

Thanks.

 

20090508211339.922:Class.CandidateBiddersListClass.sendEmail: line 162, column 17: *****CB: sendEmail: mail=Messaging.SingleEmailMessage[getBccAddresses=null;getCcAddresses=null;getCharset=null;getDocumentAttachments=(00P80000003ZJc7EAG);getFileAttachments=null;getHtmlBody=null;getPlainTextBody=null;getTargetObjectId=00580000001mU0tAAE;getTemplateId=00X800000017ZI4EAM;getToAddresses=null;getWhatId=null;isUserMail=false;]20090508211339.922:Class.CandidateBiddersListClass.sendEmail: line 171, column 21: ERROR-eScript-thrown exception
20090508211339.922:Class.CandidateBiddersListClass.sendEmail: line 172, column 21: ERROR-r2null
20090508211339.922:Class.CandidateBiddersListClass.T1: line 445, column 35:     returning NULL from method public System.PageReference sendEmail() in 1952 ms
System.NullPointerException: Script-thrown exception
public PageReference sendEmail() { //SEND OUT EMAILS TO CONTACT LIST if (selectedEmailTemplateId != null) { for (Contact selC : selectedContacts ) { if (selC.email != null) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId (u.Id); mail.setTemplateId(selectedEmailTemplateId); mail.setSaveAsActivity(false); if (selectedAttachmentId != null ) mail.setDocumentAttachments(new Id[]{selectedAttachmentId});  

system.debug ('*****CB: sendEmail: mail=' + mail);

Messaging.SendEmailResult [] r; try { r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } catch (NullPointerException e) { system.debug ('ERROR-e' + e.getmessage()); system.debug ('ERROR-r2' + r); } } } } return null; }

 

  • May 08, 2009
  • Like
  • 0
Hi Folks,
I would like to make a copy of an opportunity and all its line-items when someone clicks on a custom button (via an S-Control calling a web-service using Apex)

I figure I will pass the Opportunity ID as a parameter in the webservice call, but now I'm having a problem with the cloning part.

If I initialize an Opportunity object "opp" with an SOQL select statement, and then call "opp.clone(true), am I only cloning the object that I initialized? I want to make a copy of the entire thing.  I'm missing a fundamental concept I think.

here's the Apex routine.

WebService static String duplicateOpp(String arg) {
      String test = '005E0000003Relo';
      Opportunity opp = [ select Id,Name from opportunity where id=:test];
     
      Opportunity newOpp = opp.clone( true);
     
      update newOpp;
     
       
      return 'Copied ' + newOpp.Name + ' of type ' + newOpp.Type;
    }

Does anyone know why the following query line:

List<Contact> contacts = new List<Contact> ([Select Id, Email from Contact where IsPersonAccount = false]);

Yields this error message:

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger LeadAssignmentFromImagitas caused an unexpected exception, contact your administrator: LeadAssignmentFromImagitas: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.LeadAssignmentFromImagitas: line 18, column 9

?

The query returns only 58 rows.

Any help is greatly appreciated.  Thank you.
  • February 19, 2008
  • Like
  • 0