• SeAlVa_VFTabulator
  • NEWBIE
  • 80 Points
  • Member since 2011

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

Hello

 

Is it possible for me to use a query like Date()-7 for a certain date/time field so the query returns values for the last 7 days?

 

Something like : 

 

select Id, OwnerId, dtDateDelivered__c from Service__c where dtDateDelivered__c < "TODAY()-7" ORDER BY dtDateDelivered__c LIMIT 10

 

Which doesn't work :)

 

 

I'm trying to reduce the number of DML statements in some code. At the moment I'm looping over some logic to create a set of records to create in a custom object, then inserting the set of records. But then I'm looping over the inserted records to create some child records.

 

My question is, it is possible to create a set of the master object record and child object records and insert them using one DML?

  • February 14, 2012
  • Like
  • 0

Hi

 

Am getting the following error while creating APEX Trigger

 

Error: Compile Error: sObject type 'Line_Item__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 3 column 1

Apex Trigger Subject :

 

trigger HandleProductPriceChange on Merchandise__c (after update) {

List<Line_Item__c> openLineItems =

[SELECT j.Unit_Price__c, j.Merchandise__r.Price__c

FROM Line_Item__c j

WHERE j.Invoice_Statement__r.Status__c = 'Negotiating'

AND j.Merchandise__r.id IN :Trigger.new

FOR UPDATE];

for (Line_Item__c li: openLineItems) {

if ( li.Merchandise__r.Price__c < li.Unit_Price__c ){

li.Unit_Price__c = li.Merchandise__r.Price__c;

}

}

update openLineItems;

}

 

regards

 

Jerome John

 

