• p.gleixner
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hio!

 

I am writing a apex trigger, wich populates a Asset lookup field in Case when creating one. The trigger searches the database after a matching asset via Data(SystemID) from the Description. Becuase the System ID is not always unique  it can accure that more than 1 Asset is found. This case I want to catch with an Exception.

Now my question:

Is it possible that when the Exception is triggered, instead of printing an error message or write an email, to open up the PopUp Window of the Asset lookup, so the engineer can manually choose wich asset to look for?

If that is not possible (what i am actually excpecting) What other, more elegant possibilities do I have when an exception is triggered?


I hope my question is clear enough.

Thanks alot in advance.

Peter

Hi!


I created a apex trigger wich, among other things, calls following class when a case is created or updated (before insert, before update):

 

public class createAsset {
      
      public static void setAsset(Account acc, Case c, String[] data){
           
//defining variables for the Asset TextFields
        String assetName = data[7]+' - '+data[6];
        String gon = data[5];
        String geSystemId = data[6];
        String installCode = data[10];
        
        Contact con = [SELECT Id, Name FROM Contact WHERE Name =: data[0] limit 1];
        Release__c rel = [SELECT Id, Name FROM Release__c WHERE Name LIKE: data[8]+'%' ORDER BY Name ASC limit 1];
//Creating a new Asset with fields from Descr.
        Asset a = new Asset(AccountId = [SELECT Id FROM Account WHERE Name =: data[3] limit 1].Id,
                           Name = assetName+'_TEST04.1',
                           SF42_GON__c = gon,
                           SF42_GE_System_ID__c = geSystemId,
                           Installation_Code__c = installCode,
                           Optionen__c = data[9],
                           SF42_Release__c = rel.Id,
                           ContactId = [SELECT Id FROM Contact WHERE Name =: data[0] limit 1].Id);
      
//Update/Insert the Asset
          upsert(a);
            
   
    }
}

 

Actually that whole thing works, but the Problem is it creates not one but two similar Assets.

Why is this? Has this anything to do with the trigger? Or with the upsert method?


I hope you can help me again

 

Kind regards

Peter

Hi!

Im trying to build a trigger that automatically adds the correct Account to a Case that was created via email-to-case. The Account name stands in the Description field of the case created by the incoming email.
At the moment I am at the first step. I am simply trying to copy the String of a TextField into the Account LookUp Field.
For Example: The Textfield "Description" says "ACME Corp." Then I want that as the Account(That already exists and can be picked int the lookup field) the Case belongs to.

Here is what I got:


trigger licenseToAssetTrig on Case (before insert, before update) {
    
    for(Case c:trigger.new){
      if(c.Subject == 'ACME Corp'){
        Account accMatch = [SELECT Name FROM Account WHERE Name =: c.Subject];
        c.Account = accMatch;
     }
    }
}

Remeber, its just the first step and I am only trying to change the Case Account to the Account of the Description when I open or update a new case manually

Thanks in advance
Peter

Hi!


I created a apex trigger wich, among other things, calls following class when a case is created or updated (before insert, before update):

 

public class createAsset {
      
      public static void setAsset(Account acc, Case c, String[] data){
           
//defining variables for the Asset TextFields
        String assetName = data[7]+' - '+data[6];
        String gon = data[5];
        String geSystemId = data[6];
        String installCode = data[10];
        
        Contact con = [SELECT Id, Name FROM Contact WHERE Name =: data[0] limit 1];
        Release__c rel = [SELECT Id, Name FROM Release__c WHERE Name LIKE: data[8]+'%' ORDER BY Name ASC limit 1];
//Creating a new Asset with fields from Descr.
        Asset a = new Asset(AccountId = [SELECT Id FROM Account WHERE Name =: data[3] limit 1].Id,
                           Name = assetName+'_TEST04.1',
                           SF42_GON__c = gon,
                           SF42_GE_System_ID__c = geSystemId,
                           Installation_Code__c = installCode,
                           Optionen__c = data[9],
                           SF42_Release__c = rel.Id,
                           ContactId = [SELECT Id FROM Contact WHERE Name =: data[0] limit 1].Id);
      
//Update/Insert the Asset
          upsert(a);
            
   
    }
}

 

Actually that whole thing works, but the Problem is it creates not one but two similar Assets.

Why is this? Has this anything to do with the trigger? Or with the upsert method?


I hope you can help me again

 

Kind regards

Peter

Hi!

Im trying to build a trigger that automatically adds the correct Account to a Case that was created via email-to-case. The Account name stands in the Description field of the case created by the incoming email.
At the moment I am at the first step. I am simply trying to copy the String of a TextField into the Account LookUp Field.
For Example: The Textfield "Description" says "ACME Corp." Then I want that as the Account(That already exists and can be picked int the lookup field) the Case belongs to.

Here is what I got:


trigger licenseToAssetTrig on Case (before insert, before update) {
    
    for(Case c:trigger.new){
      if(c.Subject == 'ACME Corp'){
        Account accMatch = [SELECT Name FROM Account WHERE Name =: c.Subject];
        c.Account = accMatch;
     }
    }
}

Remeber, its just the first step and I am only trying to change the Case Account to the Account of the Description when I open or update a new case manually

Thanks in advance
Peter