• Wendy Sadeh
  • NEWBIE
  • 25 Points
  • Member since 2015

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

I have a custom field that will store the order of a related list off of the Opportunity Object.  So if item gets udpated the trigger should run through and adjust the order.  I am running into recursion errors.  I have googled for a while and haven't found a pattern that will work for me.  Any suggestion?

trigger updateTenantSortOrder on Tenant__c (before insert, before update, after delete) {
    Set<Id> opportunityIds = new Set<Id>();
    Integer order=1;

    for (Tenant__c tenant : Trigger.new) {
        // get opportunity id to be used as a key to get entire list.
        opportunityIds.add(tenant.Opportunity__c);
    }

   // Order list appropriately
    List<Tenant__c> tenants = 
          [select id,Name,TenantBySqFtSortOder__c from Tenant__c where Opportunity__c IN :opportunityIds order by Tenant_Square_Foot__c DESC LIMIT 10];

   // Update sort order field
    for (Tenant__c t : tenants) {
            t.TenantBySqFtSortOder__c =order++;
    }

    // update objects
    update tenants;
}

 

xlsx format is not supported. And xls format is no longer supported.
https://success.salesforce.com/answers?id=9063A000000iTIyQAM

I want to create an apex class to create a seperate worksheet for one to many custom object on opportunities.  Is there anyway to do this?  

I have custom code that create and xls file but I cannot open it with the latest Microsoft code.

Is there anyway to do this?  Another app?  Anything?
In my partner community I have some custom code that will create an opportunity and will set up some defaults.  If a partner creates an opportunity I want to set the Opportunity Owner to an internal salesperson.  

For instance:  opportunity.OwnerID = '005j000000CAPu5';

When I do this I get Insufficient Privileges error.  Not sure what lever to pull.
csv file:

Account Name,Account Status,Account Type,Segment Affiliation,Account Vertical
ABC Bargetto Winery,Pre-Contact,Owner,Owner-User,Mixed-Use


Segment Affiliation is a custom field picklist  on account.  When I import this data extraneous notes are added to account.  

User-added image
On the opportunity I have a custom button that does some verification and if the verification passes, I want to update the stage name.  My update code has no affect.  Below is posted my code snippets.

Here is the apext code:
<apex:page standardController="Opportunity" extensions="CustomOpportunitySaveExtension">
   <apex:form >
       <apex:pageBlock title="Opportunity Submission">
           <apex:pageBlockSection title="Please fill the below fields before submitting the Opportunity form" columns="1">
           
           <apex:outputText style="color:red" value="{!CheckAndValidate}" escape="false"/>
          
           <apex:commandButton value="Go Back to Opportunity Form" action="{!getBack}"/>

           </apex:pageBlockSection>
       </apex:pageBlock>    
   </apex:form> 
</apex:page>
 
public class CustomOpportunitySaveExtension
{

 private final Opportunity opp;

    private final ApexPages.StandardController oController;
 public Id OpportunityId {get; set;}
  
 public CustomOpportunitySaveExtension (ApexPages.StandardController stdController) 
 {
     this.opp = (Opportunity)stdController.getRecord();
     this.oController = stdController;
 }

 public PageReference getBack()
 {
     String refUrl;
     refUrl = '/'+ opp.Id ;
     PageReference ref = new PageReference(refUrl);    
     ref.setRedirect(true);
     return ref;
 }
 