trigger calculate on Item__c (after insert, after update, after delete) {

// Use a map because it doesn't allow duplicate values 
    

Map<ID, Shipping_Invoice__C> updateMap = new Map<ID, Shipping_Invoice__C>();

// Set this integer to -1 if we are deleting 
    
Integer subtract ;

// Populate the list of items based on trigger type 
    
List<Item__c> itemList;
    if(trigger.isInsert || trigger.isUpdate){
        itemList = Trigger.new;
        subtract = 1;
    }
    else if(trigger.isDelete)
    {
        // Note -- there is no trigger.new in delete 
    
        itemList = trigger.old;
        subtract = -1;
    }

// Access all the information we need in a single query  
    
// rather than querying when we need it. 
    
// This is a best practice for bulkifying requests 
    

set<Id> AllItems = new set<id>();

for(item__c i :itemList){
// Assert numbers are not negative.   
    
// None of the fields would make sense with a negative value 
    

System.assert(i.quantity__c > 0, 'Quantity must be positive');
System.assert(i.weight__c >= 0, 'Weight must be non-negative');
System.assert(i.price__c >= 0, 'Price must be non-negative');

// If there is a duplicate Id, it won't get added to a set 
    
AllItems.add(i.Shipping_Invoice__C);
}

// Accessing all shipping invoices associated with the items in the trigger 
    
List<Shipping_Invoice__C> AllShippingInvoices = [SELECT Id, ShippingDiscount__c, 
                   SubTotal__c, TotalWeight__c, Tax__c, GrandTotal__c 
                   FROM Shipping_Invoice__C WHERE Id IN :AllItems];
                   
// Take the list we just populated and put it into a Map.   
    
// This will make it easier to look up a shipping invoice 
    
// because you must iterate a list, but you can use lookup for a map,  
    
Map<ID, Shipping_Invoice__C> SIMap = new Map<ID, Shipping_Invoice__C>();

for(Shipping_Invoice__C sc : AllShippingInvoices)
{
    SIMap.put(sc.id, sc);
}

// Process the list of items 
    
    if(Trigger.isUpdate)
    {
        // Treat updates like a removal of the old item and addition of the          
    
        // revised item rather than figuring out the differences of each field  
    
        // and acting accordingly. 
    
        // Note updates have both trigger.new and trigger.old 
    
        for(Integer x = 0; x < Trigger.old.size(); x++)
        {
            Shipping_Invoice__C myOrder;
            myOrder = SIMap.get(trigger.old[x].Shipping_Invoice__C);

            // Decrement the previous value from the subtotal and weight. 
    
            myOrder.SubTotal__c -= (trigger.old[x].price__c * 
                                    trigger.old[x].quantity__c);
            myOrder.TotalWeight__c -= (trigger.old[x].weight__c * 
                                       trigger.old[x].quantity__c);
                
            // Increment the new subtotal and weight. 
    
            myOrder.SubTotal__c += (trigger.new[x].price__c * 
                                    trigger.new[x].quantity__c);
            myOrder.TotalWeight__c += (trigger.new[x].weight__c * 
                                       trigger.new[x].quantity__c);
        }
        
        for(Shipping_Invoice__C myOrder : AllShippingInvoices)
        {
            
            // Set tax rate to 9.25%  Please note, this is a simple example.   
    
            // Generally, you would never hard code values. 
    
            // Leveraging Custom Settings for tax rates is a best practice.   
    
            // See Custom Settings in the Apex Developer's guide  
    
            // for more information. 
    
            myOrder.Tax__c = myOrder.Subtotal__c * .0925;
            
            // Reset the shipping discount 
    
            myOrder.ShippingDiscount__c = 0;
    
            // Set shipping rate to 75 cents per pound.   
    
            // Generally, you would never hard code values. 
    
            // Leveraging Custom Settings for the shipping rate is a best practice. 
    
            // See Custom Settings in the Apex Developer's guide  
    
            // for more information. 
    
            myOrder.Shipping__c = (myOrder.totalWeight__c * .75);
            myOrder.GrandTotal__c = myOrder.SubTotal__c + myOrder.tax__c + 
                                    myOrder.Shipping__c;
            updateMap.put(myOrder.id, myOrder);
         }
    }
    else
    { 
        for(Item__c itemToProcess : itemList)
        {
            Shipping_Invoice__C myOrder;
    
            // Look up the correct shipping invoice from the ones we got earlier 
    
            myOrder = SIMap.get(itemToProcess.Shipping_Invoice__C);
            myOrder.SubTotal__c += (itemToProcess.price__c * 
                                    itemToProcess.quantity__c * subtract);
            myOrder.TotalWeight__c += (itemToProcess.weight__c * 
                                       itemToProcess.quantity__c * subtract);
        }
        
        for(Shipping_Invoice__C myOrder : AllShippingInvoices)
        {
            
             // Set tax rate to 9.25%  Please note, this is a simple example.   
    
             // Generally, you would never hard code values. 
    
             // Leveraging Custom Settings for tax rates is a best practice.   
    
             // See Custom Settings in the Apex Developer's guide  
    
             // for more information. 
    
             myOrder.Tax__c = myOrder.Subtotal__c * .0925;
             
             // Reset shipping discount 
    
             myOrder.ShippingDiscount__c = 0;
    
            // Set shipping rate to 75 cents per pound.   
    
            // Generally, you would never hard code values. 
    
            // Leveraging Custom Settings for the shipping rate is a best practice. 
    
            // See Custom Settings in the Apex Developer's guide  
    
            // for more information. 
    
            myOrder.Shipping__c = (myOrder.totalWeight__c * .75);
            myOrder.GrandTotal__c = myOrder.SubTotal__c + myOrder.tax__c + 
                                    myOrder.Shipping__c;
                                       
            updateMap.put(myOrder.id, myOrder);
    
         }
     }    
     
     // Only use one DML update at the end. 
    
     // This minimizes the number of DML requests generated from this trigger. 
    
     update updateMap.values();
}

 Can anybody say what he was doing there....am not able to know he is dng with 'Allitems'

That is the example in documentation under appendices......shipping invoice example.....please help me with that....am not to understnad that. I want to know how he is approaching to write that trigger.

  • February 17, 2012
  • Like
  • 0

On a visualForce page, I'm showing a list of records belonging to the user as well as a list of records that haven't been claimed as of yet.  On the first page, I'm identifying the user by the id in the URL.  When they claim a record, I am passing them to a page that shows the record details and a confirmation button.  

 

When I get to that second page, I'm losing the connection to the user and I'm not sure how to pass that over to the second page.  

 

Here is the controller code:  

 

public list<Lead> getLeads2beClaimed() {
    	
leads2beClaimed = [SELECT id, FirstName, LastName, Phone, Email, Street, City, State, PostalCode, Country,Company,                        claimant__c, Claimant__c.Id, Status, Lead_Number__c, Claimant.email, LeadSource, Job_Role__c 
FROM Lead WHERE Claimaint__c = NULL];

return leads2beClaimed; 
    
  }
    
public pageReference slctLead2beClaimed(){
        l2bclaimed = [SELECT id, Name, Claimant__c, Claimant__r.Email
                FROM Lead WHERE id = :ApexPages.currentPage().getParameters().get('claimID')];

        l2bclaimed.Claimant__c = claimUser.id;
 
        update l2bclaimed;
        pageReference updtdLead = new pageReference('/apex/claimLeads?id='+claimUser.id);
        updtdLead.setRedirect(true);
    return updtdLead;
   }
  

 Thethis is the VF code I"m using to select the lead and pass them to the confirmation page: 

