• skiptomylou11
  • NEWBIE
  • 40 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 15
    Replies
Hello,

We have a process which upon Opportunity creation, creates a record entry for a custom object which is linked via Lookup to the opportunity.
I now want to get the ID of the created lookup record and store it in a dedicated field on the opportunity. 
Any idea if I can achieve this with the standard feature of Process Builder or whether APEX is needed?
Many thanks! 

Hello,

 

We have a custom object named "Bidder & Contractors" which is linked to Opportunities via a Lookup relationship.

As we want to have Roll-up summary functionality on the opportunity counting the 'Bidders & Contractors' set to 'Won' we put in the below trigger.

 

It is working fine until you try to delete a 'Bidder & Contractor' entry, which gives the following error: 

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunityRollUpContractors caused an unexpected exception, contact your administrator: OpportunityRollUpContractors: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityRollUpContractors: line 6, column 1". 

 

Many thanks for your help! 

 

trigger OpportunityRollUpContractors on Bidder_Contractors__c (after delete, after insert, after update) {
 
    Set<id> OpportunityIds = new Set<id>();
    List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
 
    for (Bidder_Contractors__c item : Trigger.new)
        OpportunityIds.add(item.Opportunity__c);
 
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Bidder_Contractors__c item : Trigger.old)
            OpportunityIds.add(item.Opportunity__c);
    }
 
    // get a map of the shipments with the number of items
    Map<id,Opportunity> opportunityMap = new Map<id,Opportunity>([select id, Contractor_Count__c from Opportunity where id IN :OpportunityIds]);
 
    // query the Opportunities and the related Competition items and add the size of the Competition items to the Opportunity's Contractor_Count__c
    for (Opportunity opp: [select Id, Name, Contractor_Count__c,(select id from Awarded_Contractors_Bidders__r WHERE Awarded__c ='Won') from Opportunity where Id IN :OpportunityIds]) {
        opportunityMap.get(opp.Id).Contractor_Count__c = opp.Awarded_Contractors_Bidders__r.size();
        // add the value/shipment in the map to a list so we can update it
        opportunitiesToUpdate.add(opportunityMap.get(opp.Id));
    }
 
    update opportunitiesToUpdate;
    
    }

 

Hi,

 

We have a trigger which submits an oportunity automatically for approval if the 'Stage' is changed to either 'Won' or 'Lost' from some other stage status.

This part of the trigger works fine.

 

What we would like to implement as well is that when an opportunity is entered with the Stage set to 'Lost' (or 'Won') directly the submission to approval should also be triggered. So on creation the trigger should check if Stage equals 'Won' or 'Lost'

 

I am not sure how to write the IF statement for this instance.

It would need to include something like the ISNEW( ) function which however is only available in formulas.

 

Ideally if possible both functionalities, the existing and the check on record entry would be dealt with in one trigger.

 

Any help is appreciated!

Many thanks...

 

 

Trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for(Integer i = 0; i < Trigger.new.size(); i++) 
    
     {
  if((Trigger.new[i].StageName == 'Won' && Trigger.old[i].StageName <> 'Won') ||

     (Trigger.new[i].StageName == 'Lost' && Trigger.old[i].StageName <> 'Lost'))

        {
 
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());  
 
        }
       
    }
 }

 

Hi,

 

I have an issue with the below trigger.

When the Stage on the Opportunity is changed to 'Won' or 'Lost' the opportunity enters an approval process.

 

However, when the approver tries to change any information on the opportunity (after unlocking it) he gets the following error:

 

Error:Apex trigger OpportunitySubmitForOrderListApproval caused an unexpected exception, contact your administrator: OpportunitySubmitForOrderListApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []: Trigger.OpportunitySubmitForOrderListApproval: line 10, column 1

 

To me it seems it is trying to submit the opportunity again and as it is still under approval brings the error message.

Can anyone see in the code below any errors regarding this?

 

Thanks!! 

 

trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for(Integer i = 0; i < Trigger.new.size(); i++) 
    
     {
        if ((Trigger.old[i].StageName <> '6 - Project won'  ||  Trigger.old[i].StageName <> '7 - Project lost')  && (Trigger.new[i].StageName == '6 - Project won'  ||  Trigger.new[i].StageName == '7 - Project lost')) 
        {
 
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());  
 
        }
       
    }
 }

 

Dear all,

 

I have created a trigger in my Sandbox which automatically submits an Opportunity to an approval process once the Stage is changed to either 'Won' or 'Lost'. I have attached both code snippets below.

