• MarkWaddle
  • NEWBIE
  • 150 Points
  • Member since 2011

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 34
    Replies

We have the following wrapper class:

 

 

public class wrapperClassController {

    //Our collection of the class/wrapper objects cTest__c 
    public List<cProducts> productsList {get; set;}
    
    //This method uses a simple SOQL query to return a List of NRProducts__c
    public List<cProducts> getProducts(){
        if(productsList == null){
            productsList = new List<cProducts>();
        
            for(NRProducts__c c : [select Id, Name, Comments_to_Content_Team__c, Product_Description__c, Feature1__c, Feature2__c, Feature3__c, Feature4__c from NRProducts__c WHERE Feature1__c = null limit 100]){
                /* As each NRProducts__c is processed we create a new cProducts__c object and
                add it to the testProducts */
                productsList.add(new cProducts(c));
            }
        }
        return productsList;
    }
    
    public PageReference processSelected(){
        /*We create a new list of NRProducts__c that will be populated only with NRProducts__c
        if they are selected*/
        List<NRProducts__c> selectedProducts = new List<NRProducts__c>();
        
        /*We will cycle through our list of NRProducts__c and will check to see if the 
        selected property is set to true, if it is we add the NRProducts__c to the 
        selectedNRProducts__c list. */
        for(cProducts cCon : getProducts()){
            if(cCon.selected == true){
                selectedProducts.add(cCon.con);
            }
        }
        
        /* Now we have our list of selected NRProducts__c and can perform any type of 
        logic we want, sending emails, updating a field on the NRProducts__c, etc */

        for(NRProducts__c con : selectedProducts){
            system.debug(con);
update selectedProducts;
        }
        return null;
    }
    
    /* This is our wrapper/container class. A container class is a class, a data 
    structure, or an abstract data type whose instances are collections of other 
    objects. In this example a wrapper class contains both the standard salesforce 
    object NRProducts__c and a Boolean value */
    public class cProducts{
        public NRProducts__c con {get; set;}
        public Boolean selected {get; set;}
        
        /*This is the contructor method. When we create a new cNRProducts__c object we pass a 
        NRProducts__c that is set to the con property. We also set the selected value to false*/
        public cProducts(NRProducts__c c){
            con = c;
            selected = false;
        }
    }
}

 And the following page:

 

 

<apex:page controller="wrapperClassController">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cAccount records -->
            <apex:pageBlockTable value="{!Products}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the account values within our cAccount container/wrapper -->           
                <apex:column value="{!c.con.Name}" />

                         <apex:column headerValue="Feature1">             
                <apex:inputField value="{!c.con.Feature1__c}" />
                      </apex:column>
                         <apex:column headerValue="Feature2">             
                <apex:inputField value="{!c.con.Feature2__c}" />
                      </apex:column>
                         <apex:column headerValue="Feature3">             
                <apex:inputField value="{!c.con.Feature3__c}" />
                      </apex:column>
                          <apex:column headerValue="Feature4">             
                <apex:inputField value="{!c.con.Feature4__c}" />
                      </apex:column>
                 <apex:column value="{!c.con.Comments_to_Content_Team__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Everything works as expected when a field is updated, checkbox is checked, and "Process" button is clicked. Except....the table does not rerended. The result that is expected is that the record with thefield that was updated should no longer be in the list, because the Controller statement is looking for ones with this field == null.

 

Not sure what I am missing?

 

  • April 26, 2011
  • Like
  • 0

I am working on an application where the user will create a custom object (mps) record from the opportunity and a trigger will update certain fields on the mps from the opportunity.When there is an MPS record attached to the opportunity, the opportunity will update the mps, and when the mps is updated, the opportunity is updated. This has created an error that says "...cannot recursively update itself..." I am trying to find a way to prevent this. The problem is I cannot the find a way to break this recursion.

 

I wannt both records to be updated when one record is updated. Below are my triggers:

 

 

