• kerwintang
  • NEWBIE
  • 205 Points
  • Member since 2009

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 81
    Replies

Hi,

 

Thanks for the help in advance!

 

Im currently working on a trigger that is supposed to insert ids of the quotes into a detail custom object named CSV_UPLOAD_HISTORY on the field (Quote__c Lookup(Quote)). Im getting an error that says im attempting to dereference a null object do not understand why (System.NullPointerException: Attempt to de-reference a null object: Trigger.assignQuoteIds: line 27, column 1).

 

Here is my code:

 

trigger assignQuoteIds on Quote (before insert) {
    
// Create the list that will contain all quote ID's
    List<Id> l_quote = new List<Id>();
    for(Quote qt: Trigger.new)
    {
        //Collect all Quote ID's
       l_quote.add(qt.OpportunityID);
    }
    
    // Map in order to match Quotes with their respectives CUH's
    Map<ID, CSV_UPLOAD_HISTORY__c> qtMap = new Map<Id, CSV_UPLOAD_HISTORY__c>();
    
    // Loop that creates the correct map between OppIDS and CUH's
    for(CSV_UPLOAD_HISTORY__c cuh : [SELECT OpportunityID__c
    FROM CSV_UPLOAD_HISTORY__c WHERE OpportunityID__c IN :l_quote])
    {
        qtMap.put(cuh.OpportunityID__c, cuh);  // Creating a map with the CUH's
    }
    
    // List in order to update the records with
    List<CSV_UPLOAD_HISTORY__c> l_cuh = new List<CSV_UPLOAD_HISTORY__c>();
    for(Quote qt: Trigger.new)
    {
        CSV_UPLOAD_HISTORY__c cuh = new CSV_UPLOAD_HISTORY__c ();
        cuh = qtMap.get(qt.OpportunityID);
        cuh.Quote__c = qt.Id; // line 27 !!!
        l_cuh.add(cuh);
    }
    
    //update l_cuh;
}

 

 

 

Hi,

 

I am trying to populate value in one field based on the picklist selection in different field of the samae object.

 

exactly like "stage" and "probability" in opportunity..

 

please check the code and tell me why it is not working only in apex:pageBlockTable.

I searched the boards and followed some solution but its not coming,

 

my VF is:

<apex:page standardController="contact" extensions="practice4">

  <script type="text/javascript">
   function populatefield()
    {
     var ex = document.getElementById('{!$Component.form.block.sec.firstfieldID}').value;
     if(ex=="one")
      document.getElementById('{!$Component.form.block.sec.secondfieldID}').value = '1';
     else
      document.getElementById('{!$Component.form.block.sec.secondfieldID}').value = '';
      
     var ex = document.getElementById('{!$Component.form.block.sec.table.firstfieldID1}').value;
          alert(ex);
     if(ex=="one")
      document.getElementById('{!$Component.form.block.sec.table.secondfieldID1}').value = '1';
    }
  </script>
  
<apex:form id="form" >
<apex:pageBlock id="block" >
<apex:pageBlockSection id="sec" >

 <apex:inputField id="firstfieldID" value="{!contact.third__c}" onchange="populatefield();" />
 <apex:inputField value="{!contact.second__c}" id="secondfieldID" />                   

 <apex:pageBlockTable id="table" value="{!section1}" var="allGNG">
  <apex:column headervalue="pick" width="15%" >
  <apex:inputField id="firstfieldID1" value="{!allGNG.third__c}" onchange="populatefield();" >
  </apex:inputField>
  </apex:column>  
  <apex:column headerValue="value">
  <apex:inputField value="{!allGNG.second__c}" id="secondfieldID1" />                   
  </apex:column>

 </apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

my controller is  

public class practice4 {

    public practice4(ApexPages.StandardController controller) {

    }
    public contact[] section1 = new contact[0];
    
     Public List<contact> getsection1()
    {
     section1= [SELECT third__c, second__c from contact];
     return section1;
    }


}

what I saw is "document.getElementById" is getting the values from pageblocksection, but not from pageblocktable.

 

Is there any other way...?!?

 

Thanks

Prabhan

 

 

  • August 01, 2012
  • Like
  • 0

So, I have a visualforce page on a Case page layout. I want the visualforce element to only display the information for the creation time of that case rather then everything in real time. Any ideas from the community on how to do this?

 

Thanks in advance

Hi

 

I have a requirement where I have to extract couple of hundreds of rows and update price. Issue is in the query I have to use. When I try to use the following query with relationships and do an export in data loader no rows gets extracted.

 