It is now working fine in my sandbox but when I try to deploy it to the production Org I receive the following error on the test class referring to the last line of code of the test class.

 

Many thanks for any support!

 

TestOpportunitySubmitForOrderApproval.testApprovalSuccess()Class211Failure Message: "System.AssertException: Assertion Failed: Expected: 2, Actual: 1", Failure Stack Trace: "Class.TestOpportunitySubmitForOrderApproval.testApprovalSuccess: line 21, column 1"

 

trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for(Integer i = 0; i < Trigger.new.size(); i++) 
    
     {
        if ((Trigger.old[i].StageName <> '6 - Project won'  ||  Trigger.old[i].StageName <> '7 - Project lost')  && (Trigger.new[i].StageName == '6 - Project won'  ||  Trigger.new[i].StageName == '7 - Project lost')) 
        {
 
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());  
 
        }
       
    }
 }

 

 

@isTest
private class TestOpportunitySubmitForOrderApproval {
 
    static testMethod void testApprovalSuccess() {
 
        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opp';
        opp.Amount = 100;
        opp.CloseDate = Date.today();
        opp.StageName = '0 - New Opportunity';
        opp.Division__c= 'SYS';
        // insert the new opp
        insert opp;
        // change the probability of the opp so the trigger submits it for approval
    opp.StageName = '6 - Project won';
    // update the opp which should submit it for approval
    update opp;
 
        // ensure that the opp was submitted for approval
        List<ProcessInstance> processInstances = [select Id, Status from ProcessInstance where TargetObjectId = :opp.id];
    System.assertEquals(processInstances.size(),1);
 
    }
 }

 

Dear all,

 

I am very new to triggers.

I want all opportunities to be automatically submitted for approval if...

 

a) Their Stage is changed to either 'Won' or 'Lost'

b) They are created with the Stage set to 'Won' or 'Lost'

 

What happens based on the below code is that a newly created Oppty with Stage 'Won' or 'Lost' enters approval automatically.

 

When changing the stage to 'won' or 'Lost' on an existing opportunity I get the following error:

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunitySubmitForOrderListApproval caused an unexpected exception, contact your administrator: OpportunitySubmitForOrderListApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []: Trigger.OpportunitySubmitForOrderListApproval: line 12, column 1".

 

Moreover creating a new oppty with the Stage NOT set to 'Won' or 'Lost'  brings the following error

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunitySubmitForOrderListApproval caused an unexpected exception, contact your administrator: OpportunitySubmitForOrderListApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found.: []: Trigger.OpportunitySubmitForOrderListApproval: line 12, column 1". 

 

Any help is greatly apprecated!!! 

Thanks! 

 

trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for (Integer i = 0; i < Trigger.new.size(); i++) {
 
        if (Trigger.old[i].StageName <> '6 - Project won'  ||  Trigger.old[i].StageName <> '7 - Project lost'  &&   Trigger.new[i].StageName == '6 - Project won'  ||  Trigger.new[i].StageName == '7 - Project lost') {
 
            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
 
        }
 
    }
 
}

 

Hello,

 

I have the following custom button which is used on a related list (custom object) to record a new entry.

The standard 'New' buttons in the related lists open in the same window as the opprtunity is shown.

I would like to have the same functionality here...

 

I tried window.location but that gives me an error when clicking the button.

 

Many thanks! 

 

window.open('/a1c/e?CF00N20000003ZohQ={!Opportunity.Name}&CF00N20000003ZohQ_lkid={!Opportunity.Id} &retURL=%2F{!Opportunity.Id} & RecordType=01220000000JOLS')

 

Hi,

 

I have embedded a VF page into a standard Salesforce page for Accounts.

 

The VF page contains input fields as well as apex:relatedLists. 

Whenever I click on a link (e.g. a lookup field) or try to create a new related list entry via the 'New' button only the section of the VF page is reloaded an shows the lookup record or entry mask for a new related list item.

 

How can I make the whole Account (parent / host) page reload?

I tried target='_top' in different areas but I could not make it work.

 

Any ideas?

Many thanks! 

Dear all,

 

What I try to achieve is to have a visualforce page where a single field (Bid_Costs_Forecast_YE__c) can be updated for a number of records in a single step instead of going into each record individually.

 

The records in the VF page should be filtered and sorted by certain criteria .

 

Therefore I put in an extension. 

