• Mak
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 28
    Replies

Hello

 

I am a newbie to visualforce pages. From 3days i am trying to figure out a way how to pass parameters from VS page to apex class. Please help!!

 

I have a custom link on home page which points to VS page. Based on the loggged in user, i have to check few things in the custom object and return those results to the VS page.

 

For this i need to pass logged in user id to the apex class query the custom object for this userid and return few fields data.

 

Can someone Please advise how to solve this....Thanks

 

  • March 25, 2009
  • Like
  • 0
Hi,

I added an before insert trigger on Attachment object and it doesn't fire.
It works in case of Update but not on After Insert or Before Insert.
Anyone knows the reason behind this?

I found three posts on this issue but no one has ever replied to this.

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=9947&jump=true#M9947
http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=3312
http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=1342

Thanks

Message Edited by Mak on 12-01-2008 03:34 AM
  • December 01, 2008
  • Like
  • 0
I tried moving a page in a sandbox from dev enviornment. This page is still working correctly on dev.
But on trying to save the page on sandbox, I received the following error:
Expression Error: Named Object: core.apexpages.components.cdk.ApexComponentRefHandler not found.

Apparently, this is caused when you use <apex:pageMessages /> in your Visualforce page. I remove this one line and my page is saved without a problem.

I have no clue what the error means and how to avoid it. Could someone help me out of this?

Thanks

  • August 26, 2008
  • Like
  • 0
Hi

I have multiple views for an object. The user can select any view and go on to edit any particualr instance of the object.
Now I want to redirect the user to correct view (the one he came from), when he is done with editing and hits 'Save'.
Is there any method in Apex which could give me the last URL?

Thanks
  • August 22, 2008
  • Like
  • 0

Hi,

 

I have a method which is marked as future which is being called from 2 triggers. But when executed in production I get the following error:

 

Failed to invoke future method 

 

caused by: System.AsyncException: Future method cannot be called from a future method:

 

 

Is this a case of recursion? I am not sure what the exact error is and how would I go about fixing this

 

Thanks

Gita 

 

  • August 11, 2009
  • Like
  • 0

// WHEN NEW PATIENT IS ADDED OR UPDATED, TRIGGER CREATES A PATIENT__SHARE IF AN ASSOCIATED PORTAL
// USER EXISTS.  IF NOT, PATIENT SHOULD BE ADDED WITHOUT SHARING OR ERROR.

trigger PhyPortalPatientApexSharing on Patient__c (after insert, after update)
{

    // CREATE A NEW LIST OF SHARING OBJECTS FOR PATIENT.
    List<Patient__Share> patientShrs  = new List<Patient__Share>();
     //Map<ID,Patient__c> posIdToPatientMap = new Map<ID,Patient__c>(); // Map of PositionId-->Patient__c record  
    // DECLARE VARIABLES FOR PATIENT SHARING.
    Patient__Share physicianShr;
    Patient__Share patientShr;
      
    for(Patient__c p : Trigger.new)
    {
        // FOR ASSOCIATD REFERRALS FIND ASSOCIATED PORTAL USER.
       for(List<Prescription__c> prescriptions : [Select id,Patient_MRN__c,r.Physician_Contact__r.Portal_User_ID__c,Patient_MRN__r.id   From Prescription__c r where r.Physician_Contact__r.Portal_User_ID__c!=null])
       {
       if(prescriptions.Prescription__c != null)
       {
          for(List<Patient__c> Patients : [Select id, name From Patient__c Where name=:prescriptions.Patient_MRN__c])
            {
            // loop thru the list of interviewers and create sharing records
                for(Patient__c p1 : Patients)
                {
            // INSTANTIATE THE SHARING OBJECTS.
          
            physicianShr = new Patient__Share();
           
            // SET THE ID OF THE RECORD BEING SHARED.
            physicianShr.ParentId = p1.id;
           
            // GET THE ID OF THE RELATED USER BEING GRANTED ACCESS. THERE MAY BE MORE THAN 1
            // PHYSICIAN PORTAL USER TO SHARE TO.
           //Prescription__c pe = [Select Physician_Contact__r.Portal_User_ID__c From Prescription__c Where Id=:prescriptions.Id];
                             
            // SET THE ID OF THE USER BEING GRANTED ACCESS.
            physicianShr.UserOrGroupId = prescriptions.Physician_Contact__r.Portal_User_ID__c ;
                                   
            // SET THE ACCESS LEVEL.
            physicianShr.AccessLevel = 'read';
                       
            // SET THE APEX SHARING REASON FOR PHYSICIAN.
            physicianShr.RowCause = Schema.Patient__Share.RowCause.Physician_Portal_User__c;
                       
            // ADD OBJECTS TO LIST FOR INSERT.
            patientShrs.add(physicianShr);
            }//end of for loop
            }//end of for loop
       }//end of for loop
       }//edn if loop
            }

My query returns the output as List<List<sobject>>.

When I tried to read it from VF page, it throws error
Unknown property 'VisualforceArrayList.Aircraft__c' 

 

Here is the sample code, that i have written.

 

<apex:dataTable value="{!SearchFlights}"
var="flight" styleClass="list" rendered="{!NOT(ISNULL(SearchFlights))}">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!flight.Aircraft__c}"/>
</apex:column>
<apex:column >

 

