• 1ne-Up
  • NEWBIE
  • 5 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hello,

 

I am fairly new to APEX and have recently ran into an error when trying to do a mass upload using dataloader.  I have found that the error is because I have an IF statement within a FOR loop and was hoping someone could help me take the IF statement out with different logic?  My code is below and I have highlighted the IF statement in red that is looping through.  Thanks in advance.

 

 

trigger ImplementationCaseforIntegrationProducts on Opportunity (after insert, after update) {

string recordtype = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Implementation').getRecordTypeId();
List<Case> cases = new List<Case>();
List<Task> tasksList = new List<Task>();
for (Opportunity opp: Trigger.New){
case newcase= new case();
if(opp.AccountId != null){
Account a = [select id,name,Closed__c,ImplementationCaseCreated__c,Implementation_Specialist__c from Account where id =: opp.AccountId limit 1]; //This line more than enough to check in common, because if account id in opportunity is not null means only one value going to be there.

if((trigger.isInsert && (opp.StageName.toLowerCase().equals('closed won'))&&(opp.Type.toLowerCase().equals('adjustment'))&& opp.Integration_Product_Attached__c == True)||
(trigger.isUpdate && (opp.StageName != Trigger.oldMap.get(opp.Id).StageName && opp.StageName.toLowerCase().equals('closed won'))&&(opp.Type.toLowerCase().equals('adjustment')) && opp.Integration_Product_Attached__c == True))
{
if ((a.Closed__c == TRUE && a.implementationcasecreated__c == TRUE) || (a.ImplementationCaseCreated__c == False)){
newcase.AccountId=opp.AccountId;
newcase.Opportunity__c=opp.Id;
newcase.Subject='New Implementation case for '+opp.Account_Name__c;
newcase.Status='New';
newcase.Origin='Sign Up Form';
newcase.Priority='Medium';
newcase.RecordTypeId=recordtype;
newcase.Billing_Email__c = opp.Billing_Email__c;
newcase.ContactID = opp.PrimaryContactID__c;
cases.add(newcase);
}
else{
Task t = new Task(ownerId = a.Implementation_Specialist__c, Subject = 'Integration Sale', status = 'Not Started',
Priority = 'High', whatID = opp.Accountid, ActivityDate = Date.Today()); //You can change values accordingly
tasksList.add(t);
}
}
}
}

if(cases.size() > 0){
insert cases;
}
if(tasksList.size() > 0){
insert tasksList;
}
}

Hi,

 

I am a complete newbie to Apex triggers so hopefully someone can help.

 

CURRENT SITUATION:

Each day our SF org auto-imports Account records plus their related Account Team members (added to AccountTeamMember object) from an external source. When each related Account Team member is inserted it also automatically creates a record in the AccountShare table. This table has 3 "AccessLevel" fields that are given the following values:

 - AccountAccessLevel = 'Read'

 - OpportunityAccessLevel = 'None'

 - CaseAccessLevel = 'None'

* Note - These 3 values are set by default from our OWD settings which are Account, Opportunity and Private all = 'Private' and it has to stay this way.

 

PROBLEM:

But I need these 3 fields to have the following values:

 - AccountAccessLevel = 'Edit'

 - OpportunityAccessLevel = 'Read'

 - CaseAccessLevel = Edit'

 

DAILY MANUAL WORK-AROUND:

What I do then each day to fix the problem is export any newly inserted records (via apex data loader) to a CSV file using this query:

 

   Select Id, AccountAccessLevel, OpportunityAccessLevel,

   CaseAccessLevel FROM AccountShare WHERE RowCause in ('Team') AND

   LastModifiedById in ('00590000001CEQQAA4') AND AccountAccessLevel in

   ('Read') AND CaseAccessLevel in ('None') AND OpportunityAccessLevel in ('None')

 

Then I manually change the 3 AccessLevel values in the CSV file to the values that  I need them to be (ie 'Edit' 'Read' 'Edit') and then I update the records back into SF using the apex data loader.

 

APEX TRIGGER FIX?:

How would I write an Apex Trigger that does this update on insert automatically whenever a record is inserted into the AccountShare object  from the external source (ie LastModifiedById in ('00590000001CEQQAA4') ) and thus allow me to avoid doing this daily manual "export>modify>import" work-around?

 

Regards,

 

Matt

  • December 11, 2013
  • Like
  • 0

So we're using the apex-lang libraries (http://code.google.com/p/apex-lang/) which has its own set of test classes.

 

When we do a "run all tests", it passes fine, but when we try to deploy some of our own classes, the deployment fails in those apex-lang test classes with :-

 

Failure Message: "System.Exception: null", Failure Stack Trace: "External entry point"

 

Anyone got any ideas on how we get out of this one?