You need to sign in to do that
Don't have an account?

Help with Trigger
Hi Everyone,
I am stuck on a trigger. I want this to populate the Inside Sales Representative on the record being saved. However I am getting an error:
Review all error messages below to correct your data.
Apex trigger OpportunityISR caused an unexpected exception, contact your administrator: OpportunityISR: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityISR: line 5, column 1
Here is the Trigger Code:
trigger OpportunityISR on Opportunity (before insert){
Opportunity oppty;
Set<Id> OpptyId= new Set<Id>();
if(oppty.Inside_Sales_Representative__c == null) {
oppty.Inside_Sales_Representative__c = Userinfo.getUserId();
System.debug('Setting Sales Representative to ' + Userinfo.getUserId());
} else {
if(Trigger.isInsert) {
oppty.Inside_Sales_Representative__c = Userinfo.getUserId();
System.debug('Setting Opportunity Owner to ' + Userinfo.getUserId());
}
}
}
I am stuck on a trigger. I want this to populate the Inside Sales Representative on the record being saved. However I am getting an error:
Review all error messages below to correct your data.
Apex trigger OpportunityISR caused an unexpected exception, contact your administrator: OpportunityISR: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityISR: line 5, column 1
Here is the Trigger Code:
trigger OpportunityISR on Opportunity (before insert){
Opportunity oppty;
Set<Id> OpptyId= new Set<Id>();
if(oppty.Inside_Sales_Representative__c == null) {
oppty.Inside_Sales_Representative__c = Userinfo.getUserId();
System.debug('Setting Sales Representative to ' + Userinfo.getUserId());
} else {
if(Trigger.isInsert) {
oppty.Inside_Sales_Representative__c = Userinfo.getUserId();
System.debug('Setting Opportunity Owner to ' + Userinfo.getUserId());
}
}
}
Hope the code above solves the issue
All Answers
Hope the code above solves the issue