trigger OppUpdateMPS on Opportunity (before update) {
       Map<Id, Id> mapOpportunitytoMPS = new Map<Id, Id>();

    for(Opportunity o : trigger.new){
        // Populate map of Opportunity.Id to MPS.Id
        if (o.MPS__c != null) {
            mapOpportunitytoMPS.put(o.Id, o.mps__c);
        }
    }

    if (!mapOpportunitytoMPS.isEmpty()) {
        // Query all relevant opportunities to a map with key of Opportunity.Id
        Map<Id, MPS__c> mps = new Map<Id,MPS__c>([select id, MPS_BV__c, MPS_Comment__c, 
                         MPS_Scheduled_Ship_Date__c, MPS_Status__c, Close_Date__c, LastModifiedDate,
                         Projected_Ship_Date__c, Projected_On_Site_Delivery_Date__c,
                         Forecast_Category__c, Combined_Probability__c, Recursive_Update__c
                         from MPS__c where id in:mapOpportunitytoMPS.values()]);

        List<MPS__c> mpsToUpdate = new List<MPS__c>();
        Id mpsId;
        MPS__c m;

        for (Opportunity s : trigger.new) {
            if (mapOpportunitytoMPS.containsKey(s.Id)) {
                // Get the MPS__c ID from the map
                mpsId = mapOpportunitytoMPS.get(s.Id);
                // Get the opportunity based on the opportunity ID
                m = mps.get(mpsId);
                // Set fields on MPS based on Opportunity
                m.Forecast_Category__c = s.ForecastCategoryName;
                m.Combined_Probability__c = s.Combined_Probability__c;
                m.Close_Date__c = s.CloseDate;
                m.Projected_Ship_Date__c = s.Projected_Ship_Date__c;
                m.Projected_On_Site_Delivery_Date__c = s.Projected_On_Site_Delivery_Date__c ;
                m.MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;
                MPSToUpdate.add(m);
            }
        }

        // Update all MPS__c in one call
        update MPSToUpdate;
        
    }
}

 

trigger MPSUpdate on MPS__c (Before Insert, Before Update) {
    Map<Id, Id> mapMpsToOpportunity = new Map<Id, Id>();
     
    for(MPS__c mps : trigger.new){
        // Populate map of MPS.Id to Opportunity.Id
        if (mps.OpportunityID__c != null) {
            mapMpsToOpportunity.put(mps.Id, mps.OpportunityID__c);
        }
    }
    
    if (!mapMpsToOpportunity.isEmpty()) {
        // Query all relevant opportunities to a map with key of Opportunity.Id
        Map<Id, Opportunity> opps = new Map<Id, Opportunity>([select id, MPS_BV__c, MPS_Comment__c, 
                         MPS_Scheduled_Ship_Date__c, MPS_Status__c, CloseDate,
                         Projected_Ship_Date__c, Projected_On_Site_Delivery_Date__c,
                         ForecastCategoryName, Combined_Probability__c
                         from Opportunity where id in:mapMpsToOpportunity.values()]);

        List<Opportunity> oppsToUpdate = new List<Opportunity>();
        Id oppId;
        Opportunity o;
        for (MPS__c s : trigger.new) {
            if (mapMpsToOpportunity.containsKey(s.Id)) {
                // Get the opportunity ID from the map
                oppId = mapMpsToOpportunity.get(s.Id);
                // Get the opportunity based on the opportunity ID
                o = opps.get(oppId);
                // Set fields on MPS based on Opportunity
                s.Forecast_Category__c = o.ForecastCategoryName;
                s.Combined_Probability__c = o.Combined_Probability__c;
                s.Close_Date__c = o.CloseDate;
                s.Projected_Ship_Date__c = o.Projected_Ship_Date__c;
                s.Projected_On_Site_Delivery_Date__c = o.Projected_On_Site_Delivery_Date__c;
                // Set fields on Opportunity based on MPS
                o.MPS_Status__c = s.MPS_Status__c;
                o.MPS_BV__c = s.MPS_BV__c;
                o.MPS_Comment__c = s.MPS_Comment__c;
                o.MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;
                o.MPS__c = s.id;
                oppsToUpdate.add(o);
            }
       } 
        // Update all opportunities in one call
        update oppsToUpdate;
    }
}

 

 

 

I have thought about creating checkboxes to be checked when the a trigger updates a record, and reset the field with a time-based workflow, but I only need to stagger the time a few seconds before the field is reset. Is there any way I can achieve the same thing within the triggers?

 

Thanks,

ckellie

Does anyone know how to change the default starting quote number in an opportunity? We don't want it to read 0000011, we'd like instead to have it default start at 0004139, for instance. This is shown when the PDF is created.

Hello Everyone,

 

I need some  help with a bit of apex code.  I am creating a query list that I need to check to see if it is empty.

 

Here is my code:

if (oldPhoneName != null){
    	 List<Transportation_Services__c> oldRecord = [Select Name, Pickup_Time__c, Client__r.Last_Name__c,  Pickup_Location__r.Name,
        Drop_Off_Location__r.Name, Phone_Name__c, Notes_Transportation__c from Transportation_Services__c 
        WHERE Pickup_Time__c = TODAY AND Phone_Name__c = :oldPhoneName AND Name != :valueTwo Order by Pickup_Time__c];
        if(oldRecord.isEmpty){
        	createXML(record, oldPhoneName, true);
        }else{
        	createXML(oldRecord, oldphoneName, false);
        }
    } 

 

 