Can anybody please explain me How to read List<List<sobject>> and display it on the on visualforce page.

i have an object called ScoringRule. ScoringRule has these fields - FldName, Operator1, Val1, Operator2, Val2, Score. This would return me more than 1 record. 

 

How can i loop through the records? I dont want to display it on a page but i want to compare the fieldName__c with the lead object's field and apply some logic to it.

 

So i will have 2 queries:

     // Get me the result from the query
        ScoringRule__c score = [Select n.fieldName__c,
                           n.Val2__c, n.ScoringRule_Rule1__c, ScoringRule_Val1__c,
                           n.Score__c, n.Rule2__c
                           FromScoringRule__c n
                           where n.Val2__c != '' 
                           and n.fieldName__c!='']; 

 

 Lead lead = [select FirstName, LastName, NumberOfEmployees, AnnualRevenue from lead]

 

I want to compare the fieldName__c with the the fields returned by the lead query.

 

Any help would be appreciated.

 

Regards

  • June 19, 2009
  • Like
  • 0

How can I make a page that has both Master Record and Detail Records on the same page for data entry?

 

I have a Header Table and a Line Table and would like to be able to enter the Header Details at the top of the page and then be able to add multiple lines associated with the Header, all from within the same page.

 

So the Page would look somewhat like:

 

Header Field 1 Header Feild 2 Header Field 3

-------------------------------------------------------------------- 

 

Row 1 = Detail Field 1 Detail Field 2 Detail Field 3 Detail Field 4

Row 2 = Detail Field 1 Detail Field 2 Detail Feild 3 Detail Field 4 

.

.

 

 

Thanks. 

  • June 18, 2009
  • Like
  • 0

I've run into some issues after the summer 09 update changing the behavior of commandButton/commandLink rerenders and it behaves differently in Firefox vs. IE. I've got a pageBlockTable with one column containing a "Copy" commandLink and the next column containing an inputField. Clicking the Copy link will copy the value from the inputField on that row to all other objects in the list. The commandLink then refreshes the pageBlockTable only so the copied values are displayed to the user. This much works perfectly in both Firefox and IE.

However IE goes a step further. After refreshing the pageBlockTable and displaying the copied values correctly, it then refreshes the entire page. Problem is, this causes the original queries to re-fire and all the object values are returned to their original values and the user's "copy" is wiped out before their eyes. This second refresh does not happen in Firefox.

 

<apex:pageBlockTable id="avlist" value="{!accountVariables}" var="av">
<apex:column headerValue="Copy">
<apex:commandLink value="Copy" action="{!copyFieldValue}" status="accountcopy" rerender="avlist" rendered="{!IF(contains(av.Category__c, 'Account'), 'true', 'false')}">
<apex:param name="avarid" value="{!av.Account__c}"/>
<apex:actionSupport event="oncomplete" status="accountsuccess"/>
</apex:commandLink>
</apex:column>
<apex:column headerValue="{!av.FieldID__c} {!av.Variable_Master__r.Name}">

<apex:outputPanel id="editvalue" rendered="{!IF(AND(OR(av.Type__c='Image',contains(av.Type__c, 'Text')), contains(av.Category__c, 'Account')), 'true', 'false')}">
<apex:inputField value="{!av.Value__c}"/>
</apex:outputPanel>

