• k
  • NEWBIE
  • 30 Points
  • Member since 2013
  • Senior Consultent

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
I am fairly new with apex triggers, and I have written a basic trigger to create a Vendor Details page when the account type = Vendor.  The problem is I only want it to do this once, and if someone were to change the type to something else, and back to Vendor, it creates the page again.

here is my trigger so far:

trigger AutoCreateVendorDet on Account (after update) {
for (Account a : Trigger.new) {
    if (a.Type__c == 'Vendor') {
        // Create a new Vendor Details Page
        Vendor_Details__c v = new Vendor_Details__c();
            v.Name = 'Vendor Information';
            v.Account__c = a.Id;
            insert v;
            }
    }
}
Hi,

Forgive me if I do not give enough information, I am passing on an issue from our developer.

Our organisation have a web portal that we use to link with Salesforce. 

We are working on an invoice submission tool (which is in place already) and I wanted to add an extra field to be included. I created this field and the developer tried to 'add it' to the portal. However, when performing a query, when the results are returned the field that I added does not appear in the result set.

Could anyone help?

Thank you
My requirement is to display records of a child's child's records in the parent (Account). I am able to do this via Apex, SOQL and Visualforce for output, but the problem I am running into is being able to filter out records that don't pertain to the current account (outputted via Visualforce inside the Account page layout. It currently returns all records). How can I filter out to only show the records of the child's child that pertain to the Account?

The account Id in the SOQL statement is "Current_Product__r.Current_Services__r.Account__r.Id"

Class:
public class PEQueryController{
    private final Account acct;
    public PEQueryController(ApexPages.StandardController stdController){
        this.acct = (Account)stdController.getRecord();
    }
    public List<Price_Exception__c> getRelatedPEs(){
        List<Price_Exception__c> pequery = [Select Name, Proposed_Oil_Rate__c, Proposed_Price_Ranking__c, Price_Exception_Reason__c, Approval_Status__c, Current_Product__r.Current_Services__r.Account__r.Id From Price_Exception__c];
        return pequery;
    }
}
Visualforce page:
<apex:page standardController="Account" extensions="PEQueryController" >
    <apex:pageBlock>
        <apex:pageBlockTable value="{!RelatedPEs}" var="pe">
            <apex:column>
                <apex:pageBlockTable value="{!pe.Name}" var="peName">        
                    <apex:column headerValue="Price Exception Name">
                        <apex:outputField value="{!pe.Name}"/>
                    </apex:column>
                    <apex:column headerValue="Proposed Price Ranking">
                        <apex:outputField value="{!pe.Proposed_Price_Ranking__c}"/>
                    </apex:column>
                    <apex:column headerValue="Proposed Oil Rate">
                        <apex:outputField value="{!pe.Proposed_Oil_Rate__c}"/>
                    </apex:column>
                    <apex:column headerValue="Price Exception Reason">
                        <apex:outputField value="{!pe.Price_Exception_Reason__c}"/>
                    </apex:column>
                    <apex:column headerValue="Approval Status">
                        <apex:outputField value="{!pe.Approval_Status__c}"/>
                    </apex:column>
                    <apex:column headerValue="Account.Id">
                        <apex:outputField value="{!pe.Current_Product__r.Current_Services__r.Account__r.Id}"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:column>		
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

Hello,

I've created the trigger below on my OpportunityLineItem object.  There is a custom field on the Opportunity object called Max_Deliv_Hx__c which captures the highest number of Opportunity Products that have been included on an Opportunity.  I am trying to assign a value to each OpportunityLineItem from 1 to Max_Deliv_Hx__c, but only if that OpportunityLineItem does not already have a value.  When I run this trigger I get and error:

Error: Invalid Data.
Apex trigger UniqueDelivID caused an unexpected exception, contact your administrator: UniqueDelivID: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00kn00000032bk8AAA; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00kn00000032bk8) is currently in trigger UniqueDelivID, therefore it cannot recursively update itself: []: Trigger.UniqueDelivID: line 18, column 1


Can anyone provide some help?  Thanks.


trigger UniqueDelivID on OpportunityLineItem (before insert, before update) {

    //get the Product Numbers and other fields from the OpportunityLineItem and build a list of OpportunityLineItems to update

    List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();

        for(OpportunityLineItem oli : [SELECT Id, Opportunity.Max_Deliv_Hx__c, Max_Deliv__c
                                       FROM OpportunityLineItem
                                       WHERE Id in : trigger.new]) {

        IF(oli.Max_Deliv__c = null){
            oli.Max_Deliv__c = oli.Opportunity.Max_Deliv_Hx__c + 1; //Update the OpportunityLineItem
        }
        oliList.add(oli);

    }

    update oliList; //Update the OpportunityLineItems with the Max_Deliv__c field

}
  • June 05, 2014
  • Like
  • 0