However, when I update the information in the VF page and click 'Save' the updates are not saved.

Any help on how the extension needs to be modified is highly appreciated.

 

Many thanks! 

 

<apex:page standardController="Project__c" recordSetVar="Projects__c" tabstyle="Project__c" sidebar="false" extensions="BidCostAmericasExt">
    <apex:form >  
        <apex:pageBlock title="Bid Costs Americas" >
        <apex:pageblockButtons >
           <apex:commandButton style=" height:25px; margin-left:400px; font-size:14px" action="{!quickSave}" value="Save" />
        </apex:pageblockButtons>
            <apex:pageBlockTable value="{!SYSProjects}" var="opp">          
                <apex:column headerValue="Project" > 
                     <apex:outputLink target="_blank" value="/{!opp.id}">{!opp.Name}</apex:outputLink>             
                </apex:column> 
                <apex:column headerValue="Priority" width="150px"> 
                    <apex:outputField value="{!opp.Priority__c}" />        
                </apex:column>    
                <apex:column headerValue="Actuals YTD" width="80px">
                    <apex:outputField value="{!opp.Bid_Costs_Actuals_YTD__c}" />
                </apex:column> 
                <apex:column headerValue="Budget YE" width="80px">
                    <apex:outputField value="{!opp.Bid_Costs_Budget_YE__c}" />
                </apex:column>   
                <apex:column headerValue="Forecast YE" width="80px">
                    <apex:inputField style="width:80px" value="{!opp.Bid_Costs_Forecast_YE__c}" />
                </apex:column>  
            </apex:pageBlockTable>  
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

public class BidCostAmericasExt {

    public BidCostAmericasExt(ApexPages.StandardSetController controller) {

    }

    Project__c proj;
    
    public BidCostAmericasExt (ApexPages.StandardController controller) {
        proj = (Project__c) controller.getRecord();            
    }    
    
    public List<Project__c> getSYSProjects() {
        return [select name, Priority__c, Bid_Manager__c, Bid_Costs_Actuals_CTD_PY__c, Bid_Costs_Actuals_YTD__c, Bid_Costs_Budget_YE__c, Bid_Costs_Forecast_YE__c,  Comment_Bid_Costs__c from Project__c where Business_Unit__c = 'Americas' order by Bid_Costs_Forecast_YE__c];    
    }
}

 

 

 

Dear all,

 

I am trying to deloy the following APEX Class, which is used as an extension on an VF page.

 

The purpose is to upload an attachment (via the VF Page) on the RCS_WhiteBook__c object and store the attachment id in a custom field (Picture_id__c).

The code is working fine in the sandbox but I have issues deploying.

 

Many thanks for your help!

 

public class ExtUploadPicture  {

    private Attachment attachment;
    private final ApexPages.standardController theController;  
    private Id contId = ApexPages.currentPage().getParameters().get('objectId');
    //private Id userId = ApexPages.currentPage().getParameters().get('userId');
    private Id attId;
  
    public ExtUploadPicture (ApexPages.StandardController con) {
        theController = con;
        this.attachment = (Attachment) con.getRecord();
        this.attachment.ParentId = contId;
    }
    
    public PageReference updateRCSWhiteBook() {
        this.attachment.Name = 'Upload.jpg';
        insert this.attachment;
      
        RCS_Whitebook__c cont = [Select Picture_Id__c, Id From RCS_Whitebook__c Where Id = :this.contId];
        cont.Picture_Id__c = this.attachment.Id;
        update cont;
         
        PageReference pageRef = new PageReference('/'+ this.contId);
        return pageRef;
    }                    
}

 

Hi,

 

I am actually trying to build a very basic trigger on opportunities.

 

The field country_object__c is a lookup field to an object with country information.

The selection he makes there (country name) should be filled into the country__c field when the entry is saved.

 

The code below however only puts in the id of the country object record.

 

Background is that the field country__c is used in many reports and sharing rules which I do not want to rework.

 

Many thanks!!!!

 

 

Trigger Update_Country on Opportunity (before update, before insert) {

 // Fill the Country__c field with the lookup name
 
  for (Opportunity o : Trigger.new) {
     o.Country__c = o.Country_Object__c;
  }

}

 

Hi there,

 

On opportunities I want to use a picklist field ('Stage') to trigger opening a VF page if a certain value in selected (i.e. Project Lost).

 

I have already created the VF page (which includes some addtional input fields like who is the winning competitor) but my issue is how can I trigger the VF page to appear / pop-up once 'Project Lost' is selected in the 'stage' field.

 