Apex does not like my 'records.isEmpty'.  I get this error on compile:  

Save error: Initial term of field expression must be a concrete SObject: LIST<Transportation_Services__c>  

 

Does anyone know of a way that I can check if a SOQL generated list came back with no records (empty)?

 

Thanks.

  • April 21, 2011
  • Like
  • 0

I am working on a trigger that pulls data from the related opportunity to the to the custom object related record (MPS__c). I have yet to pull information from a related record, I have only pushed information to a record, and am wondering whether the trigger is bulkified.

 

I am primarily concerned about the following:

 

 

    trigger.new[0].Forecast_Category__c = o[0].ForecastCategoryName;
    trigger.new[0].Combined_Probability__c = o[0].Combined_Probability__c;
    trigger.new[0].Close_Date__c = o[0].CloseDate;

 

Here is the full trigger:

 

 

trigger MPSUpdate on MPS__c (Before Insert, before update) {

    Set<Id> mIds = new Set<Id>();
    Set<Id> oIds = new Set<Id>();
    
    for(MPS__c mps : trigger.new){
            System.debug('**** 0 mps id : '+ mps.id);
        mIds.add(mps.id);
            System.debug('**** 1 mps id : '+ mps.id);
            System.debug('**** 2 o id : '+ mps.Opportunityid__c);
        oIds.add(mps.OpportunityID__c);
            System.debug('**** 3 o id : '+ mps.Opportunityid__c);   
    }
    
   List<Opportunity> o = [select id, MPS_BV__c, MPS_Comment__c, 
                MPS_Scheduled_Ship_Date__c, MPS_Status__c, CloseDate,
                ForecastCategoryName, Combined_Probability__c
                from Opportunity where id in :oIds];

   List<MPS__c> p = [select id, MPS_BV__c, MPS_Comment__c, MPS_Scheduled_Ship_Date__c, MPS_Status__c,
                Close_Date__c, Combined_Probability__c, Forecast_Category__c
                from MPS__c where id in :mIds];

    trigger.new[0].Forecast_Category__c = o[0].ForecastCategoryName;
    trigger.new[0].Combined_Probability__c = o[0].Combined_Probability__c;
    trigger.new[0].Close_Date__c = o[0].CloseDate;
    
    for(MPS__c s : p){
    
            o[0].MPS_Status__c = s.MPS_Status__c;
            o[0].MPS_BV__c = s.MPS_BV__c;
            o[0].MPS_Comment__c = s.MPS_Comment__c;
            o[0].MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;

       update o;
    }
}

 

This trigger does work, just am wondering whether this is bulkified?

 

Thanks,

ckellie

 

 

Hi,

 

I'd like to make a trigger that would delete a lead record when the lead first name and last name are the same.  Here is what I have so far and I'm getting error message:

 

Apex trigger Test1 caused an unexpected exception, contact your administrator: Test1: execution of BeforeInsert caused by: System.SObjectException: DML statment cannot operate on trigger.new or trigger.old: Trigger.Test1: line 5, column 6

 

What do I need to change?

 

trigger Test1 on Lead (before insert) {
   for(Lead a: Trigger.new){
 if (a.firstname == a.lastname)
 try {
     delete a;
   } catch (DmlException e)
   {}
   }
  }

 

Thanks in advance!

  • April 19, 2011
  • Like
  • 0

I have two apex:relatedLists on a VisualForce page, each with a different account as the subject. When the page is rendered it always renders both relatedLists with the subject of the first relatedList in the source.

 

For example, this code always renders both lists as though their subject is accountOne, even though when you look at the names and Ids that are rendered they are different. If I switch the subject of the first list to accountTwo and the second to accountOne, then they both render the list for accountTwo.

 

Is this a VisualForce bug (or feature?)? Or am I doing something wrong?

 

 

<table cellpadding="0" cellspacing="0">
<tr><td>
<h2 class="mainTitle">Primary: {!accountOne.Name} ({!accountOne.CreatedBy.Name} on {!accountOne.CreatedDate}) [{!accountOne.Id}]</h2>
<apex:relatedList id="list1" list="Financial_Facts__r" subject="{!accountOne}" pageSize="100" />
</td>
<td>
<h2 class="mainTitle">Secondary: {!accountTwo.Name} ({!accountTwo.CreatedBy.Name} on {!accountTwo.CreatedDate}) [{!accountTwo.Id}]</h2>
<apex:relatedList id="list2" list="Financial_Facts__r" subject="{!accountTwo}" pageSize="100" />
</td></tr>
</table>

 

 

