• Choleric
  • NEWBIE
  • 25 Points
  • Member since 2009
  • ADvendio.com

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

Hey,

 

I need to create Partner-Object entries within an APEX class.

Therefore the User needs 'view all data' permissions.

Granting these permissions permanently is not an option.

 

Thats why I'm searching for a way to:

a) switch the user in an APEX class -> runAs() seems to work in TestClasses only,

b) granting permissions within the class

or

c) skip any permission checks for the class / certain calls in the class

 

Any Idea is welcome.

 

 

so long

Stefan

 

 

Hi,

 

I'm getting System.LimitException: Too many script statements for the below Apex Code:

 

Apex Code:

public class OpportunitySalesTeamSwarmHelper {

public static void evaluateOpptySalesTeamRules() {

// Get list of Opptys with opp, acc, owner details
List<Opportunity> opptys = [SELECT o.Id, o.Name, o.Type, o.AccountId, Account.Name,Account.OwnerId, Account.JDA_Industry__c,
Account.Named_Account__c,Account.Target_Rating__c, o.StageName, o.Amount,o.CurrencyIsoCode, o.Local_Region_Override__c,o.CloseDate, o.Business_Unit__c,
o.OwnerId, o.Owner.Name, o.Owner.Reports_To__c FROM Opportunity o WHERE o.StageName like 'open'];

// Get list of all rules
List<Opportunity_Swarm_Rule__c> rules = [select Name,type__c, Opportunity_amount__c, Opportunity_stage__c,
Opportunity_type__c, Opportunity_Local__c,Opportunity_Business_Unit__c,JDA_Industry__c, user__c,
ownerId, Notify_on_Swarm__c from Opportunity_Swarm_Rule__c WHERE user__r.IsActive = true];

// Get all subscriptions and put in string concatenating subscriber + object ID
List<EntitySubscription> existingOpptySubs = [select SubscriberId, ParentId from EntitySubscription where ParentId in :opptys];

Set<String> existingOpptySubsIds = new Set<String>();
for (EntitySubscription es:existingOpptySubs) {
existingOpptySubsIds.add((String)es.SubscriberId + es.ParentId);
}//for

List<OpportunityTeamMember> opptySalesTeams = [SELECT UserId from OpportunityTeamMember where OpportunityId in :opptys];

// Create a list of subscripions and chatter feeds and insert them later outside the loop
List<EntitySubscription> subs = new List<EntitySubscription>();
List<FeedItem> feedNotifications = new List<FeedItem>();

// For each oppty check all rules.
// If criteria is satisfied, make the user of rule to follow the opportunity
Integer count = 0;
for (Opportunity thisOppty : opptys) {
count++;
System.debug('The value of Count is'+count);
for (Opportunity_Swarm_Rule__c rule : rules) {

if(rule.Type__c.contains('Opptys where I am an Account Team Member')) {

boolean salesTeamFlag = false;
boolean condition = false;
for (OpportunityTeamMember opptySalesTeam : opptySalesTeams) {
if(rule.User__c == opptySalesTeam.UserId ){
salesTeamFlag=true;
}
if(salesTeamFlag)
break;
}

condition= salesTeamFlag;
System.debug('The value of Condition - Opptys where I am Sales Team Member is : '+condition);

if(condition) {
if (existingOpptySubsIds.contains((string)rule.User__c + thisOppty.Id) == FALSE) {
subs.add(new EntitySubscription(parentId = thisOppty.id, SubscriberId = rule.User__c));
existingOpptySubsIds.add((String)rule.User__c + thisOppty.id);

// Add swarming notification to user's feed
if (rule.Notify_on_Swarm__c == true) {
//displaying close datetime as only date string
Datetime dateTimetemp = thisOppty.CloseDate;
Date dateTemp = Date.newInstance(dateTimetemp.year(),dateTimetemp.month(),dateTimetemp.day());
String dateStr = dateTemp.format();

string msg = 'You have automatically swarmed an Opportunity.'+ '\n' +
'Opportunity Name : ' + thisOppty.Name+ '\n' +
'Account : ' + thisOppty.Account.Name + '\n' +
'Type : ' + thisOppty.Type + '\n' +
'Close Date : ' + dateStr + '\n' +
'Owner : ' + thisOppty.Owner.Name;

FeedItem swarmNotification = new FeedItem();
swarmNotification.Type = 'LinkPost';
swarmNotification.ParentId = rule.User__c;
swarmNotification.Title = 'Link to Opportunity Record '+thisOppty.Name+' Swarmed';
swarmNotification.Body = msg;
swarmNotification.LinkUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/' + thisOppty.Id;
feedNotifications.add(swarmNotification);
}// if 3
}//if 2
}//if 1
}

}//for 2

}//for 1 oppty's

try {
System.Debug('Subscription count : ' + subs.size());
insert subs;
insert feedNotifications;
} catch (DMLException e) {
system.debug('Oppty Swarm subscriptions were not all inserted successfully. Error: '+e);
}//catch
}//evaluateOpptyRules

}//class

 