</apex:column>
</apex:pageBlockTable>

 

 

Message Edited by MarkL on 06-18-2009 09:17 AM

I am in the process of writing a test method in the developer version of Salesforce for a visualforce controller class that i have created.

 

The creation of which I have assumed there will be some test data in the system to work with?

 

When migrating my project accross to the Enterprise  version of the Salesforce system I am assuming that I can initailly import all my code into a sandbox version of my system... (without needing to pass the unit tests) and then input some test data which will allow the test methods to pass? Or should I rewrite my test methods in such a way  that no data(other than reference data) need be in the sytem. Also some of my reference data is held in its own Objects in the sytem can I package this up for the main export. Excuse theses newbie questions.  

Hi All


I have a custom object that contains more than 100,000 records. Now I want to get count of records on visualforce page. But apex has a governor limits of 10,000 query rows. And API calls is also not fulfill this requirement, due to API calls limit per day.


Any other idea???


Thanks



  • June 18, 2009
  • Like
  • 0

To auto populate the standard employee number field on user object I have created auto no field and using a trigger on object user on after insert I am updating also . Also as per my requirement I have to also create a contact record on the after insert of user . But is not allowing me to do both the dml operation together.

 

the code is as follows:

trigger employeenoautopopulate on User (after insert)
{
 
     List<Contact> Con = new List<Contact>();
 
     for(User usr: Trigger.new)
     {
             System.debug('****** condition true');
             Contact con_temp = new Contact();
             con_temp.FirstName = usr.FirstName;
             con_temp.LastName = usr.LastName;
             con_temp.Date_Of_Joining__c = usr.Date_of_Joining__c;
             con_temp.User__c = usr.Id;
             con_temp.OwnerId = usr.Id;
             con_temp.Employee_Number__c = usr.Employee_Number__c;
             Con.add(con_temp);
      }  
      if(Con.size()>0)
      {
       insert Con;
        System.debug('****** insert done');
      }
   
     Set<Id> userid = new Set<Id>();
     for(User usr: Trigger.new)
     {
  
         userid.add(usr.Id);   
     }
  
     User[] usr = [select Id, EmployeeNumber,Employee_Number__c from user where Id in :userid];
     for(Integer i=0;i<usr.size();i++)
     {
        usr[i].EmployeeNumber = usr[i].Employee_Number__c ;
        System.debug('****'+usr[i].Employee_Number__c);
     }
      
      update usr;
      System.debug('****** update done');
}

 

I am getting following exception:

 

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger employeenoautopopulate caused an unexpected exception, contact your administrator: employeenoautopopulate: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User: []: Trigger.employeenoautopopulate: line 20, column 8
 

 

  • June 18, 2009
  • Like
  • 0

