You need to sign in to do that
Don't have an account?
Azusfdc
Getting error System.NullPointerException: Attempt to de-reference a null object: how to resolve this below is the code ?
public class Helperclass { public static void user_coninsertupdated() { } public static void oppnameupdatewithacnamelastmodifyclsdate(List<Opportunity> opp) { set<id> accountid=new set<id>(); set<id> ownerid=new set<id>(); string opname; for(opportunity opp1:opp) { accountid.add(opp1.accountid); ownerid.add(opp1.ownerid); } map<id,account> accmap=new map<id,account> ([select id,name from account where id in:accountid]); map<id,user> usermap=new map<id,user> ([select id,lastmodifiedby.name from user where id in:ownerid]); for(opportunity opp2:opp) { opname=accmap.get(opp2.accountid).name+' '+opp2.closedate+' '+usermap.get(opp2.ownerid).lastmodifiedby.name; if(opp2!=null) opp2.name=opname; } } }
trigger accnameclsdatemodifydate on Opportunity (before insert,before update) { if(trigger.isbefore && trigger.isinsert) { Helperclass.oppnameupdatewithacnamelastmodifyclsdate(trigger.new); } if(trigger.isbefore && trigger.isupdate) { Helperclass.oppnameupdatewithacnamelastmodifyclsdate(trigger.new); } }
Let us know if this will help you
Please find the below modified code:
Here I modified / followed:
(1) Naming Convention.
(2) Alignment.
(3) Bulkified the code.
(4) Corrected the logic
(5) Also tested the code in my DE environment and everything looks good.
Apex Class:
Trigger:
Also go through the below links for understanding the Apex Code:
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex1_2.htm
https://developer.salesforce.com/page/Apex_Code:_The_World's_First_On-Demand_Programming_Language
https://www.quora.com/What-is-the-best-method-to-learn-Salesforce-com-product-s-Apex-code
http://www.slideshare.net/EdwinOstos/introduction-to-apex-code
https://www.youtube.com/watch?v=Azb31kE31ZA
Please do let me know if it helps you.
Regards,
Mahesh