• Mike@Mungos
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 11
    Replies
Hi,

I am trying to create a custom button on a custom object which can only be clicked if a date on the parent oject is filled in.  I am new to SOQL and javascript but have managed to created custom buttons in the past with validation rules which related to the object they are on however I am struggling with cross object rules.

In this instance an Assessment__c can only be submitted if it's parent Referral__c has an accepted date that is not blank.

Any help would be very much apprecitated.

Here is the code so far:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var ReferraAccepted = "SELECT Accepted_date__c FROM Referral__c WHERE Name = '{!Assessment__c.Referral__c}' LIMIT 1";

if (ReferraAccepted == null){alert ("Please submit the completed referral form to the Clearing House as this form cannot be submitted on it's own.")} 

else {

var newRecords = []; 
var c = new sforce.SObject("Assessment__c"); 
c.id ="{! Assessment__c.Id }"; 
c.Submit_for_assessment__c = true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();
}
 
Hi 

I am attempting to write a Test Class for a trigger I wrote.  However, I keep getting the following errors, "TriggerTest2.validateUpdateBedspaceWithNewNomTen(), Details: System.QueryException: List has no rows for assignment to SObject Class.TriggerTest2.validateUpdateBedspaceWithNewNomTen: line 6, column 1" and  "System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.TriggerTest2.validateUpdateBedspaceWithNewNomTen: line 6, column 1".  Can anyone help me to figure out where I've gone wrong?

@isTest
Private class TriggerTest2 {
   
    static testMethod void validateUpdateBedspaceWithNewNomTen() {
     
      String rtBed = [SELECT Id FROM RecordType WHERE DeveloperName = 'Bedspace' AND SobjectType = 'Bedspace__c' LIMIT 1].Id;
      Bedspace__c ref = new Bedspace__c(Scheme__c = 'a052000000Hcpg2', RecordTypeId = rtBed); 
    insert ref;
     
      ref = [SELECT Id, Current_nomination_tenancy__c FROM Bedspace__c WHERE Id =:ref.Id];
     
      String rtNom = [SELECT Id FROM RecordType WHERE DeveloperName = 'Nomination_Tenancy' AND SobjectType = 'Nomination_Tenancy__c' LIMIT 1].Id;
      Nomination_Tenancy__c ra = new Nomination_Tenancy__c(Bedspace__c = ref.Id, Client__c = 'a052000000Hcpg2', RecordTypeId = rtNom); 
    insert ra;
   
    ref = [SELECT Id, Current_nomination_tenancy__c FROM Bedspace__c WHERE Id =:ref.Id];
   
    System.assertEquals(ref.Current_nomination_tenancy__c, ra.Id);
    } 

}

Many Thanks,

Mike
Hi

I am trying to write a trigger that will update the lookup field called Most_recent_nomination_tenancy__c field on a custom object called Referral__c when a new Nomination/Tenancy is created.  However at present rather than updating the field with the name of the new Nomination/Tenancy it is turning the field blank.   Does anyone know why this trigger is turning the field blank and not updating it?

trigger UpdateReferralWithNewNomTen on Nomination_Tenancy__c (before insert, before update) {

  for(Nomination_Tenancy__c newRecord : Trigger.new)  {        
      Referral__c Referral = [Select Id, Most_recent_nomination_tenancy__c from Referral__c WHERE Id = :newRecord.Referral__c ];
        Referral.Most_recent_nomination_tenancy__c = newRecord.Name;
        update Referral;               
    }

}

Many Thanks,

Mike
Hi,

I am trying to create a custom button on a custom object which can only be clicked if a date on the parent oject is filled in.  I am new to SOQL and javascript but have managed to created custom buttons in the past with validation rules which related to the object they are on however I am struggling with cross object rules.

In this instance an Assessment__c can only be submitted if it's parent Referral__c has an accepted date that is not blank.

Any help would be very much apprecitated.

Here is the code so far:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var ReferraAccepted = "SELECT Accepted_date__c FROM Referral__c WHERE Name = '{!Assessment__c.Referral__c}' LIMIT 1";