I assume I'd have to use Java for this but I have no / not much experience with it.

 

Does anyone has some sample code or can point me in the right direction?

Help is highly appreciated...

Many thanks!!! 

Dear all,

 

I have put together the trigger below which creates a child record (SYS_Capture_Plan__c) when a new master record (Project__c) is created.

From what I saw this works fine.

 

trigger AutoCreateCapturePlan on Project__c (after insert) {
    List<SYS_Capture_Plan__c> SYSCapturePlan = new List<SYS_Capture_plan__c>();
     
    for (Project__c newPosition: Trigger.New) {
         {
            SYSCapturePlan.add(new SYS_Capture_Plan__c(
                        Name = newPosition.Name + ' - Capture Plan',
                        Project__c = newPosition.id ));
        }
    }
    insert SYSCapturePlan;
}

 What I would now like to do is record the ID of the child object that gets created on a filed on the master level (Field name = Capture_Plan_id__c).

I would actually like to hide the related list in the master object page layout and instead include a button (using the Capture_plan_id__c field) to link it.

Can this be included in the existing code? (probably a stupid question).

 

Moreover, I'm struggling with writing a test script for this. Could anybody help?

 

Many thanks,

patrick

Hallo,

In our SF environment the Account object is set to 'Public Read Only'.

All users however should be able to change the record type via a VF page component with several links simply calling different the record types.

 

My only idea is to use a custom contoller without sharing rules. I however, have no experience whatsoever writing a custom controller...

Any hints or code samples would be very appreciated.

Many thanks! 

 

Hi,

 

I am new to Apex and triggers...

 

This is what I want to do:

I have a Child_Object__c to Opportunity. The record name field is set to Text (80). 

On creation (or saving) of a child record I would like the record name field to be filled with the name of the parent opportunity. Even though it is set up via Master-Detail relationship there is always just one related child record required so there is no issue with the text being unique.

 

I really appreciate your support.

Cheers! 

Hello,

 

We have a custom object named "Bidder & Contractors" which is linked to Opportunities via a Lookup relationship.

As we want to have Roll-up summary functionality on the opportunity counting the 'Bidders & Contractors' set to 'Won' we put in the below trigger.

 

It is working fine until you try to delete a 'Bidder & Contractor' entry, which gives the following error: 

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunityRollUpContractors caused an unexpected exception, contact your administrator: OpportunityRollUpContractors: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityRollUpContractors: line 6, column 1". 

 

Many thanks for your help! 

 

trigger OpportunityRollUpContractors on Bidder_Contractors__c (after delete, after insert, after update) {
 
    Set<id> OpportunityIds = new Set<id>();
    List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
 
    for (Bidder_Contractors__c item : Trigger.new)
        OpportunityIds.add(item.Opportunity__c);
 
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Bidder_Contractors__c item : Trigger.old)
            OpportunityIds.add(item.Opportunity__c);
    }
 
    // get a map of the shipments with the number of items
    Map<id,Opportunity> opportunityMap = new Map<id,Opportunity>([select id, Contractor_Count__c from Opportunity where id IN :OpportunityIds]);
 
    // query the Opportunities and the related Competition items and add the size of the Competition items to the Opportunity's Contractor_Count__c
    for (Opportunity opp: [select Id, Name, Contractor_Count__c,(select id from Awarded_Contractors_Bidders__r WHERE Awarded__c ='Won') from Opportunity where Id IN :OpportunityIds]) {
        opportunityMap.get(opp.Id).Contractor_Count__c = opp.Awarded_Contractors_Bidders__r.size();
        // add the value/shipment in the map to a list so we can update it
        opportunitiesToUpdate.add(opportunityMap.get(opp.Id));
    }
 
    update opportunitiesToUpdate;
    
    }

 

Hello,

We have a process which upon Opportunity creation, creates a record entry for a custom object which is linked via Lookup to the opportunity.
I now want to get the ID of the created lookup record and store it in a dedicated field on the opportunity. 
Any idea if I can achieve this with the standard feature of Process Builder or whether APEX is needed?
Many thanks! 

Hello,

 

We have a custom object named "Bidder & Contractors" which is linked to Opportunities via a Lookup relationship.

As we want to have Roll-up summary functionality on the opportunity counting the 'Bidders & Contractors' set to 'Won' we put in the below trigger.

 