We have the following wrapper class:

 

 

public class wrapperClassController {

    //Our collection of the class/wrapper objects cTest__c 
    public List<cProducts> productsList {get; set;}
    
    //This method uses a simple SOQL query to return a List of NRProducts__c
    public List<cProducts> getProducts(){
        if(productsList == null){
            productsList = new List<cProducts>();
        
            for(NRProducts__c c : [select Id, Name, Comments_to_Content_Team__c, Product_Description__c, Feature1__c, Feature2__c, Feature3__c, Feature4__c from NRProducts__c WHERE Feature1__c = null limit 100]){
                /* As each NRProducts__c is processed we create a new cProducts__c object and
                add it to the testProducts */
                productsList.add(new cProducts(c));
            }
        }
        return productsList;
    }
    
    public PageReference processSelected(){
        /*We create a new list of NRProducts__c that will be populated only with NRProducts__c
        if they are selected*/
        List<NRProducts__c> selectedProducts = new List<NRProducts__c>();
        
        /*We will cycle through our list of NRProducts__c and will check to see if the 
        selected property is set to true, if it is we add the NRProducts__c to the 
        selectedNRProducts__c list. */
        for(cProducts cCon : getProducts()){
            if(cCon.selected == true){
                selectedProducts.add(cCon.con);
            }
        }
        
        /* Now we have our list of selected NRProducts__c and can perform any type of 
        logic we want, sending emails, updating a field on the NRProducts__c, etc */

        for(NRProducts__c con : selectedProducts){
            system.debug(con);
update selectedProducts;
        }
        return null;
    }
    
    /* This is our wrapper/container class. A container class is a class, a data 
    structure, or an abstract data type whose instances are collections of other 
    objects. In this example a wrapper class contains both the standard salesforce 
    object NRProducts__c and a Boolean value */
    public class cProducts{
        public NRProducts__c con {get; set;}
        public Boolean selected {get; set;}
        
        /*This is the contructor method. When we create a new cNRProducts__c object we pass a 
        NRProducts__c that is set to the con property. We also set the selected value to false*/
        public cProducts(NRProducts__c c){
            con = c;
            selected = false;
        }
    }
}

 And the following page:

 

 

<apex:page controller="wrapperClassController">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cAccount records -->
            <apex:pageBlockTable value="{!Products}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the account values within our cAccount container/wrapper -->           
                <apex:column value="{!c.con.Name}" />

                         <apex:column headerValue="Feature1">             
                <apex:inputField value="{!c.con.Feature1__c}" />
                      </apex:column>
                         <apex:column headerValue="Feature2">             
                <apex:inputField value="{!c.con.Feature2__c}" />
                      </apex:column>
                         <apex:column headerValue="Feature3">             
                <apex:inputField value="{!c.con.Feature3__c}" />
                      </apex:column>
                          <apex:column headerValue="Feature4">             
                <apex:inputField value="{!c.con.Feature4__c}" />
                      </apex:column>
                 <apex:column value="{!c.con.Comments_to_Content_Team__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Everything works as expected when a field is updated, checkbox is checked, and "Process" button is clicked. Except....the table does not rerended. The result that is expected is that the record with thefield that was updated should no longer be in the list, because the Controller statement is looking for ones with this field == null.

 

Not sure what I am missing?

 

  • April 26, 2011
  • Like
  • 0

Hello.

 

I was wondering if I could get some guidance here.

 

I am setting up a new Visualforce work order input screen and am having issues.  Specifically...

 

1) A Master Object record value (Services_Type__c) is used to name each Work Order record. 

2) This Master Object record also has a corresponding numerical value that represents the duration required for each piece of work (Days_to_Complete__C). 

3) Each VF entry screen is comprised of three work order records.

4) For reasons not relevant to this discussion, I need to compute the largest value of the Days_to_Complete__C value for each three-record group - and place this value in the Longest_Component__C field for each member of the three-record group.

 

My problem is that I am seeing null values in the Longest_Component__C field for all records.  I am pretty sure my problem is that I am not using the getRecord or getParameters command...but I am confused as how to best approach things.

 

Also, I am using a custom controller.

 

Below is the relevant code...thanks in advance for any guidance.

 

LargestValue = 0;
for (Integer x = 0; x < 3; x++)
{
if(myList[x].Services_Type__r.Days_to_Complete__C > LargestValue)
{
LargestValue = myList[x].Services_Type__r.Days_to_Complete__C;
}
myList[x].Longest_Component__C = LargestValue;
}
insert myList; 

 

 

 