 public String getCheckAndValidate() 
 {
      List<Opportunity> opportunitylst = [
          SELECT Id, Name, PACEPartner_Project_Number__c, Transaction_Manager__c, StageName,   FROM Opportunity WHERE Id = :opp.Id     
           LIMIT 1
        ];
     
      Opportunity opportunity;

      String validationMessage = '';
      Boolean isMissed = false;
              
      if ( opportunitylst.size() > 0 ) 
      {
        opportunity = opportunitylst[0];
          
          system.debug('Oppurtunity Name : ' + opportunity.Name);
        
        // Project Status - Section Starts
        
        if(opportunity.Name == null)
        {
            validationMessage += 'Project Name - Opportunity Name';
            isMissed = true;
        }
        if(!isMissed)
        {
           // This is where I want to update the stage name.  It has no affect.
            opportunity.StageName = 'Qualified Lead';
            oController.save();

            validationMessage += 'Your application is submitted successfully';
        }
     }

 
Hello,

I think this is a basic question but I think I must be searching for the wrong information because I can't seem to figure it out.

We use custom text fields to track addresses, but we also use a service that populates the standard mailing address fields (which we have hidden from our non-admin users). I'm looking for a way to copy any data in a new contact's standard mailing address fields to our custom fields. I believe I can do this using a Workflow Rule, but I am completely unfamiliar with setting up these rules. 

I'm not sure which rule criteria to use. When it comes to setting up a Field Update, I'm not sure how to write the formula to capture the information and copy it over to the custom fields. 

I couldn't find an answer searching but I think that's due to me asking the question poorly. I'd really appreciate any suggestions / help! Thanks!

KJ

I have a custom field that will store the order of a related list off of the Opportunity Object.  So if item gets udpated the trigger should run through and adjust the order.  I am running into recursion errors.  I have googled for a while and haven't found a pattern that will work for me.  Any suggestion?

trigger updateTenantSortOrder on Tenant__c (before insert, before update, after delete) {
    Set<Id> opportunityIds = new Set<Id>();
    Integer order=1;

    for (Tenant__c tenant : Trigger.new) {
        // get opportunity id to be used as a key to get entire list.
        opportunityIds.add(tenant.Opportunity__c);
    }

   // Order list appropriately
    List<Tenant__c> tenants = 
          [select id,Name,TenantBySqFtSortOder__c from Tenant__c where Opportunity__c IN :opportunityIds order by Tenant_Square_Foot__c DESC LIMIT 10];

   // Update sort order field
    for (Tenant__c t : tenants) {
            t.TenantBySqFtSortOder__c =order++;
    }

    // update objects
    update tenants;
}

 

xlsx format is not supported. And xls format is no longer supported.
https://success.salesforce.com/answers?id=9063A000000iTIyQAM

I want to create an apex class to create a seperate worksheet for one to many custom object on opportunities.  Is there anyway to do this?  

I have custom code that create and xls file but I cannot open it with the latest Microsoft code.

Is there anyway to do this?  Another app?  Anything?
In my partner community I have some custom code that will create an opportunity and will set up some defaults.  If a partner creates an opportunity I want to set the Opportunity Owner to an internal salesperson.  

For instance:  opportunity.OwnerID = '005j000000CAPu5';

When I do this I get Insufficient Privileges error.  Not sure what lever to pull.
csv file:

Account Name,Account Status,Account Type,Segment Affiliation,Account Vertical
ABC Bargetto Winery,Pre-Contact,Owner,Owner-User,Mixed-Use


Segment Affiliation is a custom field picklist  on account.  When I import this data extraneous notes are added to account.  

User-added image
On the opportunity I have a custom button that does some verification and if the verification passes, I want to update the stage name.  My update code has no affect.  Below is posted my code snippets.

Here is the apext code:
<apex:page standardController="Opportunity" extensions="CustomOpportunitySaveExtension">
   <apex:form >
       <apex:pageBlock title="Opportunity Submission">
           <apex:pageBlockSection title="Please fill the below fields before submitting the Opportunity form" columns="1">
           
           <apex:outputText style="color:red" value="{!CheckAndValidate}" escape="false"/>
          
           <apex:commandButton value="Go Back to Opportunity Form" action="{!getBack}"/>

           </apex:pageBlockSection>
       </apex:pageBlock>    
   </apex:form> 
</apex:page>
 
public class CustomOpportunitySaveExtension
{

 private final Opportunity opp;

    private final ApexPages.StandardController oController;
 public Id OpportunityId {get; set;}
  
 public CustomOpportunitySaveExtension (ApexPages.StandardController stdController) 
 {
     this.opp = (Opportunity)stdController.getRecord();
     this.oController = stdController;
 }

 public PageReference getBack()
 {
     String refUrl;
     refUrl = '/'+ opp.Id ;
     PageReference ref = new PageReference(refUrl);    
     ref.setRedirect(true);
     return ref;
 }
 
 public String getCheckAndValidate() 
 {
      List<Opportunity> opportunitylst = [
          SELECT Id, Name, PACEPartner_Project_Number__c, Transaction_Manager__c, StageName,   FROM Opportunity WHERE Id = :opp.Id     
           LIMIT 1
        ];
     
      Opportunity opportunity;

      String validationMessage = '';
      Boolean isMissed = false;
              
      if ( opportunitylst.size() > 0 ) 
      {
        opportunity = opportunitylst[0];
          
          system.debug('Oppurtunity Name : ' + opportunity.Name);
        
        // Project Status - Section Starts
        
        if(opportunity.Name == null)
        {
            validationMessage += 'Project Name - Opportunity Name';
            isMissed = true;
        }
        if(!isMissed)
        {
           // This is where I want to update the stage name.  It has no affect.
            opportunity.StageName = 'Qualified Lead';
            oController.save();

            validationMessage += 'Your application is submitted successfully';
        }
     }