It is working fine until you try to delete a 'Bidder & Contractor' entry, which gives the following error: 

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunityRollUpContractors caused an unexpected exception, contact your administrator: OpportunityRollUpContractors: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityRollUpContractors: line 6, column 1". 

 

Many thanks for your help! 

 

trigger OpportunityRollUpContractors on Bidder_Contractors__c (after delete, after insert, after update) {
 
    Set<id> OpportunityIds = new Set<id>();
    List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
 
    for (Bidder_Contractors__c item : Trigger.new)
        OpportunityIds.add(item.Opportunity__c);
 
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Bidder_Contractors__c item : Trigger.old)
            OpportunityIds.add(item.Opportunity__c);
    }
 
    // get a map of the shipments with the number of items
    Map<id,Opportunity> opportunityMap = new Map<id,Opportunity>([select id, Contractor_Count__c from Opportunity where id IN :OpportunityIds]);
 
    // query the Opportunities and the related Competition items and add the size of the Competition items to the Opportunity's Contractor_Count__c
    for (Opportunity opp: [select Id, Name, Contractor_Count__c,(select id from Awarded_Contractors_Bidders__r WHERE Awarded__c ='Won') from Opportunity where Id IN :OpportunityIds]) {
        opportunityMap.get(opp.Id).Contractor_Count__c = opp.Awarded_Contractors_Bidders__r.size();
        // add the value/shipment in the map to a list so we can update it
        opportunitiesToUpdate.add(opportunityMap.get(opp.Id));
    }
 
    update opportunitiesToUpdate;
    
    }

 

Hi,

 

We have a trigger which submits an oportunity automatically for approval if the 'Stage' is changed to either 'Won' or 'Lost' from some other stage status.

This part of the trigger works fine.

 

What we would like to implement as well is that when an opportunity is entered with the Stage set to 'Lost' (or 'Won') directly the submission to approval should also be triggered. So on creation the trigger should check if Stage equals 'Won' or 'Lost'

 

I am not sure how to write the IF statement for this instance.

It would need to include something like the ISNEW( ) function which however is only available in formulas.

 

Ideally if possible both functionalities, the existing and the check on record entry would be dealt with in one trigger.

 

Any help is appreciated!

Many thanks...

 

 

Trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for(Integer i = 0; i < Trigger.new.size(); i++) 
    
     {
  if((Trigger.new[i].StageName == 'Won' && Trigger.old[i].StageName <> 'Won') ||

     (Trigger.new[i].StageName == 'Lost' && Trigger.old[i].StageName <> 'Lost'))

        {
 
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());  
 
        }
       
    }
 }

 

Hi,

 

I have an issue with the below trigger.

When the Stage on the Opportunity is changed to 'Won' or 'Lost' the opportunity enters an approval process.

 

However, when the approver tries to change any information on the opportunity (after unlocking it) he gets the following error:

 

Error:Apex trigger OpportunitySubmitForOrderListApproval caused an unexpected exception, contact your administrator: OpportunitySubmitForOrderListApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []: Trigger.OpportunitySubmitForOrderListApproval: line 10, column 1

 

To me it seems it is trying to submit the opportunity again and as it is still under approval brings the error message.

Can anyone see in the code below any errors regarding this?

 

Thanks!! 

 

trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for(Integer i = 0; i < Trigger.new.size(); i++) 
    
     {
        if ((Trigger.old[i].StageName <> '6 - Project won'  ||  Trigger.old[i].StageName <> '7 - Project lost')  && (Trigger.new[i].StageName == '6 - Project won'  ||  Trigger.new[i].StageName == '7 - Project lost')) 
        {
 
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());  
 
        }
       
    }
 }

 

Dear all,

 

I am very new to triggers.

I want all opportunities to be automatically submitted for approval if...

 

a) Their Stage is changed to either 'Won' or 'Lost'

b) They are created with the Stage set to 'Won' or 'Lost'

 

What happens based on the below code is that a newly created Oppty with Stage 'Won' or 'Lost' enters approval automatically.

 

When changing the stage to 'won' or 'Lost' on an existing opportunity I get the following error:

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunitySubmitForOrderListApproval caused an unexpected exception, contact your administrator: OpportunitySubmitForOrderListApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []: Trigger.OpportunitySubmitForOrderListApproval: line 12, column 1".

 

Moreover creating a new oppty with the Stage NOT set to 'Won' or 'Lost'  brings the following error

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunitySubmitForOrderListApproval caused an unexpected exception, contact your administrator: OpportunitySubmitForOrderListApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found.: []: Trigger.OpportunitySubmitForOrderListApproval: line 12, column 1". 

 