<apex:form >
<apex:pageBlock title="Leads to be Claimed">
    <apex:pageBlockTable value="{!l2bclaimed}" var="st" rows="10" width="500px" > 
        <apex:column headerValue="Company" >
            <apex:outputField value="{!st.Company}"/> 
        </apex:column>
        <apex:column headerValue="City" >
            <apex:outputField value="{!st.City}"/> 
        </apex:column>
        <apex:column headerValue="State" >
            <apex:outputField value="{!st.State}"/> 
        </apex:column>        
        <apex:column headerValue="Job Role" >
            <apex:outputField value="{!st.Job_Role__c}"/> 
         </apex:column>        
		 <apex:column headerValue="Select (up to 5/day)">
		 	<a href="/apex/claimLeads?id={!st.Claimant__r.email}&claimId?={!st.id}">Select</a>
        </apex:column> 
     </apex:pageBlockTable>
</apex:pageBlock>
</apex:form>

 

I'm getting the following error after clicking the select button on the Claim Leads page.  When I look at the URL for the ClaimLeads page, the email address is not being passed through on the URL.  I'm not sure how to pass it through when selecting the lead.  

 

System.NullPointerException: Attempt to de-reference a null object

 

Class.partnerView.slctLead2beClaimed: line 111, column 1     

 

 

The other thing I should note is that I orignally had this set to not go to the confirmation page but in stead to automatically be connected to the user and to show in a list of claimed leads on the same page - however - the <apex:commandLInk> I had to select the leads was taking the first lead in the list as opposed to the lead actually being selected.  I would rather not have the iterim step, but am unsure how to pass the id of the lead in the list through to the controller so it's the one being updated instead of the first one on the list.  

 

Thank you for your help.  

 

JoAnn

I'm getting this error when I try to update a contact record:

 

Review all error messages below to correct your data.
Apex trigger ContactStageTrigger caused an unexpected exception, contact your administrator: ContactStageTrigger: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.ContactStageTrigger: line 6, column 1

 

Here is my Code:

 

trigger ContactStageTrigger on Contact (after insert, after update) {

    Contact myContact = trigger.new[0];
    Account myAccount = [SELECT OwnerId FROM Account WHERE Id = :myContact.AccountId];
    if(myContact.Status__c == 'Prospect'){
        myContact.OwnerId = myAccount.OwnerId;
        update myContact;
    }
 }

 


Hi , 

My requirement is , i need to dispaly the current time, and depending on the current time 

i should be able to add 30 min , 1 hour , 2 hours to the current time and disaplay them in 

a dropdown ,

 

for eaxmple:

if the current time is 9:00 in the drop down i should be able to dispaly 

9:30 and 10:00 and 11:00 so on and it should alter depending upon the current itme

could anyone could help me with an example how would i achieve this

 

Thank You

Hello

 

Is it possible for me to use a query like Date()-7 for a certain date/time field so the query returns values for the last 7 days?

 

Something like : 

 

select Id, OwnerId, dtDateDelivered__c from Service__c where dtDateDelivered__c < "TODAY()-7" ORDER BY dtDateDelivered__c LIMIT 10

 

Which doesn't work :)

 

 

Hi All,

I have a custom object and which having two master deatils relation ship with diffent object. So now when i go to OWD setting i found that for this object default setting is Controller by Parent. I want to know in this case it will conside which object as Parent?????????

I'm trying to reduce the number of DML statements in some code. At the moment I'm looping over some logic to create a set of records to create in a custom object, then inserting the set of records. But then I'm looping over the inserted records to create some child records.

 

My question is, it is possible to create a set of the master object record and child object records and insert them using one DML?

  • February 14, 2012
  • Like
  • 0

Hi

 

Am getting the following error while creating APEX Trigger

 

Error: Compile Error: sObject type 'Line_Item__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 3 column 1

Apex Trigger Subject :

 

trigger HandleProductPriceChange on Merchandise__c (after update) {

List<Line_Item__c> openLineItems =

[SELECT j.Unit_Price__c, j.Merchandise__r.Price__c

FROM Line_Item__c j

WHERE j.Invoice_Statement__r.Status__c = 'Negotiating'

AND j.Merchandise__r.id IN :Trigger.new

FOR UPDATE];

for (Line_Item__c li: openLineItems) {

if ( li.Merchandise__r.Price__c < li.Unit_Price__c ){

li.Unit_Price__c = li.Merchandise__r.Price__c;

}

}

update openLineItems;

}

 

regards

 

Jerome John