Select p.product, p.shipment__r.name,p.id,p.name,p.unit_price__c from  product_shipment__c p

where  p.shipment__r.name like 'Test %'

and p.unit_price__c <> 0  

 

My question is it possible to include relationships in dataloader query . If so, whats the issue with my query.

 

Also is there a way to export rows from apex explorer. When I click on the more button below the rows  , I get a 'unhandled exception error ' 

 

Thanks in advance for your time

gvi 

 

 

Message Edited by gv on 05-12-2009 04:29 PM
  • May 12, 2009
  • Like
  • 0

I had help with this trigger previously and it worked great until the users changed the way they wanted it used.  Here is a link to my previous question.

 

Previous Apex Code Help

 

 

The new issue is that the users want to be able to have more than one Entity Account before they save. Currently the trigger requires a user to have one entity account active in order to change the operational status of an Account to "Operational." The trigger also has the limitation that they can currently only have one Entity Account active before they can change the operational Status to "Operational" then save, the users want to be able to create as many Entity Accounts as they want related to the Account then change the operational status to "Operational" then save.  Currently this produces the error that I have listed in the trigger in the link above.

 

Here is the actual trigger I wrote which is pretty much the same as the one in the link.

 

trigger AccountReqEntity on Account (after insert, after update) { Set<Id> practiceIds = new Set<Id>(); for(Account acct : trigger.new){ //practice record type if(acct.RecordTypeId == '012700000009R7B'){ practiceIds.add(acct.Id); //a list of practices if(acct.Operational_Status__c == 'Operational') { try { Entity_Account__c eAcct = [SELECT Id, Active__c, Account__c FROM Entity_Account__c WHERE Account__c in :practiceIds]; } catch(exception e) { acct.Operational_Status__c.addError('Must have an Entity Account Activated'); } } } } }

 

Any suggestions would be greatly appreciated.

 

Thanks!

 I use following code to invoke a approval process in trigger, the approval process will send an email to the owner's manager for approval, now the problem is when I update of insert the record, the approval will run twice, it will send two email to the owner's manager, but I only invoke it once as you can see in the trigger.

 

 

trigger autoApproveTrigger on Quote__c(after update,after insert) {
    for (Quote__c a : Trigger.new) {
        if(a.Quoted_Cost_Unit_Price__c < a.Field_Min1__c){
             
             Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
             req1.setComments('Submitting request for approval.');
             req1.setObjectId(a.id);
             Approval.ProcessResult result1 = Approval.process(req1);
             
        }else{
            //do nothing for other record type case.
        }
    }
    
}

 

 

If you have multiple datetime values in a map is there a way to grab the earliest 'lowest value' date, when you get the values from the map?

 

Thank you. 

Actually to start with, this may or may not be an issue and am lacking knowledge on SOQL. Let me explain you guys about my case: I got two objects in my database, Users and Contact. Users has got information about user records like email addresses Contact has got info about users contact details like contact email addresses. But User.email != Conatct.email, for some of users in my case and this is because some users have updated the email addresses after the registration. And we did not have any triggers which also updates the contact emails. Now we have that in place. My question is to update the older user accounts(before trigger in place) and I can extract the user emails from User object and Contact emails from Conatct object separately. But I want to extract them in one single data file (excel sheet using Apex dataloader)so that I just replace the contact emails with coressponding new email addresses. Need help in how to extract fileds from two objects into a single data file. Please reply....
  • May 06, 2009
  • Like
  • 0

Hi,

 

I have a managed package with a Master-Detail relationship (both Custom Objects), and for some reason when I install the Managed Package in the Partner Development Org (Enterprise Edition), that Detail Custom Object's page layout has "Submit for Approval" button by default. We don't need that. This happens to all Detail Custom Objects. Would anyone know the reason why it's there by default, and how to remove it automatically when installing the Package?

 

Thanks and Regards,

Kerwin

Hi guys,

 

Is it possible to query the no. of parent records where certain criteria is specified for the child records?

 

e.g. possible ways to do it in SQL:

select  count(1) from Parent where exists (select 1 from Child where Child.parentId = Parent.parentId and <add'l criteria>)

select  count(distinct parentId) from Child where <add'l criteria>

 

 

As i've tried, at best, i can only do this:

select Id,(select  Id from Child where <add'l criteria>) from Parent;

then loop thru all retrieved records, count each record where Child is null.

or

select parentId from Child where <add'l criteria>

then loop thru all retrieved records and count distinc parentIds.

 

Both solutions above suffer in performance, though, since you have to retrieve all records to get the correct number.

 

 

Any of you have a better solution?

 

Best Regards,

Kerwin

Hi,

 

I have a managed package with a Master-Detail relationship (both Custom Objects), and for some reason when I install the Managed Package in the Partner Development Org (Enterprise Edition), that Detail Custom Object's page layout has "Submit for Approval" button by default. We don't need that. This happens to all Detail Custom Objects. Would anyone know the reason why it's there by default, and how to remove it automatically when installing the Package?

 

Thanks and Regards,

Kerwin

Hi,

 

Thanks for the help in advance!

 

Im currently working on a trigger that is supposed to insert ids of the quotes into a detail custom object named CSV_UPLOAD_HISTORY on the field (Quote__c Lookup(Quote)). Im getting an error that says im attempting to dereference a null object do not understand why (System.NullPointerException: Attempt to de-reference a null object: Trigger.assignQuoteIds: line 27, column 1).

 

Here is my code:

 

trigger assignQuoteIds on Quote (before insert) {
    
// Create the list that will contain all quote ID's
    List<Id> l_quote = new List<Id>();
    for(Quote qt: Trigger.new)
    {
        //Collect all Quote ID's
       l_quote.add(qt.OpportunityID);
    }
    
    // Map in order to match Quotes with their respectives CUH's
    Map<ID, CSV_UPLOAD_HISTORY__c> qtMap = new Map<Id, CSV_UPLOAD_HISTORY__c>();
    
    // Loop that creates the correct map between OppIDS and CUH's
    for(CSV_UPLOAD_HISTORY__c cuh : [SELECT OpportunityID__c
    FROM CSV_UPLOAD_HISTORY__c WHERE OpportunityID__c IN :l_quote])
    {
        qtMap.put(cuh.OpportunityID__c, cuh);  // Creating a map with the CUH's
    }
    
    // List in order to update the records with
    List<CSV_UPLOAD_HISTORY__c> l_cuh = new List<CSV_UPLOAD_HISTORY__c>();
    for(Quote qt: Trigger.new)
    {
        CSV_UPLOAD_HISTORY__c cuh = new CSV_UPLOAD_HISTORY__c ();
        cuh = qtMap.get(qt.OpportunityID);
        cuh.Quote__c = qt.Id; // line 27 !!!
        l_cuh.add(cuh);
    }
    
    //update l_cuh;
}

 

 

 

Ok, spoke too soon. I am getting this error and need some assistance in restructuring my code.

 

Below is the code that I have:

List<Trial_Session__c> objTrialSession = new List<Trial_Session__c>();
         
         objTrialSession = [SELECT External_ID__c FROM Trial_Session__c WHERE External_ID__c = :TSInfo.strOrderID];
         
         if(objTrialSession.size() > 0)
         {
            // Existing Session Check
            
            Trial_Session__c updateTrialSession = [SELECT Patient_Data__c, External_ID__c, Test_Date__c, Type_of_Test__c, Reviewer_Name__c, Reviewer_Comments__c, Date_of_Birth__c, Height__c, Weight__c, Gender__c, Ethnicity__c, Asthma__c, COPD__c, Smoker__c, Date_Reviewed__c, Lung_Age__c, Quality_Grade__c, Quality_Grade_Original__c, Software_Version__c FROM Trial_Session__c
            WHERE External_ID__c = :TSInfo.strOrderID];
            
            updateTrialSession.External_ID__c = TSInfo.strOrderID;
            updateTrialSession.Test_Date__c = TSInfo.dtmTestDate;
            updateTrialSession.Type_of_Test__c = TSInfo.strTypeofTest;
            updateTrialSession.Reviewer_Name__c = TSInfo.strReviewerName;
            updateTrialSession.Reviewer_Comments__c = TSInfo.strReviewerComments;
            updateTrialSession.Date_of_Birth__c = TSInfo.dtmDateofBirth;
            updateTrialSession.Height__c = TSInfo.numHeight;
            updateTrialSession.Weight__c = TSInfo.numWeight;
            updateTrialSession.Gender__c = TSInfo.strGender;
            updateTrialSession.Ethnicity__c = TSInfo.strEthnicity;
            updateTrialSession.Asthma__c = TSInfo.strAsthma;
            updateTrialSession.COPD__c = TSInfo.strCOPD;
            updateTrialSession.Smoker__c = TSInfo.strSmoker;
            updateTrialSession.Date_Reviewed__c = TSInfo.dtmDateReviewed;
            updateTrialSession.Lung_Age__c = TSInfo.numLungAge;
            updateTrialSession.Quality_Grade__c = TSInfo.strQualityGrade;
            updateTrialSession.Quality_Grade_Original__c = TSInfo.strQualityGradeOriginal;
            updateTrialSession.Software_Version__c = TSInfo.strSoftwareVersion;

            update updateTrialSession;

            return updateTrialSession;
         }

 It is erroring out on the Update updateTrialSession line.

 

The error is:

'List has more than 1 row for assignment to SObject'

 

Thank you for any assistacne you can prodive. FYI the external ID is set to unique

 

 

Hi,

 

I am trying to populate value in one field based on the picklist selection in different field of the samae object.

 

exactly like "stage" and "probability" in opportunity..

 

please check the code and tell me why it is not working only in apex:pageBlockTable.

I searched the boards and followed some solution but its not coming,

 

my VF is:

<apex:page standardController="contact" extensions="practice4">

  <script type="text/javascript">
   function populatefield()
    {
     var ex = document.getElementById('{!$Component.form.block.sec.firstfieldID}').value;
     if(ex=="one")
      document.getElementById('{!$Component.form.block.sec.secondfieldID}').value = '1';
     else
      document.getElementById('{!$Component.form.block.sec.secondfieldID}').value = '';
      
     var ex = document.getElementById('{!$Component.form.block.sec.table.firstfieldID1}').value;
          alert(ex);
     if(ex=="one")
      document.getElementById('{!$Component.form.block.sec.table.secondfieldID1}').value = '1';
    }
  </script>
  
<apex:form id="form" >
<apex:pageBlock id="block" >
<apex:pageBlockSection id="sec" >

 <apex:inputField id="firstfieldID" value="{!contact.third__c}" onchange="populatefield();" />
 <apex:inputField value="{!contact.second__c}" id="secondfieldID" />                   

 <apex:pageBlockTable id="table" value="{!section1}" var="allGNG">
  <apex:column headervalue="pick" width="15%" >
  <apex:inputField id="firstfieldID1" value="{!allGNG.third__c}" onchange="populatefield();" >
  </apex:inputField>
  </apex:column>  
  <apex:column headerValue="value">
  <apex:inputField value="{!allGNG.second__c}" id="secondfieldID1" />                   
  </apex:column>

 </apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

my controller is  

public class practice4 {

    public practice4(ApexPages.StandardController controller) {

    }
    public contact[] section1 = new contact[0];
    
     Public List<contact> getsection1()
    {
     section1= [SELECT third__c, second__c from contact];
     return section1;
    }


}

what I saw is "document.getElementById" is getting the values from pageblocksection, but not from pageblocktable.

 

Is there any other way...?!?

 

Thanks

Prabhan

 

 

  • August 01, 2012
  • Like
  • 0

I would think this would be a simple thing but I can't find it. The closest is JavaScript and I would like to keep it very simple  indeed.

 

I have a section of a page that is for input. Code below.There are a few things that don't work like I would expect:

  • When the page comes up the cursor is on Contributor Last Name, tabindex=1 not Contributor First Name, tabindex=0 as I would expect.
  • If I enter something in a field, any field, and then press enter what runs is the second button, Export Page, not the first, Run Search, as I would expect.
  • I would like to explicitly place the cursor on a field or button regardless of tabindex. Is there a way to do that?

Are my expectations wrong? What am I missing here? Does all of this have to be done in JS?

 

Thanks... Bob

 

 

  <table width="100%" border="0">
  <tr>  
    <td width="200" valign="top"> 
      <apex:pageBlock title="Search Criteria" mode="edit" id="criteria">
      <table cellpadding="2" cellspacing="2">
      <tr>  <td style="font-weight:bold;">Contributor First Name<br/>  <apex:inputText id="contributorFname" tabindex="0" value="{!contributorFname}"/>  </td></tr>
      <tr>  <td style="font-weight:bold;">Contributor Last Name<br/>  <apex:inputText id="contributorLname" tabindex="1" value="{!contributorLname}"/>  </td></tr>
      <tr>  <td style="font-weight:bold;">Contributor State<br/>  <apex:inputText id="contributorState" tabindex="2" value="{!contributorState}"/>  </td></tr>
      <tr>  <td style="font-weight:bold;">MOC First Name<br/>  <apex:inputText id="MOC_Fname" tabindex="3" value="{!MOC_Fname}"/>  </td></tr>
      <tr>  <td style="font-weight:bold;">MOC Last Name<br/>  <apex:inputText id="MOC_Lname" tabindex="4" value="{!MOC_Lname}"/>  </td></tr>
      <tr>  <td style="font-weight: bold;">Record Limit<br/>
           <apex:selectlist tabindex="5" value="{!soqlLimitPage}" multiselect="false" size="1">
              <apex:selectOption itemValue="limit 20" itemLabel="20 Records"/>
              <apex:selectOption itemValue="limit 40" itemLabel="40 Records"/>
              <apex:selectOption itemValue="limit 80" itemLabel="80 Records"/>
           </apex:selectlist>           
      </td></tr>
      <tr>  
        <td style="font-weight: bold;"><br/>
          <apex:commandButton action="{!runSearch}" tabindex="6" value="Run Search" rerender="results,debug" id="theSearch"/>         
      </td>
      </tr>
      <tr>  
        <td style="font-weight: bold;"><br/>
          <apex:commandButton action="{!$Site.CurrentSiteUrl}/apex/ContributionsToCSV_v1" tabindex="7" value="Export Page" id="theExportPage" />         
      </td>
      </tr>      
    </table> 

 

 

 

  • July 31, 2012
  • Like
  • 0

Hi All,

Please Help me in my issue.from last two days it's not came.

 

I wnat to open a new window when we click on a button.So popwindow came now.

But whenever we click on outside the popup window it should be close.

It can work on VF page. But i want to create javascript Button for this same issue . 

My VF page code is:

 

<apex:page >

<script type="text/javascript">

function openLookup(){

var url="/apex/LookupExamplePopup?namefield=" + name + "&idfield=" + id;
newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
if (window.focus)
{
newWin.focus();
}

return false;
}

<!-- openPopup("apex/dfsdfs","350, 480,height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no",true); -->

}
</script>

<apex:form >
<apex:commandButton onclick="openLookup();return false;" value="Show Popup"/>
</apex:form>

</apex:page>

---

The same thing should be done on Javascript button also.

 

Please help me guys,

hi guys,

 

Please help me in with the query.

My contact will have only one opportunity  1-1 relation ship:-1 account ,1 contact 1, opportunity.

 

  for(Comments__c cs:trigger.New){
        cms=cs;    
        if(cms.Opportunity__c==null && cms.Contact__c!=null ){
            sobjectSetOfIds.add(cms.Contact__c);           
        }
    }   
    
    Map<Id,Contact>smap1= new Map<Id, Contact>([Select id
                                                        ,Name
                                                        ,Opportunities__r.id // error  
                                                         from Contact 
                                                         where Id in : sobjectSetOfIds]);
                
    for(Comments__c s: trigger.new){
        if(smap1.containsKey(s.Contact__c)){        
            s.Opportunity__c=smap1.get(s.Contact__c).Opportunities.id;    //error
                
        }
    }

 

Thanks

Anil.B

 

Force community, 

 

I'm new to writing Apex triggers, and wanted to get some feedback on my issue. I currently have two Custom Objects - lets call those CO1 and CO2.

 

CO1 records are created as children of Opportunities, and contain about 20 fields. When my company signs on a client, we change a field called 'Type' on the Account object to 'Customer' instead of 'Prospect'. When this happens, I'd like to have an Apex Trigger create a new CO2 record, and copy all the data from existing CO1 records (which are, again, children of the opportunity), to CO2 records, which are merely related to Accounts.

 

I'm pretty new to this, but my two biggest questions are these: Do I have to compare a map to notice if the Type = Customer? And how exactly do I navigate related objects to find the correct CO1 record to copy? 

 

Thanks, any help is apprecaited! 

 

I am very new to apex and I am trying to learn it on my own, I have been trying to create a webservice from my wsdl file, but i get the error below.

 

The following generated class(es) have compilation errors: Error: xserver


Error: unexpected token: 'Select' at 748:46.

 

After reading I have found out that select is a keyword. The select keyword is in my method:

here is a snippet of my wsdl. And most of my class names also include this is there any advice or tips for solving this because changing the webservice

would be a major issue. 

 

 public xserver.SelectResult Select (String tXqlQuery) {
            xserver.Select_element request_x = new xserver.Select_element();
            xserver.SelectResponse_element response_x;
            request_x.tXqlQuery = tXqlQuery;
            Map<String, xserver.SelectResponse_element> response_map_x = new Map<String, xserver.SelectResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://XServer/Select',
              'http://XServer/',
              'Select',
              'http://XServer.nl/',
              'SelectResponse',
              'xserver.nl.SelectResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.SelectResult;
        }

 

 

Thanks

 

Jamil