Hi all,

 

am new to visual force and am trying to get values from my visual force page for further processing but am getting null values in my controller .

 

Can any one let me know what is the problem??

 

Here is my code snippet.

 

VF page :

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

 

 

<apex:page controller="paginationController">
<apex:form >
    <apex:pageBlock mode="edit" title="Search">
    <script>
    function scriptSearch(){
        //alert(document.getElementById("firstName").value);
        //alert(document.getElementById("lastName").value);
        //alert(document.getElementById("country").options[document.getElementById("country").selectedIndex].value);
        searchCall(document.getElementById("firstName").value,document.getElementById("lastName").value,document.getElementById("country").options[document.getElementById("country").selectedIndex].value);
    }
    </script>
    <apex:actionFunction name="searchCall" action="{!searchFunctionality}">
    <apex:param name="firstname" value="" />
    <apex:param name="lastname" value="" />
    <apex:param name="country" value="" />
    </apex:actionFunction>
        <table>
            <tr>
                <td>First Name : <input type="text" id="firstName"/></td>
                <td>Last Name: <input type="text" id="lastName"/></td>
                <td>
                Country : <select id="country">
                <option value=""></option>
                <apex:repeat value="{!countries}" var="country">
                <option value="{!country}">{!country}</option>
                </apex:repeat>
                </select>
                </td>
                <td><apex:commandButton onclick="scriptSearch();" value="Search"/></td>
            </tr>
       </table>
    </apex:pageBlock>
    
    <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!queryString}" />           
  </apex:pageBlock> 
  
</apex:form>
</apex:page>

 

 

Controler :

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

 

 

public class paginationController {

 

public string queryString{get;set;}

 

public List<SampleObject001__c> userDetails{get;set;}

 

public paginationController(){

 queryString='Select First_Name__c,Last_Name__c,Country__c From SampleObject001__c';

 executeQuery();

}

public List<String> countries {

    get {

      if (countries == null) {

 

        countries = new List<String>();

        Schema.DescribeFieldResult field = SampleObject001__c.Country__c.getDescribe();

 

        for (Schema.PicklistEntry f : field.getPicklistValues())

          countries.add(f.getLabel());

 

      }

      return countries;          

    }

    set;

  }

 

 public PageReference searchFunctionality(){

 

  String firstName = Apexpages.currentPage().getParameters().get('firstname');

    String lastName = Apexpages.currentPage().getParameters().get('lastname');

    String country = Apexpages.currentPage().getParameters().get('country');

 

    system.debug('-----firstName-------'+firstName);

    system.debug('-----lastName-------'+lastName);

    system.debug('-----country-------'+country);

 

    if(firstName!=null && !firstName.equals('')){

     queryString+='and First_Name__c LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';

    }

    if(lastName!=null && !lastName.equals('')){

     queryString+='and Last_Name__c LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';

    }

    if(country!=null && !country.equals('')){

     queryString += ' and Country__c includes (\''+country+'\')';

    }

 

    executeQuery();

  return null;

 }

 

 public void executeQuery(){

  try{

  system.debug('-----QUERY-------'+queryString);

  userDetails= Database.query(queryString);

  }catch(Exception e){

 

  }

 }

}

 

 

 

please help me to resolve this issue.

 

  • April 22, 2011
  • Like
  • 0

Hi everyone,

 

I'll use the HTTP Request object to POST data to an HTTPS endpoint.

Please let me know if you have some important points.

 

Thanks,

Seiji

I am working on an application where the user will create a custom object (mps) record from the opportunity and a trigger will update certain fields on the mps from the opportunity.When there is an MPS record attached to the opportunity, the opportunity will update the mps, and when the mps is updated, the opportunity is updated. This has created an error that says "...cannot recursively update itself..." I am trying to find a way to prevent this. The problem is I cannot the find a way to break this recursion.

 

I wannt both records to be updated when one record is updated. Below are my triggers:

 

 