Below is debug log info:

01:42:46.811|LIMIT_USAGE_FOR_NS|(default)|

Number of SOQL queries: 4 out of 100
Number of query rows: 6698 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Number of script statements: 200002 out of 200000 ******* CLOSE TO LIMIT
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

 

Can someone look at the code and please share your thoughts to overcome the above exception..

 

Thanks in advance..

 

Stumped on an error: Non-selective query against large object type (more than 100000 rows). My query is on the assets object which does have over 700k records. However, the exact query runs fine in a class or anonymous block. It only throws the error when executing from a trigger. I've tried indexing one of the fields in the WHERE clause, but I'm still getting the error. Open ticket with Salesforce has not been helpful, so I'm rather desperate - has anyone here run into this?

 

Query:


Select id, name, SerialNumber from Asset where IsVisionLink__c = false and Exception_from_Disable__c = true  and source__c != null and source__c = 'CN_CCFL_OU'

 

 

Again - query runs just fine in an anonymous block.  The source__c field has been marked as an external id, which should mean it is indexed.  Why am I still getting this error?  Have an open ticket with Salesforce, but they have not been helpful thus far.

  • September 21, 2011
  • Like
  • 0

Hi Guys,


I am looking for some help in regards to a trigger I am writing on the case object.


The case is currently orphaned as it has no account ID inserted with it. However, on the case I do have the name of the account in a text field wriiten exactly as it is shown on the account page. Why I have this data structured like this is a long dull story and I know there were probably better ways to do this when setting up my process but I am new at this.


Here's what I want to - I want a trigger to look at the text field with the account name, search for the AccountID and link the case to the correct account so it's not orphaned any more.


My code is below - where am I going wrong?

 

trigger CaseAccountUpdater2 on Case (before insert, before update) {

 

 for(Case cas : Trigger.New){  

 

   if(cas.AccountId != null) {  

      cas.Account = [Select ID    

      From Account    

      Where Name = :Cas.Council_Name_Text__c    

      Limit 1];  

    }

  }

}

I am facing difficulties in writing test class. The main class logic reads the current date and time, reads the default business hours data, and performs functions based on the current date or time is within business hours or not. Also, it schedules jobs for end of business. My problem is since DML is not allowed in business hours, my coverage doesnt always remain constant and at times tests fail if i try to run it on weekends or holidays? Has anyone faced this before? Any suggestions to approach this problem would be very useful. 

Hey,

 

I need to create Partner-Object entries within an APEX class.

Therefore the User needs 'view all data' permissions.

Granting these permissions permanently is not an option.

 

Thats why I'm searching for a way to:

a) switch the user in an APEX class -> runAs() seems to work in TestClasses only,

b) granting permissions within the class

or

c) skip any permission checks for the class / certain calls in the class

 

Any Idea is welcome.

 

 

so long

Stefan