Any help is greatly apprecated!!! 

Thanks! 

 

trigger OpportunitySubmitForOrderListApproval on Opportunity (after update) {
 
    for (Integer i = 0; i < Trigger.new.size(); i++) {
 
        if (Trigger.old[i].StageName <> '6 - Project won'  ||  Trigger.old[i].StageName <> '7 - Project lost'  &&   Trigger.new[i].StageName == '6 - Project won'  ||  Trigger.new[i].StageName == '7 - Project lost') {
 
            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
 
        }
 
    }
 
}

 

Hi,

 

I have embedded a VF page into a standard Salesforce page for Accounts.

 

The VF page contains input fields as well as apex:relatedLists. 

Whenever I click on a link (e.g. a lookup field) or try to create a new related list entry via the 'New' button only the section of the VF page is reloaded an shows the lookup record or entry mask for a new related list item.

 

How can I make the whole Account (parent / host) page reload?

I tried target='_top' in different areas but I could not make it work.

 

Any ideas?

Many thanks! 

Dear all,

 

I am trying to deloy the following APEX Class, which is used as an extension on an VF page.

 

The purpose is to upload an attachment (via the VF Page) on the RCS_WhiteBook__c object and store the attachment id in a custom field (Picture_id__c).

The code is working fine in the sandbox but I have issues deploying.

 

Many thanks for your help!

 

public class ExtUploadPicture  {

    private Attachment attachment;
    private final ApexPages.standardController theController;  
    private Id contId = ApexPages.currentPage().getParameters().get('objectId');
    //private Id userId = ApexPages.currentPage().getParameters().get('userId');
    private Id attId;
  
    public ExtUploadPicture (ApexPages.StandardController con) {
        theController = con;
        this.attachment = (Attachment) con.getRecord();
        this.attachment.ParentId = contId;
    }
    
    public PageReference updateRCSWhiteBook() {
        this.attachment.Name = 'Upload.jpg';
        insert this.attachment;
      
        RCS_Whitebook__c cont = [Select Picture_Id__c, Id From RCS_Whitebook__c Where Id = :this.contId];
        cont.Picture_Id__c = this.attachment.Id;
        update cont;
         
        PageReference pageRef = new PageReference('/'+ this.contId);
        return pageRef;
    }                    
}

 

Hi,

 

I am actually trying to build a very basic trigger on opportunities.

 

The field country_object__c is a lookup field to an object with country information.

The selection he makes there (country name) should be filled into the country__c field when the entry is saved.

 

The code below however only puts in the id of the country object record.

 

Background is that the field country__c is used in many reports and sharing rules which I do not want to rework.

 

Many thanks!!!!

 

 

Trigger Update_Country on Opportunity (before update, before insert) {

 // Fill the Country__c field with the lookup name
 
  for (Opportunity o : Trigger.new) {
     o.Country__c = o.Country_Object__c;
  }

}

 

Dear all,

 

I have put together the trigger below which creates a child record (SYS_Capture_Plan__c) when a new master record (Project__c) is created.

From what I saw this works fine.

 

trigger AutoCreateCapturePlan on Project__c (after insert) {
    List<SYS_Capture_Plan__c> SYSCapturePlan = new List<SYS_Capture_plan__c>();
     
    for (Project__c newPosition: Trigger.New) {
         {
            SYSCapturePlan.add(new SYS_Capture_Plan__c(
                        Name = newPosition.Name + ' - Capture Plan',
                        Project__c = newPosition.id ));
        }
    }
    insert SYSCapturePlan;
}

 What I would now like to do is record the ID of the child object that gets created on a filed on the master level (Field name = Capture_Plan_id__c).

I would actually like to hide the related list in the master object page layout and instead include a button (using the Capture_plan_id__c field) to link it.

Can this be included in the existing code? (probably a stupid question).

 

Moreover, I'm struggling with writing a test script for this. Could anybody help?

 

Many thanks,

patrick

Hi,

 

I am new to Apex and triggers...

 

This is what I want to do:

I have a Child_Object__c to Opportunity. The record name field is set to Text (80). 

On creation (or saving) of a child record I would like the record name field to be filled with the name of the parent opportunity. Even though it is set up via Master-Detail relationship there is always just one related child record required so there is no issue with the text being unique.

 

I really appreciate your support.

Cheers!