• Ashique Khan 7
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Trying to relate events for contact roles to the opportunity. I'm getting an 'Error: Compile Error: unexpected token: WHERE at line 3 column 122'. Here's the code:
 
trigger ChangeRelatedTo on Event (before insert) {

List<OpportunityContactRole> contactsToCheck = [SELECT ContactId, OpportunityId, CreatedDate  FROM OpportunityContactRole WHERE IsDeleted = FALSE ORDER BY CreatedDate DESC];



 for( Event e : Trigger.new){

      if (e.WhoId != null){

             for ( OpportunityContactRole c: contactsToCheck ){

                 if (e.WhoId.equals(c.ContactId) ){

                 String oId = c.OpportunityId;

                     List<Opportunity> opportunity;

                     opportunity o = new opportunity();

                     o = [SELECT IsClosed, Id From Opportunity WHERE Id = :c.OpportunityId];

                     if (!o.IsClosed){

                             e.WhatId = c.OpportunityId;

                             break;

                             }

                 }

             }

      }

  }
}

 
I have a process that creates a new Opportunity when a new Event is created where there are no open Opporunities under the Account. However, the related to field on the Event defaults to the Account. How can I automate this to update the related to ID to the new Opportunity ID?
Trying to relate events for contact roles to the opportunity. I'm getting an 'Error: Compile Error: unexpected token: WHERE at line 3 column 122'. Here's the code:
 
trigger ChangeRelatedTo on Event (before insert) {

List<OpportunityContactRole> contactsToCheck = [SELECT ContactId, OpportunityId, CreatedDate  FROM OpportunityContactRole WHERE IsDeleted = FALSE ORDER BY CreatedDate DESC];



 for( Event e : Trigger.new){

      if (e.WhoId != null){

             for ( OpportunityContactRole c: contactsToCheck ){

                 if (e.WhoId.equals(c.ContactId) ){

                 String oId = c.OpportunityId;

                     List<Opportunity> opportunity;

                     opportunity o = new opportunity();

                     o = [SELECT IsClosed, Id From Opportunity WHERE Id = :c.OpportunityId];

                     if (!o.IsClosed){

                             e.WhatId = c.OpportunityId;

                             break;

                             }

                 }

             }

      }

  }
}

 
I have a process that creates a new Opportunity when a new Event is created where there are no open Opporunities under the Account. However, the related to field on the Event defaults to the Account. How can I automate this to update the related to ID to the new Opportunity ID?

I am trying to Limit the number of Protected Accounts a User should have under their ownership.  This is the trigger I created with the help of the SFDC Community 

trigger Limit1000AccountsForUsers on Account (before insert, before update) {
    Account accs = Trigger.new[0];

    if (accs.Protected_Accounts__c == true) {
        Integer accounts = [ SELECT COUNT()FROM Account WHERE Account.OwnerId = : userInfo.getUserId()]; 
        system.debug(accounts);

        if (accounts >3 ) {
            accs.addError('You are your limit of Accounts.');
        }
    }
}

But I noticed it only goes by the logged in user.  Is there a way to update the trigger so it limits the Protected Accounts regardless of the user?

 

I need to export a report as a CSV to an FTP site or email it on a daily or weekly basis.

 

I have a Report.  I need to get the report out of Salesforce somehow into CSV format.

 

Ideally, this would be scheduled.


I'm a developer so I can do developer stuff.  However, I don't know APEX and I don't know VisualForce.  I can get someone to do that stuff if we need to.


Thanks!

  • July 26, 2011
  • Like
  • 2