• cdavis@elt.com
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 10
    Replies
trigger Touch_Imp on User (after insert) {
if(trigger.isInsert){
    Set<String> usercontactid = new Set<String>();
    for (User u : Trigger.new) {
        usercontactid.add(u.contactid);
    }
    if([SELECT COUNT() FROM implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid]>0){
        Implementation__c[] updateimp = [SELECT id from Implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid];
        Database.update(updateimp);
    }
}
}

 Above is my current code. But I get an error message about updaing a setup object and non-setup object at the same time when I try to create a user record now. I believe I need to use the future command to fix this, but I have no idea how. I'm pretty new to apex coding and I'm really hoping you guys can give me a step by step on how to accomplish this task.

 

More Info (background on what I'm trying to do):

  I'm trying to get my triggers on my Imp object to fire after my new user is created. The only way I know how to do that is to update the Imp record after the User record is updated. If there is a better way to accomplish this, please let me know! If I can supply any more needed information, just ask and I'll see what I can stir-up.

 

Thanks for reading, and hopefully helping :smileyhappy:

Error: Compile Error: Illegal assignment from LIST<AggregateResult> to Date at line 9 column 7

 

trigger update_expiry_date on opportunity (after insert, after update) {
if (trigger.isUpdate) {
  List<Opportunity> opptemp = new List<Opportunity>();
  for(Opportunity o : trigger.new){
    String oppid = o.id;
    if ([SELECT COUNT(license_term_end__c) FROM opportunitylineitem WHERE opportunityid = :oppid] > 0) {
      String accid = o.accountid;
      Account updateacc = [SELECT id, expiry_date_2__c FROM account WHERE id = :accid];
      updateacc.expiry_date_2__c = [SELECT MAX(license_term_end__c) FROM opportunitylineitem WHERE opportunityid =:oppid];
      Database.update(updateacc);
      }
    }
  }
}

 Both of the fields expiry_date_2__c and license_term_end__c are date fields. Does the Max command just not work on this. That could be it I suppose. Please help thanks. I'm pretty much just trying to do a max roll-up and have it write the value to the date field expiry_date_2__c.

 

Thanks!!!

I have seen some forum saying to use @future to get around this, but I'm not sure how to accomplish that

Below is my trigger, it is short and sweet (well at least I think so). Please have a look and let me know how to fix this.

Thanks!!!!

trigger Touch_Imp on User (after insert) {
if(trigger.isInsert){
    Set<String> usercontactid = new Set<String>(); 
    for (User u : Trigger.new) {
        usercontactid.add(u.contactid);
    }
    if([SELECT COUNT() FROM implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid]>0){
        Implementation__c[] updateimp = [SELECT id from Implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid];
        Database.update(updateimp);
    }
}
}

 

Can anyone give me a Test Class for this? I don't yet understand Test Classes.

 

trigger Share_Imp_Contact on Implementation__c (after insert, before update) {
if(trigger.isUpdate){
    Set<String> impIds = new Set<String>();
    for (Implementation__c imp : Trigger.new) {
        impIds.add(imp.Id);
    }
    Implementation__Share[] doomedSharing = [select id, RowCause from Implementation__Share where Implementation__Share.ParentId IN :impIds and RowCause = 'Customer_Portal__c']; 
    Database.delete(doomedSharing);
}
List<Implementation__Share> implementationShares = new List<Implementation__Share>();
  for(Implementation__c implementation : trigger.new){
    Implementation__Share impAccountShare = new Implementation__Share();
    impAccountShare.ParentId = Implementation.Id;
        String ImpContact = Implementation.Implementation_Contact__c;
        if(ImpContact != NULL){
        if([SELECT COUNT() FROM User WHERE contactid = :ImpContact]>0){
        String ImpUserId = [SELECT Id FROM User WHERE contactid = :ImpContact].Id;
    impAccountShare.UserOrGroupId = ImpUserId;
    impAccountShare.AccessLevel = 'edit';
    impAccountShare.RowCause = Schema.Implementation__Share.RowCause.Customer_Portal__c;
    implementationShares.add(impAccountShare);
    }}}
  Database.SaveResult[] implementationShareInsertResult = Database.insert(implementationShares,false);
}

I have 2 more triggers I'm trying to get up, but i'm sure I can figure those out if someone helps me with these.

I have been scourging the forums and I have found some examples, but I'm having problems following them and relateing them back to mine.

This does work in my sandbox.

trigger Touch_Imp on User (after insert) {
if(trigger.isInsert){
    Set<String> usercontactid = new Set<String>();
    for (User u : Trigger.new) {
        usercontactid.add(u.contactid);
    }
    if([SELECT COUNT() FROM implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid]>0){
        Implementation__c[] updateimp = [SELECT id from Implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid];
        Database.update(updateimp);
    }
}
}

 Above is my current code. But I get an error message about updaing a setup object and non-setup object at the same time when I try to create a user record now. I believe I need to use the future command to fix this, but I have no idea how. I'm pretty new to apex coding and I'm really hoping you guys can give me a step by step on how to accomplish this task.

 

More Info (background on what I'm trying to do):

  I'm trying to get my triggers on my Imp object to fire after my new user is created. The only way I know how to do that is to update the Imp record after the User record is updated. If there is a better way to accomplish this, please let me know! If I can supply any more needed information, just ask and I'll see what I can stir-up.

 

Thanks for reading, and hopefully helping :smileyhappy:

I have seen some forum saying to use @future to get around this, but I'm not sure how to accomplish that

Below is my trigger, it is short and sweet (well at least I think so). Please have a look and let me know how to fix this.

Thanks!!!!

trigger Touch_Imp on User (after insert) {
if(trigger.isInsert){
    Set<String> usercontactid = new Set<String>(); 
    for (User u : Trigger.new) {
        usercontactid.add(u.contactid);
    }
    if([SELECT COUNT() FROM implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid]>0){
        Implementation__c[] updateimp = [SELECT id from Implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid];
        Database.update(updateimp);
    }
}
}

 

Can anyone give me a Test Class for this? I don't yet understand Test Classes.

 

trigger Share_Imp_Contact on Implementation__c (after insert, before update) {
if(trigger.isUpdate){
    Set<String> impIds = new Set<String>();
    for (Implementation__c imp : Trigger.new) {
        impIds.add(imp.Id);
    }
    Implementation__Share[] doomedSharing = [select id, RowCause from Implementation__Share where Implementation__Share.ParentId IN :impIds and RowCause = 'Customer_Portal__c']; 
    Database.delete(doomedSharing);
}
List<Implementation__Share> implementationShares = new List<Implementation__Share>();
  for(Implementation__c implementation : trigger.new){
    Implementation__Share impAccountShare = new Implementation__Share();
    impAccountShare.ParentId = Implementation.Id;
        String ImpContact = Implementation.Implementation_Contact__c;
        if(ImpContact != NULL){
        if([SELECT COUNT() FROM User WHERE contactid = :ImpContact]>0){
        String ImpUserId = [SELECT Id FROM User WHERE contactid = :ImpContact].Id;
    impAccountShare.UserOrGroupId = ImpUserId;
    impAccountShare.AccessLevel = 'edit';
    impAccountShare.RowCause = Schema.Implementation__Share.RowCause.Customer_Portal__c;
    implementationShares.add(impAccountShare);
    }}}
  Database.SaveResult[] implementationShareInsertResult = Database.insert(implementationShares,false);
}

I have 2 more triggers I'm trying to get up, but i'm sure I can figure those out if someone helps me with these.

I have been scourging the forums and I have found some examples, but I'm having problems following them and relateing them back to mine.

This does work in my sandbox.