• T-S.com
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 7
    Replies

Hi all,

 

I'm pretty new to SFDC development and I need to bulkify following trigger. I've checked multiple resources, but couldn't move forward. :(  Every help will be highly appreciated!

 

Regs

 

---------------------------------

 

trigger BI_Rental_CheckAssetStatus on Rental__c (before insert) {

// Disables to rent assets with other status than Available.

    for(Rental__c myRental : trigger.new){

        Asset__c myAsset = [SELECT status__c FROM Asset__c WHERE Id = :myRental.Asset__c];
    
        if(myAsset.status__c != 'Available'){
            myRental.addError('You cannot borrow asset, which has a different status than Available. Current asset status is ' + myAsset.status__c + '.');
        }

    }

}

 

---------------------------------

Is it possible to retrieve values for Picklist object from SFDC by Android SDK / REST or SOQL? 

Hello, 

 

I've written a test class for my trigger, but it doesn't work correctly because it always references a null object.

 

@isTest

private class Trigger_Test{

static testMethod void testInsert() {

Object1__c myObject1 = new Object1__c (name = '123', status__c = 'A');
Object2__c myObject2 = new Object2__c (name = 'John Doe');
Object3__c myObject3 = new Object3__c(Object1__c = myObject1.Id, Object2__c = myObject2.Id, date__c = datetime.now()); // should launch trigger that changes myObject1.status__c = 'X'

insert myObject1;
insert myObject2;

System.debug('Object3 name ' + myObject3.name + ' Object1 ' + myObject3.Object1__c + ' Object2 ' + myObject3.Object2__c);

insert myObject3;

System.assertEquals('X', [SELECT status__c FROM Object1__c WHERE id =: myObject1.id].status__c);

}

}

 

 

Already the system debug displays that myObject3 doesn't exist (all references are null) and assert then naturally fails.

 

Thanks in advance for any help!