I am fairly new with apex triggers, and I have written a basic trigger to create a Vendor Details page when the account type = Vendor.  The problem is I only want it to do this once, and if someone were to change the type to something else, and back to Vendor, it creates the page again.

here is my trigger so far:

trigger AutoCreateVendorDet on Account (after update) {
for (Account a : Trigger.new) {
    if (a.Type__c == 'Vendor') {
        // Create a new Vendor Details Page
        Vendor_Details__c v = new Vendor_Details__c();
            v.Name = 'Vendor Information';
            v.Account__c = a.Id;
            insert v;
            }
    }
}
Hi Community,

Below is the sample code
List<User> salesOffice = [Select id, Sales_Office__c, profile.Name from User  where Sales_Office__c != null];

for(User usr: salesOffice){

this.pickList.add(new salesOffice(usr.Sales_Office__c, usr.Sales_Office__c));

}
From the above process I am getting the duplicate values in the picklist and displaying in the alphabetical order. 

Any Ideas please.

Thanks,
Suresh.

I am getting this error for a scheduled job that sends mass emails every day.

First error: SendEmail failed. First exception on row 0; first error: LIMIT_EXCEEDED, Too many target object ids.: []

Here is the code:

global with sharing class EmailSenderBatch implements Database.Batchable<SObject>, Database.Stateful 
{
    public String query = '';
    global Set<ID> contactIDsToSendEmailTo;
    
    public EmailSenderBatch()
    {
        query = 'Select ID, Name from Account';
        contactIDsToSendEmailTo = new Set<ID>();
    }   
    
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, list<sObject> scope)
    {
        Set<ID> accountIDs = new Set<ID>();
        for(Account a: (List<Account>) scope)
            accountIDs.add(a.ID);
        
        Set<ID> accountIdsToSendEmailTo = new Set<ID>();
        for(Contract ctrct: [Select ID, AccountID, Subscription_Start_Date__c
                             from Contract 
                             where AccountID in: accountIDs
                             and Contract_Status__c =: 'Active'
                             and Subscription_Start_Date__c !=: null])
        {
        //send every 3 months and 9 months from subscription start date
            if(
            ((ctrct.Subscription_Start_Date__c.addMonths(3).month() == (Date.today().month()))
            || (ctrct.Subscription_Start_Date__c.addMonths(9).month() == (Date.today().month())))
            )
            {
                accountIDsToSendEmailTo.add(ctrct.AccountID);
            }
        }
        
        //if we have qualified accounts
        if(accountIDsToSendEmailTo.size() > 0)
        {
            for(Contact c: [Select ID, LastName, FirstName, Key_Contact__c
                            from Contact
                            where AccountID in: accountIdsToSendEmailTo
                            and Contact_Status__c =: Constants.STATUS_ACTIVE
                            ])
            {
                if(c.Key_Contact__c != null && c.Key_Contact__c.contains(Constants.CONTACTOBJ_PRIMARY_SUPPORT_CONTACT))
                    contactIDsToSendEmailTo.add(c.ID);
            }
        }
    }
    
    global void finish(Database.BatchableContext BC)
    {
        if(contactIDsToSendEmailTo.size() > 0)
        {
            List<ID> contactIDs = new List<ID>();
            contactIDs.addAll(contactIDsToSendEmailTo);
            Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
            mail.setSenderDisplayName('Andrew Simpson');
            mail.setTargetObjectIds(contactIDs);
            mail.setTemplateId(GenericServices.getGeneralSettingValueForKey(Constants.TEMPLATE_ID));
            Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
        }
    }
    
    global static void startCalculation()
    {
        EmailSenderBatch cesb = new EmailSenderBatch();
        Database.executeBatch(cesb);
    }
}

Is the error referring to the daily email limit or too many results from the query? Any help on how I could resolve the limit would be appreciated.
  • June 02, 2014
  • Like
  • 0
Hi,
 
Is there a functionality available in salesforce where users can download the contents of "Printable View" link in a detail page to an MS Word document which is further editable?
 
Thanks for all your feedbacks.
 
Regards,
Ambili
  • April 29, 2008
  • Like
  • 0