trigger OppUpdateMPS on Opportunity (before update) {
       Map<Id, Id> mapOpportunitytoMPS = new Map<Id, Id>();

    for(Opportunity o : trigger.new){
        // Populate map of Opportunity.Id to MPS.Id
        if (o.MPS__c != null) {
            mapOpportunitytoMPS.put(o.Id, o.mps__c);
        }
    }

    if (!mapOpportunitytoMPS.isEmpty()) {
        // Query all relevant opportunities to a map with key of Opportunity.Id
        Map<Id, MPS__c> mps = new Map<Id,MPS__c>([select id, MPS_BV__c, MPS_Comment__c, 
                         MPS_Scheduled_Ship_Date__c, MPS_Status__c, Close_Date__c, LastModifiedDate,
                         Projected_Ship_Date__c, Projected_On_Site_Delivery_Date__c,
                         Forecast_Category__c, Combined_Probability__c, Recursive_Update__c
                         from MPS__c where id in:mapOpportunitytoMPS.values()]);

        List<MPS__c> mpsToUpdate = new List<MPS__c>();
        Id mpsId;
        MPS__c m;

        for (Opportunity s : trigger.new) {
            if (mapOpportunitytoMPS.containsKey(s.Id)) {
                // Get the MPS__c ID from the map
                mpsId = mapOpportunitytoMPS.get(s.Id);
                // Get the opportunity based on the opportunity ID
                m = mps.get(mpsId);
                // Set fields on MPS based on Opportunity
                m.Forecast_Category__c = s.ForecastCategoryName;
                m.Combined_Probability__c = s.Combined_Probability__c;
                m.Close_Date__c = s.CloseDate;
                m.Projected_Ship_Date__c = s.Projected_Ship_Date__c;
                m.Projected_On_Site_Delivery_Date__c = s.Projected_On_Site_Delivery_Date__c ;
                m.MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;
                MPSToUpdate.add(m);
            }
        }

        // Update all MPS__c in one call
        update MPSToUpdate;
        
    }
}

 

trigger MPSUpdate on MPS__c (Before Insert, Before Update) {
    Map<Id, Id> mapMpsToOpportunity = new Map<Id, Id>();
     
    for(MPS__c mps : trigger.new){
        // Populate map of MPS.Id to Opportunity.Id
        if (mps.OpportunityID__c != null) {
            mapMpsToOpportunity.put(mps.Id, mps.OpportunityID__c);
        }
    }
    
    if (!mapMpsToOpportunity.isEmpty()) {
        // Query all relevant opportunities to a map with key of Opportunity.Id
        Map<Id, Opportunity> opps = new Map<Id, Opportunity>([select id, MPS_BV__c, MPS_Comment__c, 
                         MPS_Scheduled_Ship_Date__c, MPS_Status__c, CloseDate,
                         Projected_Ship_Date__c, Projected_On_Site_Delivery_Date__c,
                         ForecastCategoryName, Combined_Probability__c
                         from Opportunity where id in:mapMpsToOpportunity.values()]);

        List<Opportunity> oppsToUpdate = new List<Opportunity>();
        Id oppId;
        Opportunity o;
        for (MPS__c s : trigger.new) {
            if (mapMpsToOpportunity.containsKey(s.Id)) {
                // Get the opportunity ID from the map
                oppId = mapMpsToOpportunity.get(s.Id);
                // Get the opportunity based on the opportunity ID
                o = opps.get(oppId);
                // Set fields on MPS based on Opportunity
                s.Forecast_Category__c = o.ForecastCategoryName;
                s.Combined_Probability__c = o.Combined_Probability__c;
                s.Close_Date__c = o.CloseDate;
                s.Projected_Ship_Date__c = o.Projected_Ship_Date__c;
                s.Projected_On_Site_Delivery_Date__c = o.Projected_On_Site_Delivery_Date__c;
                // Set fields on Opportunity based on MPS
                o.MPS_Status__c = s.MPS_Status__c;
                o.MPS_BV__c = s.MPS_BV__c;
                o.MPS_Comment__c = s.MPS_Comment__c;
                o.MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;
                o.MPS__c = s.id;
                oppsToUpdate.add(o);
            }
       } 
        // Update all opportunities in one call
        update oppsToUpdate;
    }
}

 

 

 

I have thought about creating checkboxes to be checked when the a trigger updates a record, and reset the field with a time-based workflow, but I only need to stagger the time a few seconds before the field is reset. Is there any way I can achieve the same thing within the triggers?

 

Thanks,

ckellie

Does anyone know how to change the default starting quote number in an opportunity? We don't want it to read 0000011, we'd like instead to have it default start at 0004139, for instance. This is shown when the PDF is created.

Hello Everyone,

 

I need some  help with a bit of apex code.  I am creating a query list that I need to check to see if it is empty.

 

Here is my code:

if (oldPhoneName != null){
    	 List<Transportation_Services__c> oldRecord = [Select Name, Pickup_Time__c, Client__r.Last_Name__c,  Pickup_Location__r.Name,
        Drop_Off_Location__r.Name, Phone_Name__c, Notes_Transportation__c from Transportation_Services__c 
        WHERE Pickup_Time__c = TODAY AND Phone_Name__c = :oldPhoneName AND Name != :valueTwo Order by Pickup_Time__c];
        if(oldRecord.isEmpty){
        	createXML(record, oldPhoneName, true);
        }else{
        	createXML(oldRecord, oldphoneName, false);
        }
    } 

 

 

