I have written an Apex class for changing the Quote owner as the Opportunity owner for Profile named 'TriLink Sales & Service'. I have called this class class in Trigger. But it is throwing 'Apex trigger changeOwner caused an unexpected exception, contact your administrator: changeOwner: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.changeOwnerClass.changeOwner: line 7, column 1' error.
APEX CODE:
public class changeOwnerClass{
public list<Opportunity> lstOpp ;
public void changeOwner(list<Quote> lstQuote){
Profile p = [select id,Name from Profile where id=:Userinfo.getProfileid()];
System.debug(p);
for (Opportunity opp : lstOpp){
for(Quote objQuote : lstQuote){
if(p.Name == 'TriLink Sales & Service' || p.Name!= 'TriLink GMP'){
objQuote.OwnerId = opp.OwnerId;
System.debug(opp.OwnerId);
System.debug(objQuote.OwnerId);
}}
}
}
}
TRIGGER:
trigger changeOwner on Quote (before insert) { changeOwnerClass clsChangeOwner = new changeOwnerClass ();
if(trigger.isInsert && trigger.isBefore){ clsChangeOwner.changeOwner(trigger.new); } }
Please help me to solve this error.