Skip to main content
Became Hot Network Question
added 13 characters in body
Source Link
David Reed
  • 93.7k
  • 14
  • 90
  • 166

today I signed in on SF Stackexchange and I'm a newbie on Apex.

1 retry: This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update) { for(Complaints__c Complaint : Trigger.new) {

trigger ComplaintInitialize on Complaints__c (before insert, before update)
{
  for(Complaints__c Complaint : Trigger.new)
  {

    if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
    {
       Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
       If(String.isBlank(Complaint.Case__c) == false)
       {
          Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                    Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                    Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
          Complaint.Employee__c = C.OwnerId;
          User KB = [select Id from User where LastName = :'ComplaintOffice'];
          Complaint.OwnerID = KB.id;
          User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
          User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
          Complaint.Complaint_Handler__c = TL.Id;

so far so good

but herhere I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c

Illegal assignment from List<PeriodOfTime__c> to Complaints__c

at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part? (The 'Limit 1' is not nescesserynecessary because there is only 1 record in the database with date of today)

today I signed in on SF Stackexchange and I'm a newbie on Apex.

1 retry: This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update) { for(Complaints__c Complaint : Trigger.new) {

if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
{
   Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
   If(String.isBlank(Complaint.Case__c) == false)
   {
      Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
      Complaint.Employee__c = C.OwnerId;
      User KB = [select Id from User where LastName = :'ComplaintOffice'];
      Complaint.OwnerID = KB.id;
      User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
      User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
      Complaint.Complaint_Handler__c = TL.Id;

so far so good

but her I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part? (The 'Limit 1' is not nescessery because there is only 1 record in the database with date of today)

This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update)
{
  for(Complaints__c Complaint : Trigger.new)
  {

    if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
    {
       Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
       If(String.isBlank(Complaint.Case__c) == false)
       {
          Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                    Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                    Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
          Complaint.Employee__c = C.OwnerId;
          User KB = [select Id from User where LastName = :'ComplaintOffice'];
          Complaint.OwnerID = KB.id;
          User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
          User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
          Complaint.Complaint_Handler__c = TL.Id;

so far so good

but here I got stuck:

Illegal assignment from List<PeriodOfTime__c> to Complaints__c

at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part? (The 'Limit 1' is not necessary because there is only 1 record in the database with date of today)

added 100 characters in body
Source Link

today I signed in on SF Stackexchange and I'm a newbie on Apex.

1 retry: This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update) { for(Complaints__c Complaint : Trigger.new) {

if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
{
   Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
   If(String.isBlank(Complaint.Case__c) == false)
   {
      Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
      Complaint.Employee__c = C.OwnerId;
      User KB = [select Id from User where LastName = :'ComplaintOffice'];
      Complaint.OwnerID = KB.id;
      User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
      User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
      Complaint.Complaint_Handler__c = TL.Id;

so far so good

but her I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part? (The 'Limit 1' is not nescessery because there is only 1 record in the database with date of today)

today I signed in on SF Stackexchange and I'm a newbie on Apex.

1 retry: This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update) { for(Complaints__c Complaint : Trigger.new) {

if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
{
   Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
   If(String.isBlank(Complaint.Case__c) == false)
   {
      Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
      Complaint.Employee__c = C.OwnerId;
      User KB = [select Id from User where LastName = :'ComplaintOffice'];
      Complaint.OwnerID = KB.id;
      User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
      User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
      Complaint.Complaint_Handler__c = TL.Id;

so far so good

but her I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part?

today I signed in on SF Stackexchange and I'm a newbie on Apex.

1 retry: This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update) { for(Complaints__c Complaint : Trigger.new) {

if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
{
   Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
   If(String.isBlank(Complaint.Case__c) == false)
   {
      Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
      Complaint.Employee__c = C.OwnerId;
      User KB = [select Id from User where LastName = :'ComplaintOffice'];
      Complaint.OwnerID = KB.id;
      User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
      User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
      Complaint.Complaint_Handler__c = TL.Id;

so far so good

but her I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part? (The 'Limit 1' is not nescessery because there is only 1 record in the database with date of today)

deleted 225 characters in body
Source Link

My User story1 retry: Uptill know we used an MS Access application for complaint registration/handling. Because we want to get rid of MS Access applications I created an object in SF called Complaints__c. Creating a task for the complaint handler, sending him/her an email that a complaint is assigned to him/her and logging that email on the activity timeline works great. Notification by email on task creation This is usually switched by our users sowhat I forced sending an email and adding it to the activity line)have:

Last thing I want to do is auto fill the deadline. When a new complaint is registered, the complaint handler has to do a follow up before the Deadline that is set when de complaint is registerd. The Deadline can depend on 2 values in another field, let's say Option: option 1, Option 2 If Option 1 is chosen, the Deadline is different then when option 2 was chosen. I have a second Custom object Called PeriodOfTime__c that contains Id, Name, Date__c, Option1Date__c, Option2Date__c. On registration I would like use an apex trigger to fillComplaintInitialize on Complaints__c (before insert) the field Deadline__c in my Complaints__c object with the value of Option1Date__c or Option2Date__c from the Object PeriodOfTime__c where PeriodOfTime__c.Date__c = date.today(, before update) I stored these dates in this table to make sure that Option1Date__c and Option2Date__c are never a saterday, sunday or a special day, like Christmas.{ I would like to get something likefor(Complaints__c Complaint : Trigger.new) {

Ifif(OptionComplaint.RecordType_Name__c == 'ComplaintInitialize')
{
   Id recordTypeId = OptionSchema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
 1  If(String.isBlank(Complaint.Case__c) == false)
   {
      Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Deadline__cCase__c ];
      Complaint.Employee__c = OptionDate1;}C.OwnerId;
Else      User KB = [select Id from User where LastName = :'ComplaintOffice'];
  {    Complaint.Deadline__cOwnerID = OptionDate2;}KB.id;

Getting user info like:

      User H = [select Id, Email, Department, Division from User where Id =: 'someC.OwnerId];
 userID'];     User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
      Complaint.Complaint_Handler__c = TL.Id;

is easyso far so good

but getting Option1Date__c and Option2Date__c fromher I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c at line....

[select      Complaints__c DT = [Select Id, Option1Date__cDate__c, Option2Date__cFirstContactDate__c, FirstContactDateAAV__c from PeriodeOfTime__cPeriodOfTime__c whereWhere Date__c =: date.today()] LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

doesn't seem to work the same way on a custom object. Can anyone help me how to do this. I guess it must be something with list or set byWhat am I can't figger out how. Thanxdoing wrong in the last part?

My User story: Uptill know we used an MS Access application for complaint registration/handling. Because we want to get rid of MS Access applications I created an object in SF called Complaints__c. Creating a task for the complaint handler, sending him/her an email that a complaint is assigned to him/her and logging that email on the activity timeline works great. Notification by email on task creation is usually switched by our users so I forced sending an email and adding it to the activity line)

Last thing I want to do is auto fill the deadline. When a new complaint is registered, the complaint handler has to do a follow up before the Deadline that is set when de complaint is registerd. The Deadline can depend on 2 values in another field, let's say Option: option 1, Option 2 If Option 1 is chosen, the Deadline is different then when option 2 was chosen. I have a second Custom object Called PeriodOfTime__c that contains Id, Name, Date__c, Option1Date__c, Option2Date__c. On registration I would like use an apex trigger to fill (before insert) the field Deadline__c in my Complaints__c object with the value of Option1Date__c or Option2Date__c from the Object PeriodOfTime__c where PeriodOfTime__c.Date__c = date.today() I stored these dates in this table to make sure that Option1Date__c and Option2Date__c are never a saterday, sunday or a special day, like Christmas. I would like to get something like:

If(Option = Option 1)
  {Complaint.Deadline__c = OptionDate1;}
Else  
  {Complaint.Deadline__c = OptionDate2;}

Getting user info like:

User H = [select Id, Email, Department, Division from User where Id =: 'some userID'];

is easy but getting Option1Date__c and Option2Date__c from:

[select Id, Option1Date__c, Option2Date__c from PeriodeOfTime__c where Date__c =: date.today()]

doesn't seem to work the same way on a custom object. Can anyone help me how to do this. I guess it must be something with list or set by I can't figger out how. Thanx

1 retry: This is what I have:

trigger ComplaintInitialize on Complaints__c (before insert, before update) { for(Complaints__c Complaint : Trigger.new) {

if(Complaint.RecordType_Name__c == 'ComplaintInitialize')
{
   Id recordTypeId = Schema.SObjectType.Complaints__c.getRecordTypeInfosByDeveloperName().get('ComplaintOffice').getRecordTypeId();
   If(String.isBlank(Complaint.Case__c) == false)
   {
      Case C = [Select Id, OwnerId, ContactId, Intermediary__c, Polisnummer_lookup__c, Account.FirstName, Account.LastName, 
                Contact.First_Name__c, Contact.LastName, Contact.MailingStreet, Contact.MailingPostalCode, Contact.MailingCity, 
                Contact.Gender__c, Contact.Phone, Contact.Email from Case Where Id =: Complaint.Case__c ];
      Complaint.Employee__c = C.OwnerId;
      User KB = [select Id from User where LastName = :'ComplaintOffice'];
      Complaint.OwnerID = KB.id;
      User H = [select Id, Email, Department, Division from User where Id =: C.OwnerId];
      User TL = [Select Id from User Where Department =: H.Department AND IsActive =: true AND Function__c =: 'Complaint_Handler' LIMIT 1];
      Complaint.Complaint_Handler__c = TL.Id;

so far so good

but her I got stuck: Illegal assignment from List<PeriodOfTime__c> to Complaints__c at line....

      Complaints__c DT = [Select Id, Date__c, FirstContactDate__c, FirstContactDateAAV__c from PeriodOfTime__c Where Date__c =: date.today() LIMIT 1];
      If(Complaint.Received_by__c == 'Complaint coordinator AAV')
          {Complaint.Deadline__c = DT.FirstContactDateAAV__c;}
      else
          {Complaint.Deadline__c = DT.FirstContactDate__c;}

What am I doing wrong in the last part?

added 18 characters in body
Source Link
Keith C
  • 137.3k
  • 29
  • 218
  • 458
Loading
added 19 characters in body
Source Link
Keith C
  • 137.3k
  • 29
  • 218
  • 458
Loading
edited body
Source Link
Loading
added 617 characters in body
Source Link
Loading
Source Link
Loading