Apex does not like my 'records.isEmpty'.  I get this error on compile:  

Save error: Initial term of field expression must be a concrete SObject: LIST<Transportation_Services__c>  

 

Does anyone know of a way that I can check if a SOQL generated list came back with no records (empty)?

 

Thanks.

  • April 21, 2011
  • Like
  • 0

Hi Guys,

       Iam trying to update parent campaign based on record type it's working fine when i create a new one but when iam trying to change the record type for existing campaign the parent campaign doesn't gets updated, iam kinda new to this coding, any help is appreciated, here is my trigger

 

trigger ParentCampaign on Campaign (after insert) {
String CampaignID =Trigger.new[0].Id;
Campaign Cmp=[select id, RecordTypeID,ParentID from Campaign where id =:CampaignID];
If (Cmp.RecordTypeID =='012400000004v8d'){
Cmp.ParentID='701Q0000000Cxq2';
}
else if
(Cmp.RecordTypeID =='012300000004svr'){
Cmp.ParentID='701Q0000000CxqM';
}
else if
(Cmp.RecordTypeID =='012300000004svw'){
Cmp.ParentID='701Q0000000CxqR';
}
else if
(Cmp.RecordTypeID =='012300000004sw1'){
Cmp.ParentID='701Q0000000CxqW';
}
else if
(Cmp.RecordTypeID =='01240000000M32w'){
Cmp.ParentID='701Q0000000Cxqb';
}
else if
(Cmp.RecordTypeID =='012400000004umS'){
Cmp.ParentID='701Q0000000Cxqg';
}
Update cmp;
}

 

So i'm trying to validate an apex form that submits via an ajax call. The form validation is being applied, however the form is still being submitted. It looks like the following:

 

 

<apex:form styleClass="createCaseForm" id="createCaseForm">
   <!--Form Elements-->

    <apex:commandLink rerender="status" action="{!submitCase}" styleClass="createCaseButton">
       <input type="image" value="Submit" src="..."/>
    </apex:commandLink>
</apex:form>

 Then the jquery that handles the validation looks like this:

 

 

$(document).ready(function(){
   $(".createCaseButton").click(function(event){
		if(mustCheck) {
			// Prevent submit if validation fails
			if( !checkForm($(".createCaseForm")) ) {
				event.preventDefault();
			};
		} else {
			mustCheck = !mustCheck;
		}
	});
});

 

Any idea how to prevent the form from being submitted when the validation fails?

 

 

  • April 21, 2011
  • Like
  • 0

In an apex custom controller, is there a way to determine the current user's sharing access for a custom object record?

Example:

//Standard building of a custom select list
List<SelectOption> theList = new List<SelectOption>{};

List<CustomObject__c> items = Database.query(query);
                        for(CustomObject__c i : items){
                                theList.add(new SelectOption(i.id, i.name));
                        }

 



//What I would like to do
List<SelectOption> theList = new List<SelectOption>{};

List<CustomObject__c> items = Database.query(query);
                        for(CustomObject__c i : items){
                               
                               //determine user sharing rights on record
                               boolean optionDisabled = false;
                               string?? userAccess = i.methodThatReturnsCurrentSharingAccess;
                               if(userAccess != 'read/write'){
                                         optionDisabled = true;
                               }
                                theList.add(new SelectOption(i.id, i.name, optionDisabled));
                        }

 



I understand that I would probably need to get the current user object using the global and pass that to whatever method determines the sharing access. Unless the user object has the method and I pass it the record object. I will look into that while I wait for a reply.

 

 

Mike

I am working on a trigger that pulls data from the related opportunity to the to the custom object related record (MPS__c). I have yet to pull information from a related record, I have only pushed information to a record, and am wondering whether the trigger is bulkified.

 

I am primarily concerned about the following:

 

 

    trigger.new[0].Forecast_Category__c = o[0].ForecastCategoryName;
    trigger.new[0].Combined_Probability__c = o[0].Combined_Probability__c;
    trigger.new[0].Close_Date__c = o[0].CloseDate;

 

Here is the full trigger:

 

 