if (ReferraAccepted == null){alert ("Please submit the completed referral form to the Clearing House as this form cannot be submitted on it's own.")} 

else {

var newRecords = []; 
var c = new sforce.SObject("Assessment__c"); 
c.id ="{! Assessment__c.Id }"; 
c.Submit_for_assessment__c = true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();
}
 
Hi 

I am attempting to write a Test Class for a trigger I wrote.  However, I keep getting the following errors, "TriggerTest2.validateUpdateBedspaceWithNewNomTen(), Details: System.QueryException: List has no rows for assignment to SObject Class.TriggerTest2.validateUpdateBedspaceWithNewNomTen: line 6, column 1" and  "System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.TriggerTest2.validateUpdateBedspaceWithNewNomTen: line 6, column 1".  Can anyone help me to figure out where I've gone wrong?

@isTest
Private class TriggerTest2 {
   
    static testMethod void validateUpdateBedspaceWithNewNomTen() {
     
      String rtBed = [SELECT Id FROM RecordType WHERE DeveloperName = 'Bedspace' AND SobjectType = 'Bedspace__c' LIMIT 1].Id;
      Bedspace__c ref = new Bedspace__c(Scheme__c = 'a052000000Hcpg2', RecordTypeId = rtBed); 
    insert ref;
     
      ref = [SELECT Id, Current_nomination_tenancy__c FROM Bedspace__c WHERE Id =:ref.Id];
     
      String rtNom = [SELECT Id FROM RecordType WHERE DeveloperName = 'Nomination_Tenancy' AND SobjectType = 'Nomination_Tenancy__c' LIMIT 1].Id;
      Nomination_Tenancy__c ra = new Nomination_Tenancy__c(Bedspace__c = ref.Id, Client__c = 'a052000000Hcpg2', RecordTypeId = rtNom); 
    insert ra;
   
    ref = [SELECT Id, Current_nomination_tenancy__c FROM Bedspace__c WHERE Id =:ref.Id];
   
    System.assertEquals(ref.Current_nomination_tenancy__c, ra.Id);
    } 

}

Many Thanks,

Mike
Curious what the best approach is to replace custom buttons that are currently using OnClick Javascript or URL since they are no longer supported when switching to Lightning Experience. Is it best to replace the classic buttons by building a new buton using the Lightning Design System framework within Lightning components and then adding to the page layout?
Hi,

I am trying to create a custom button on a custom object which can only be clicked if a date on the parent oject is filled in.  I am new to SOQL and javascript but have managed to created custom buttons in the past with validation rules which related to the object they are on however I am struggling with cross object rules.

In this instance an Assessment__c can only be submitted if it's parent Referral__c has an accepted date that is not blank.

Any help would be very much apprecitated.

Here is the code so far:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var ReferraAccepted = "SELECT Accepted_date__c FROM Referral__c WHERE Name = '{!Assessment__c.Referral__c}' LIMIT 1";

if (ReferraAccepted == null){alert ("Please submit the completed referral form to the Clearing House as this form cannot be submitted on it's own.")} 

else {

var newRecords = []; 
var c = new sforce.SObject("Assessment__c"); 
c.id ="{! Assessment__c.Id }"; 
c.Submit_for_assessment__c = true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.reload();
}
 
Hi

I am trying to write a trigger that will update the lookup field called Most_recent_nomination_tenancy__c field on a custom object called Referral__c when a new Nomination/Tenancy is created.  However at present rather than updating the field with the name of the new Nomination/Tenancy it is turning the field blank.   Does anyone know why this trigger is turning the field blank and not updating it?

trigger UpdateReferralWithNewNomTen on Nomination_Tenancy__c (before insert, before update) {

  for(Nomination_Tenancy__c newRecord : Trigger.new)  {        
      Referral__c Referral = [Select Id, Most_recent_nomination_tenancy__c from Referral__c WHERE Id = :newRecord.Referral__c ];
        Referral.Most_recent_nomination_tenancy__c = newRecord.Name;
        update Referral;               
    }

}

Many Thanks,

Mike