I'm writing what should be a simple Apex class to determine if a Lead being added already exists as an Account. To do this, I need to check for matching email addresses between the Lead and the Account Contacts, and matching company names and zip codes between the Account and the Lead. They have very little data in their sandbox, so I tested the best I could in my dev account, and had 92% coverage on the class with no errors. Right after deployment though, two of the queries started exceeding governor limits, in ways that just don't make sense to me.  (I'm still waiting on specific data to recreate.) Here's the first, which generates a "Too many query rows:1001" exception.

 

if (TestLead.Email != null) { // Nested query returns accounts having contacts with matching emails Account[] emailAccts = [SELECT AccountNumber, Account_Activity__c FROM Account WHERE ID in (SELECT AccountID FROM Contact WHERE Email = :TestLead.Email)]; if (!emailAccts.isEmpty()) { bFoundExact = true; sExactType = emailAccts[0].Account_Activity__c; } }

 

 

The error column is 30, which is the beginning of the outer Select - does that mean it's the number of Account records that's too large? If so, is my problem related to the IN working on all the empty result sets the inner query will return? If that's not it, ...?

 

The second error is even more of a mystery, it's "Non-selective query against large object type (more than 100000 rows)." Here's the query:

 

for (Contact zipContact : [SELECT Account.Type, Email FROM Contact WHERE Account.BillingPostalCode = :TestLead.PostalCode]) { ContactDomain = DomainPart(zipContact.Email); if (ContactDomain == LeadDomain) // Partial match { bFoundPartial = true; sPartialType = zipContact.Account.Type; break; } }

 

 

Ok, so I get that the zip codes probably aren't indexed fields so it's got to check all the records, and they do have 50k accounts, but 1 million contacts still seems a bit unlikely. Any idea what I'm doing wrong? How do I read that message - that the result set has too many rows, or that the object being queried on a non-indexed field has too many?

 

Finally, I've searched high & low and can't find out how to tell which fields in an object are indexed, could someone kindly point me in the right direction?

 

Thanks,

Mike Brumley

 

VisualForce pages rendered as PDF never retain the font styling and other formating present in the HTML. What have you done to make the output more like the HTML output?

I created a trigger to check for duplicate and raise an error.

It woks fine for Admin users.

Howevere when run by sales users they have the following error : 

 

Review all error messages below to correct your data.
Apex trigger setOwnerFromPrevious caused an unexpected exception, contact your administrator: setOwnerFromPrevious: 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 DuplicateLead on Lead (before insert) {
Map<String, Lead> leadMap= new Map<String, Lead>();

for (Lead lead : System.Trigger.new) {
if(lead.Email !='' && lead.Email != null )
leadMap.put(lead.Email, lead);
}
if(leadMap.size()>0){
for (Lead lead : [SELECT Email,OwnerId,Account_Application__c,LeadSource,Account_Application_Date__c,ConvertedDate FROM Lead WHERE Email IN :leadMap.KeySet() Limit 1000])
{
Lead newLead = leadMap.get(lead.Email);
if(newLead!=null){
newLead.Email.addError('Email already exist');
}
}
}
}
 

 Any help will be greatly appreciated.

Message Edited by mhanafi on 06-17-2009 05:58 AM

Hi,

 

I am trying to code down Apex script for the case when the account is of particular record type, insert and update some fields. I have done via hard coding record-type id field value and it succeeded in inserting and updating field values but still I want to generalise the code so that the same can be used in all sandboxes and organisations (I may be wrong but from what I have heard and learned, recrod type ids vary in sandbox and production environment for same record type, please let me know if I am wrong).

 

I have attempted to write the code as shown below. But still it does not work as required(does not insert/update records as per condition of Record Type name).

 

trigger AccRecTypeMatchAutoPopulateFieldValues on Account (before insert, before update)
{
   List<Id> AccIds = new List<Id>();
   String Flag;
 if(Trigger.isInsert)
 {
   Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
   Account[] newAccs = Trigger.new;
   for(Integer i=0; i < newAccs.size(); i++)
   {
    if(Trigger.new[i].RecordTypeId == RecId)
   //for(Account newAccs : Trigger.new)
    {
        // if(newAccs.RecordTypeId == '01290000000ChWo')
        //
          newAccs[i].Website = 'http://www.tcs.com';
          newAccs[i].BillingStreet = 'Yantra Park';
          //a.BillingCity = 'Mumbai';
          newAccs[i].BillingState = 'Maharashtra';
          newAccs[i].BillingCountry = 'India';
          newAccs[i].Fax = '223120';
          newAccs[i].Phone = '2230175';
          Flag = 'Y';
          AccIds.add(newAccs[i].Id);
  }
 }
 if(Flag == 'Y')
{
 Account[] accs = [select Id, name from Account where Id in :AccIds];
 insert accs;
}
}

if(Trigger.isUpdate)
{
 Id RecId = [Select Id, Name from RecordType where name = 'rec_type1' limit 1].Id;
   Account[] oldAccs = Trigger.new;
   for(Integer i=0; i < oldAccs.size(); i++)
   {
    if(Trigger.new[i].RecordTypeId == RecId)
   //for(Account newAccs : Trigger.new)
    {
        // if(newAccs.RecordTypeId == '01290000000ChWo')
        //
          oldAccs[i].Website = 'http://www.tcs.com';
          oldAccs[i].BillingStreet = 'Yantra Park';
          //a.BillingCity = 'Mumbai';
          oldAccs[i].BillingState = 'Maharashtra';
          oldAccs[i].BillingCountry = 'India';
          oldAccs[i].Fax = '223120';
          oldAccs[i].Phone = '2230175';
          Flag = 'Y';
          AccIds.add(oldAccs[i].Id);
    }
   }
   if(Flag == 'Y')
{
 Account[] accs = [select Id, name from Account where Id in :AccIds];
 update accs;
}}

}

I need to create enable a new SelfServiceUser when a contact of specific record type is created.

 

This is what I got so far, but I am stuck.

 

Would appreciate your help

trigger test1 on Contact (after insert) { List<SelfServiceUser> newSSU = new List<SelfServiceUser>(); for (Contact c : Trigger.new) { SelfServiceUser s = null; if (c.RecordTypeId == '01220000000135y') { s = new SelfServiceUser(); s.ContactId = c.Id; s.Email = c.Email; s.FirstName = c.FirstName; s.LastName = c.LastName; s.IsActive = true; } newSSU.add(s); } insert newSSU; }

 

The errors and problems I have are;

 

1. I get an error as follow:

 

Severity and Description Path Resource Location Creation Time Id Save error: DML not allowed on SelfServiceUser Test/src/triggers test1.trigger line 23 1238057376540 70

 -- I guess I cannot create SSU like this - what is the correct way than?

 

2. I think that  my workflow is wrong, but not sure how to fix.

 

Would appreciate any help.

 

 

 

I was at a Developers User Group meeting in NYC the other night and swore that I saw switch being used in an example by Ron Hess.  I don't see documentation for it though and can't get it to compile right when I try it (see example below, I get an error on the very first line).  So either my syntax is off OR Ron was in a beta development environment not available to the rest of us OR I'm seeing code that doesn't exist.  Any ideas anyone, Ron?

 

 

switch (strType){ case 'Counseling/Referral Case': System.debug('I would like this to work'); }

 

 

Hello

 

I am a newbie to visualforce pages. From 3days i am trying to figure out a way how to pass parameters from VS page to apex class. Please help!!

 

I have a custom link on home page which points to VS page. Based on the loggged in user, i have to check few things in the custom object and return those results to the VS page.

 

For this i need to pass logged in user id to the apex class query the custom object for this userid and return few fields data.

 

Can someone Please advise how to solve this....Thanks

 

  • March 25, 2009
  • Like
  • 0
Hello Everyone,

I hope you can help me on this..Im working with singleEmail to send an email to a particular sales representative on every territory. but every time I invoked my trigger via update of my objects, it returns an exception. The error is: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.\.: Trigger.Notify_Rep_Trigger: line 90, column 21

my code is written below:

Account territory = [select Territory_Name__c from Account where Id =:data.Account_ID__c];
           
            if(territory.Territory_Name__c != null)
            {
               
                List<string> splitID = territory.Territory_Name__c.split(';', -1);
                Set<string> tID = new Set<string>();
                tID.clear();
               
                List<Territory> territoryId = [Select id From Territory where name in :splitID];
               
                List<UserTerritory> usersId = [Select UserId From UserTerritory where territoryid in :territoryId];
               
                for(integer x=0; x < usersId.size(); x++)
                {
                        tID.add(usersId[x].UserId);
                }
               
                List<User> emailAdd = [select Id, email from User where Id in :tID];
               
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                List <String> Addresses = new List<String>();
           
                for(integer i=0; i < emailAdd.size(); i++)
                {
                    //String[] toAddresses = new String[] {emailAdd[i].email};
       
                    //mail.setToAddresses(toAddresses);
                    mail.setCcAddresses(ccAddresses);
                   
                    mail.setBccSender(true);
                    mail.setUseSignature(false);
                    mail.setSaveAsActivity(false);
                   
                    String toTargetObjects = (string)emailAdd[i].Id;
                   
                    system.debug('target object deb:'+toTargetObjects);
                    system.debug('data id deb:'+data.Id);
                   
                    mail.setTargetObjectId(toTargetObjects);
                    mail.setWhatId(toTargetObjects);
       
                    mail.setTemplateId(templateId);
                   
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                }
            }
        }

any suggestion? I would really appreciate it if you can help me on this.


Thanks in advance,

Wilson




Message Edited by wilson34 on 11-21-2008 01:50 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:51 AM

Message Edited by wilson34 on 11-21-2008 01:53 AM
Hi,

Is there any way to know if an attachment is added in salesforce? I am creatin an application to process cases and its attchemnt created/updated in salesforce. We are using outbound messaging to know whenever a new case is created/updated but we cant create an outbound message when an attahcment is added to a case.

Can anyone suggest a way to let my application know when an attachment is added to the case.

Thanks
GM
  • January 29, 2008
  • Like
  • 0