trigger MPSUpdate on MPS__c (Before Insert, before update) {

    Set<Id> mIds = new Set<Id>();
    Set<Id> oIds = new Set<Id>();
    
    for(MPS__c mps : trigger.new){
            System.debug('**** 0 mps id : '+ mps.id);
        mIds.add(mps.id);
            System.debug('**** 1 mps id : '+ mps.id);
            System.debug('**** 2 o id : '+ mps.Opportunityid__c);
        oIds.add(mps.OpportunityID__c);
            System.debug('**** 3 o id : '+ mps.Opportunityid__c);   
    }
    
   List<Opportunity> o = [select id, MPS_BV__c, MPS_Comment__c, 
                MPS_Scheduled_Ship_Date__c, MPS_Status__c, CloseDate,
                ForecastCategoryName, Combined_Probability__c
                from Opportunity where id in :oIds];

   List<MPS__c> p = [select id, MPS_BV__c, MPS_Comment__c, MPS_Scheduled_Ship_Date__c, MPS_Status__c,
                Close_Date__c, Combined_Probability__c, Forecast_Category__c
                from MPS__c where id in :mIds];

    trigger.new[0].Forecast_Category__c = o[0].ForecastCategoryName;
    trigger.new[0].Combined_Probability__c = o[0].Combined_Probability__c;
    trigger.new[0].Close_Date__c = o[0].CloseDate;
    
    for(MPS__c s : p){
    
            o[0].MPS_Status__c = s.MPS_Status__c;
            o[0].MPS_BV__c = s.MPS_BV__c;
            o[0].MPS_Comment__c = s.MPS_Comment__c;
            o[0].MPS_Scheduled_Ship_Date__c = s.MPS_Scheduled_Ship_Date__c;

       update o;
    }
}

 

This trigger does work, just am wondering whether this is bulkified?

 

Thanks,

ckellie

 

 

I am working with an export method that requires "flattening" of data, so my schema of children objects has a field "exportSequence" which is just an integer ordered by date.

 

I have triggers to update that order when a new child record is made, or deleted. but I just found out today that if contacts are merged, then the children record triggers do not fire. (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_merge_statements.htm)

 

I need a suggestion as to how to make the children object triggers fire (without looping) to reorder themselves based on the contact they're attached to.

 

Note: There are 5 objects all children to Contact, and I'm hoping to not have the global "reorder everything" trigger on the contact, that will reorder all five children objects when I only need to do one or two.

 

Thanks,

ScriptMonkey

Setting the checked attribute in a dynamic way doesn't seem possible.

As per html spec, checked="checked", checked = "junk", checked="" all lead to a checked radio button. Just the presence of attribute is enough.

 

So it leads to following problems. I guess the workaround would be in Javascript?

 

 

 

//sfdc is smart enought to removes checked attribute in the rendered html because it is empty
<input type="radio" name="r1" value="Bike" checked="" />

//SFDC renders checked="" in html, hence button is checked. SFDC should get rid attribute as it does above
 <input type="radio" name="r1" value="Bike" checked="{IF(false,'checked' ,'')}" />

//So try to get rid of the attribute itself dynamically. However SFDC does not allow the next two syntax in API 19.0 with complile time error - Element type "input" should be followed by either attribute specifications, ">" or "/>". Seems like it wants attribute=value syntax. It allows it at compile time in 16.0, but end users get the same message at run time, which is not acceptable.
 <input type="radio" name="r1" value="Bike" {!IF(false,'checked' ,'')} />
<input type="radio" name="r1" value="Bike" {!IF(false,'checked=\"checked\"','')} />

 

 

 

 

 

 

I have two apex:relatedLists on a VisualForce page, each with a different account as the subject. When the page is rendered it always renders both relatedLists with the subject of the first relatedList in the source.

 

For example, this code always renders both lists as though their subject is accountOne, even though when you look at the names and Ids that are rendered they are different. If I switch the subject of the first list to accountTwo and the second to accountOne, then they both render the list for accountTwo.

 

Is this a VisualForce bug (or feature?)? Or am I doing something wrong?

 

 

<table cellpadding="0" cellspacing="0">
<tr><td>
<h2 class="mainTitle">Primary: {!accountOne.Name} ({!accountOne.CreatedBy.Name} on {!accountOne.CreatedDate}) [{!accountOne.Id}]</h2>
<apex:relatedList id="list1" list="Financial_Facts__r" subject="{!accountOne}" pageSize="100" />
</td>
<td>
<h2 class="mainTitle">Secondary: {!accountTwo.Name} ({!accountTwo.CreatedBy.Name} on {!accountTwo.CreatedDate}) [{!accountTwo.Id}]</h2>
<apex:relatedList id="list2" list="Financial_Facts__r" subject="{!accountTwo}" pageSize="100" />
</td></tr>
</table>