- ra811.3921220580267847E12
- NEWBIE
- 119 Points
- Member since 2014
-
ChatterFeed
-
3Best Answers
-
1Likes Received
-
0Likes Given
-
5Questions
-
39Replies
System.NullPointerException: Attempt to de-reference a null object
Hi,
I'm adding a field from a parent object on one of our apex classes and one the corresponding visualforce page. When I am navigating to the visualforce page I checked the error message "System.NullPointerException: Attempt to de-reference a null object".
The error seems to be coming from line 620 on the apex class -
offerSiteObj.Offer__r.End_Date__c = offerSiteList[0].Offer__r.End_Date__c;
But I can't see whats wrong with this - this is to allow the user to enter a value and then when they save it will save the value on the field on the parent object.
The field is then referenced on the vf page as:
<apex:inputField value="{!offerSiteList[0].Offer__r.End_Date__c}"/>
Does anyone know what is wrong here? Am I unable to reference a field from a parent object here?
Any help is much appreciated.
-
- RadDude89
- March 30, 2015
- Like
- 0
- Continue reading or reply
Mass Emailing trigger sending email out 5 times - Please help - Urgent
I have a trigger which I have wrriten to send emails to all the contacts that are the children of an account which a custom object record (service__c) is also the child of. The code is designed to trigger upon Last_emails_Sent (picklist) change. The picklist is changed from a time based work flow rule with rule criteria of '(Service: Service NameEQUALSIntensive Property Coaching) AND (Service: Start of ServiceNOT EQUAL TOnull)'. It updates the picklist at (40 days before end of service support, 1 hour before end of service support, 120 days after sstart of service and 240 days after start of service). For some reason, upon reviewing my mass email, 5 accounts came to expiry today and at 11pm last night, 5 emaiils were sent out to each associated contact.
I am not sure what has caused this problem, any help would be very much appreciated. Particular to do with whether this is due to the time based workflow or the trigger. Thank you in advance for any hel that you may give me. Below is my code:
rigger SendEmailtocontact on Service__c (after Update) { List<String> lcontactEmails = new List<String>(); Set<Id> sIds = new Set<Id>(); //Added Set<ID> accIds = new Set<ID>(); for(Service__c qItr : Trigger.new) { if(Trigger.isUpdate) { if(Trigger.oldmap.get(qItr.id).Last_Email_Sent__c!= qItr.Last_Email_Sent__c ) { sIds.add(qItr.id); //Added accIds.add(qItr.Account__c); } } //Will Never Execute as trigger will fire only if a record is updated else if(Trigger.isInsert) { sIds.add(qItr.id); } } // Modified //for(Account accItr : [SELECT id,(SELECT id FROM Contacts) FROM Account WHERE id IN (SELECT Account__c FROM Service__c WHERE Id IN: sIds)]) for(Account accItr : [SELECT id,(SELECT id FROM Contacts) FROM Account WHERE id IN : accIds]) { for(Contact con : accItr.contacts) { if(!String.isBlank(con.id)) { lcontactEmails.add(con.id); } } // No need to put this condition here. /*if(!lcontactEmails.isEmpty()) { EmailHandler.sendEmail(lcontactEmails); }*/ } //Put this here if(!lcontactEmails.isEmpty()) { for(Service__c serv : Trigger.new) { if(Serv.Accept_Mass_Emails__c == True){ //Email handler Updated if(Serv.Last_Email_Sent__c == 'IPC Support Expiry') { EmailHandler.sendSupportExpiryIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '120 days after IPC Support Start') { EmailHandler.send120AfterStartIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '240 days after IPC Support Start') { EmailHandler.send240AfterStartIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '40 days before IPC Support Expiry') { EmailHandler.send40BeforeExpiryIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == 'Momentum Support Expiry') { EmailHandler.sendSupportExpiryMOMEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '160 days after Momentum Support Start') { EmailHandler.send150AfterStartMOMEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '320 days after Momentum Support Start') { EmailHandler.send300AfterStartMOMEmail(lcontactEmails); } } } } }
-
- Developer.mikie.Apex.Student
- March 05, 2015
- Like
- 0
- Continue reading or reply
governor limit
I have below code . Can I update anything to avoid governor limit ?
trigger PenaltyNoticeReviewTrigger on Penalty_Notice_Review__c (before insert) {
try
{
if (Trigger.isInsert) {
if(trigger.isBefore){
for(Penalty_Notice_Review__c item :Trigger.New){
// get list of Penalty_Notice_Review__c
List<Penalty_Notice_Review__c> penaltyNotices = [SELECT Id,Name,Penalty_Notice__c,Review_Number__c FROM Penalty_Notice_Review__c where Penalty_Notice__c =: item.Penalty_Notice__c];
if(penaltyNotices.size()==0)
item.Review_Number__c = 1;
else
item.Review_Number__c = penaltyNotices.size() + 1;
}
}
}
}
catch (Exception ex)
{
System.debug('Error Occurred:' + '[' + ex.getMessage() +' ]');
throw new FADMSException(ex.getMessage());
}
-
- Huy Nguyen
- February 03, 2015
- Like
- 0
- Continue reading or reply
-
- ra811.3921220580267847E12
- September 02, 2014
- Like
- 0
- Continue reading or reply
need to rerender when picklist values are chagend, but not working
<apex:page standardcontroller="MPI_Category__c" extensions="MPIController1" action="{!autoRun}"
tabStyle="Contact">
<apex:form >
<apex:actionFunction name="rerenderSg1" rerender="sg1sSelectList1" >
<apex:param name="firstParam" assignTo="{!catalog}" value="" />
</apex:actionFunction>
<apex:actionFunction name="rerenderSg2" rerender="sg2sSelectList1" >
<apex:param name="firstParam" assignTo="{!sg1}" value="" />
</apex:actionFunction>
<apex:actionFunction name="rerenderSg3" rerender="sg3sSelectList1" >
<apex:param name="firstParam" assignTo="{!sg2}" value="" />
</apex:actionFunction>
<apex:actionFunction name="rerenderSg4" rerender="sg4sSelectList1" >
<apex:param name="firstParam" assignTo="{!sg3}" value="" />
</apex:actionFunction>
<apex:sectionHeader title="MPI {!mpi.name}" subtitle="MPI Item Selection" />
<apex:pageBlock >
<table><tbody>
<tr>
<th>Catalog</th>
<td>
<apex:selectList id="catalog" styleclass="std" size="1"
value="{!catalog}" onchange="rerenderSg1(this.value)" >
<apex:selectOptions value="{!catalogsSelectList}"/>
</apex:selectList>
</td>
<th>Segment1</th>
<td>
<apex:selectList id="sg1sSelectList1" styleclass="std" size="1"
value="{!sg1}" onchange="rerenderSg2(this.value)" >
<apex:selectOptions value="{!sg1sSelectList1}"/>
</apex:selectList>
</td>
<th>Segment2</th>
<td>
<apex:selectList id="sg2sSelectList1" styleclass="std" size="1"
value="{!sg2}" onchange="rerenderSg3(this.value)" >
<apex:selectOptions value="{!sg2sSelectList1}"/>
</apex:selectList>
</td>
<th>Segment3</th>
<td>
<apex:selectList id="sg3sSelectList1" styleclass="std" size="1"
value="{!sg3}" onchange="rerenderSg4(this.value)" >
<apex:selectOptions value="{!sg3sSelectList1}"/>
</apex:selectList>
</td>
<th>Segment4</th>
<td>
<apex:selectList id="sg4sSelectList1" styleclass="std" size="1"
value="{!sg4}" >
<apex:selectOptions value="{!sg4sSelectList1}"/>
</apex:selectList>
</td>
</tr>
</tbody>
</table>
<apex:commandButton action="{!addRow}" value="AddRow" rerender="pgblckID" />
<apex:commandButton action="{!clear}" value="Clear " id="theButton1" />
</apex:pageblock>
</apex:form>
</apex:page>
controller class:
public with sharing class MPIController1 {
public MPI_Category__c mpi {get;set;}
public MPI_Category__c mpiObject {get;set;}
public MPIProducts__c mpi1 {get;set;}
public Boolean sg4Bool {get;set;}
public Boolean sg3Bool {get;set;}
public Boolean sg2Bool {get;set;}
public Boolean sg1Bool {get;set;}
ApexPages.StandardController controller;
Public Boolean ShowpageBlockFlag{get;set;}
List<SelectOption> optionsca {get;set;}
List<SelectOption> options1 {get;set;}
List<SelectOption> options2 {get;set;}
List<SelectOption> options3 {get;set;}
List<SelectOption> options4 {get;set;}
public MPIController1(ApexPages.StandardController controller) {
this.controller=controller;
mpi=[Select m.Name from MPI_Category__c m where m.id= :ApexPages.currentPage().getParameters().get('id')];
mpiObject = new MPI_Category__c ();
mpiObject = (MPI_Category__c )controller.getRecord();
}
public PageReference autoRun() {
return null;
}
// Variables to store country and state selected by user
public String catalog {get; set;}
public String sg1 {get;set;}
public String sg2 {get;set;}
public String sg3 {get;set;}
public String sg4 {get;set;}
// Generates catalog dropdown from country settings
public List<SelectOption> getCatalogsSelectList()
{
optionsca = new List<SelectOption>();
optionsca.add(new SelectOption('', '--SelectOne--'));
// Find all the catalogs in the custom setting
List<product2> prd= [select id, name, MPI_Catalog__c,MPI_Sg1__c,MPI_Sg2__c,MPI_Sg3__c,MPI_Sg4__c from product2 where MPI_Catalog__c!=null];
set<String> s= new Set<String>();
for(Product2 pr:prd)
{
s.add(pr.MPI_Catalog__c);
}
List<String> list1= new List<String>();
list1.addAll(s);
list1.sort();
for(String s1:list1)
{
optionsca.add(new SelectOption(s1, s1));
}
return optionsca;
}
public List<SelectOption> getSg1sSelectList1() {
System.debug('entered1-----------------------');
System.debug('entered1-catalog----------------------'+catalog);
optionsca.clear();
options1= new List<SelectOption>();
// Find all the states we have in custom settings.
List<product2> allsg1 =[select MPI_Catalog__c,MPI_Sg1__c from product2 where MPI_Catalog__c=:catalog and MPI_Catalog__c!=null];
if(allsg1.size()>0)
{
System.debug('entered11-----------------------');
// Filter states that belong to the selected country
Map<String, Product2> sg1s = new Map<String, Product2>();
for(Product2 sg19 : allsg1) {
if (sg19.MPI_Catalog__c == this.catalog) {
sg1s.put(sg19.MPI_Sg1__c, sg19);
}
}
// Sort the states based on their names
List<String> sg1Names = new List<String>();
sg1Names.addAll(sg1s.keySet());
sg1Names.sort();
System.debug('entered1---sg1Names -------'+sg1Names);
// Generate the Select Options based on the final sorted list
for (String sg1Name : sg1Names) {
Product2 state = sg1s.get(sg1Name);
System.debug('entered1---state -------'+state);
options1.add(new SelectOption(state.MPI_Sg1__c, state.MPI_Sg1__c));
}
}
// If no states are found, just say not required in the dropdown.
if (options1.size() > 0) {
options1.add(0, new SelectOption('', '--Select One--'));
} else {
options1.add(new SelectOption('', 'Not Required'));
}
return options1;
}
public List<SelectOption> getSg2sSelectList1() {
optionsca.clear();
options1.clear();
System.debug('entered2-----------------------');
options2 = new List<SelectOption>();
options2.clear();
List<product2> allsg2 =[select MPI_Catalog__c,MPI_Sg1__c,MPI_Sg2__c from product2 where MPI_Sg1__c=:sg1 and MPI_Sg1__c!=null and MPI_Sg2__c!=null and MPI_Catalog__c=:catalog ];
System.debug('query is----'+[select MPI_Catalog__c,MPI_Sg1__c,MPI_Sg2__c from product2 where MPI_Sg1__c=:sg1 and MPI_Sg1__c!=null and MPI_Sg2__c!=null and MPI_Catalog__c=:catalog] );
if(allsg2.size()>0)
{System.debug('entered21-----------------------'+allsg2);
// Filter states that belong to the selected country
Map<String, Product2> sg1s = new Map<String, Product2>();
for(Product2 sg11 : allsg2) {
if (sg11.MPI_Sg1__c == this.sg1) {
sg1s.put(sg11.MPI_Sg2__c, sg11);
System.debug('entered22-this.sg1----------------------'+this.sg1);
System.debug('entered22-sg11.MPI_Sg1__c----------------------'+sg11.MPI_Sg1__c);
System.debug('entered22-sg1s----------------------'+sg1s);
}
}
// Sort the states based on their names
List<String> sg1Names = new List<String>();
sg1Names.clear();
sg1Names.addAll(sg1s.keySet());
sg1Names.sort();
System.debug('entered23-sg1s----------------------'+sg1Names);
// Generate the Select Options based on the final sorted list
for (String sg1Name : sg1Names) {
Product2 state = sg1s.get(sg1Name);
options2.add(new SelectOption(state.MPI_Sg2__c, state.MPI_Sg2__c));
System.debug('options2.add1---------'+options2);
}
}
// If no states are found, just say not required in the dropdown.
if (options2.size() > 0) {
System.debug('options2.add2---------'+options2);
options2.add(0, new SelectOption('', '--Select One--'));
} else {
System.debug('options2.add3---------'+options2);
options2.add(new SelectOption('', 'Not Required'));
}System.debug('options2.add4---------'+options2);
return options2;
}
public List<SelectOption> getSg3sSelectList1() {
System.debug('entered3-----------------------');
optionsca.clear();
options1.clear();
options2.clear();
options3 = new List<SelectOption>();
options3.clear();
List<product2> allsg2 =[select MPI_Catalog__c,MPI_Sg1__c,MPI_Sg2__c,MPI_Sg3__c from product2 where MPI_Sg2__c=:sg2 and MPI_Sg2__c!=null and MPI_Sg3__c!=null and MPI_Catalog__c=:catalog and MPI_Sg1__c=:sg1 ];
System.debug('sg2is-------------------'+sg2);
System.debug('allsg2 -------------------'+allsg2);
if(allsg2.size()>0)
{
// Filter states that belong to the selected country
Map<String, Product2> sg1s = new Map<String, Product2>();
for(Product2 sg12 : allsg2) {
if (sg12.MPI_Sg2__c == this.sg2) {
sg1s.put(sg12.MPI_Sg3__c, sg12);
}
}
// Sort the states based on their names
List<String> sg1Names = new List<String>();
sg1Names.clear();
sg1Names.addAll(sg1s.keySet());
sg1Names.sort();
// Generate the Select Options based on the final sorted list
for (String sg1Name : sg1Names) {
Product2 state = sg1s.get(sg1Name);
options3.add(new SelectOption(state.MPI_Sg3__c, state.MPI_Sg3__c));
}
}
// If no states are found, just say not required in the dropdown.
if (options3.size() > 0) {
options3.add(0, new SelectOption('', '--Select One--'));
} else {
options3.add(new SelectOption('', 'Not Required'));
}
return options3;
}
public List<SelectOption> getSg4sSelectList1() {
System.debug('entered4-----------------------');
optionsca.clear();
options1.clear();
options2.clear();
options3.clear();
options4 = new List<SelectOption>();
options4.clear();
List<product2> allsg2 =[select MPI_Catalog__c,MPI_Sg1__c,MPI_Sg2__c,MPI_Sg3__c,MPI_Sg4__c from product2 where MPI_Sg3__c=:sg3 and MPI_Sg3__c!=null and MPI_Sg4__c!=null and MPI_Catalog__c=:catalog and MPI_Sg1__c=:sg1 and MPI_Sg2__c=:sg2];
System.debug('sg2is-------------------'+sg2);
System.debug('allsg2 -------------------'+allsg2);
if(allsg2.size()>0)
{
// Filter states that belong to the selected country
Map<String, Product2> sg1s = new Map<String, Product2>();
for(Product2 sg13 : allsg2) {
if (sg13.MPI_Sg3__c == this.sg3) {
sg1s.put(sg13.MPI_Sg4__c, sg13);
}
}
// Sort the states based on their names
List<String> sg1Names = new List<String>();
sg1Names.addAll(sg1s.keySet());
sg1Names.sort();
// Generate the Select Options based on the final sorted list
for (String sg1Name : sg1Names) {
Product2 state = sg1s.get(sg1Name);
options4.add(new SelectOption(state.MPI_Sg4__c, state.MPI_Sg4__c));
}
}
// If no states are found, just say not required in the dropdown.
if (options4.size() > 0) {
options4.add(0, new SelectOption('', '--Select One--'));
} else {
options4.add(new SelectOption('', 'Not Required'));
}
return options4;
}
public void addRow()
{
mpi1= new MPIProducts__c();
System.debug('catalog is------'+catalog);
System.debug('sg1 is------'+sg1);
System.debug('sg2 is------'+sg2);
System.debug('sg3 is------'+sg3);
System.debug('sg3 is------'+sg4);
if(catalog!=null)
{
mpi1.catlogp__c=catalog;
mpi1.Name=catalog;
}
if(sg1!=null)
{
mpi1.sg1p__c=sg1;
}
if(sg2!=null)
{
mpi1.sg2p__c=sg2;
}
if(sg3!=null)
{
mpi1.sg3p__c=sg3;
}
if(sg4!=null)
{
mpi1.sg4p__c=sg4;
}
mpi1.MPIProductLo__c=(String)mpi.id;
List<product2> itemdes=[select ProductCode,id from product2 where MPI_Catalog__c =:catalog and MPI_Sg1__c =:sg1 and MPI_Sg2__c =:sg2 and MPI_Sg3__c =:sg3 and MPI_Sg4__c =:sg4];
mpi1.ItemCode__c=itemdes[0].ProductCode;
insert mpi1;
ShowpageBlockFlag = true;
}
public pagereference clear()
{
return controller.cancel();
}
public pagereference update1()
{
update mpi1;
PageReference reRend = new PageReference('/'+mpi.id);
return reRend;
}
find the below screen shot for the same, whenever i will change 'catalog' values then that section should refresh and all sg1,sg2,sg3,sg4 as'non required'.
but it is showing with old values,
thanks in advance
}
-
- ra811.3921220580267847E12
- July 27, 2014
- Like
- 0
- Continue reading or reply
Visualforce Error Help for this Page System.NullPointerException: Argument 1 cannot be null
tabStyle="Contact">
<style type="text/css">
.m1{
width: 60px;
}
</style>
<apex:form >
<apex:actionFunction name="rerenderSg1" rerender="sg1sSelectList1" >
<apex:param name="firstParam" assignTo="{!catalog}" value="" />
</apex:actionFunction>
<apex:sectionHeader title="MPI {!mpi.name}" subtitle="MPI Item Selection" />
<apex:pageBlock >
<table><tbody>
<tr>
<th>Catalog</th>
<td>
<apex:selectList id="catalog" styleclass="std" size="1"
value="{!catalog}" onchange="rerenderSg1(this.value)" >
<apex:selectOptions value="{!catalogsSelectList}"/>
</apex:selectList>
</td>
<th>Segment1</th>
<td>
<apex:selectList id="sg1sSelectList1" styleclass="std" size="1"
value="{!sg1}" >
<apex:selectOptions value="{!sg1sSelectList1}"/>
</apex:selectList>
</td>
</tr>
</tbody>
</table>
</apex:pageblock>
</apex:form>
</apex:page>
public with sharing class MPIController1 {
public MPI_Category__c mpi {get;set;}
public MPI_Category__c mpiObject {get;set;}
public MPIProducts__c mpi1 {get;set;}
public Boolean sg4Bool {get;set;}
public Boolean sg3Bool {get;set;}
public Boolean sg2Bool {get;set;}
public Boolean sg1Bool {get;set;}
ApexPages.StandardController controller;
Public Boolean ShowpageBlockFlag{get;set;}
public MPIController1(ApexPages.StandardController controller) {
this.controller=controller;
mpi=[Select m.Name from MPI_Category__c m where m.id= :ApexPages.currentPage().getParameters().get('id')];
mpiObject = new MPI_Category__c ();
mpiObject = (MPI_Category__c )controller.getRecord();
}
public PageReference autoRun() {
return null;
}
// Variables to store country and state selected by user
public String catalog {get; set;}
public String sg1 {get;set;}
public String sg2 {get;set;}
public String sg3 {get;set;}
public String sg4 {get;set;}
// Generates catalog dropdown from country settings
public List<SelectOption> getCatalogsSelectList()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('', '--SelectOne--'));
// Find all the catalogs in the custom setting
List<product2> prd= [select id, name, MPI_Catalog__c,MPI_Sg1__c,MPI_Sg2__c,MPI_Sg3__c,MPI_Sg4__c from product2 where MPI_Catalog__c!=null];
set<String> s= new Set<String>();
for(Product2 pr:prd)
{
s.add(pr.MPI_Catalog__c);
}
List<String> list1= new List<String>();
list1.addAll(s);
list1.sort();
for(String s1:list1)
{
options.add(new SelectOption(s1, s1));
}
return options;
}
public List<SelectOption> getSg1sSelectList1() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('', '--SelectOne--'));
System.debug('catalog is -----'+catalog);
List<product2> allsg1 =[select MPI_Catalog__c,MPI_Sg1__c from product2 where MPI_Catalog__c=:catalog];
Map<String,String> allSgValues= new Map<String,String>();
for(Product2 p:allsg1)
{
if(p.MPI_Catalog__c==this.catalog)
{
allSgValues.put(p.MPI_Catalog__c,p.MPI_Sg1__c);
options.add(new SelectOption(p.MPI_Catalog__c, p.MPI_Sg1__c));
}
System.debug('allSgValues are-----'+allSgValues);
}
// If no states are found, just say not required in the dropdown.
if (options.size() > 0) {
options.add(0, new SelectOption('', '--Select One--'));
} else {
options.add(new SelectOption('', 'Not Required'));
}
return options;
}
}
this is my page and controller, getSg1sSelectList1() is not renedering properly.so that Argument 1 canot be null cmg. help me on this
-
- ra811.3921220580267847E12
- July 25, 2014
- Like
- 0
- Continue reading or reply
How to get List of licensed user details for managed packages in salesforce
how to get list of licensed user details for managed packages into vf page
-
- ra811.3921220580267847E12
- April 11, 2014
- Like
- 0
- Continue reading or reply
Inline vf error in page layout
We had a requirement where i must use for a single object, i need to use 156 formula fields. now iam trying to display those fileds in the VF page(inline vf in the page layout). iam able to display 52 fields only. for remaining fields it is showing the below error:
Query
-
- ra811.3921220580267847E12
- February 11, 2014
- Like
- 1
- Continue reading or reply
Inline vf error in page layout
We had a requirement where i must use for a single object, i need to use 156 formula fields. now iam trying to display those fileds in the VF page(inline vf in the page layout). iam able to display 52 fields only. for remaining fields it is showing the below error:
Query
-
- ra811.3921220580267847E12
- February 11, 2014
- Like
- 1
- Continue reading or reply
Looking for an offshore part time Visual Force Developer
Details will be provided later. You must have 2-3 years of hands-on programming experience in Apex, VFP, Java Script, SOQL, etc. Must sign an NDA (non-disclosure agreement). Please contact us with your hourly rate and email address.
- Asir Rahman
- July 27, 2016
- Like
- 0
- Continue reading or reply
Salesforce developer Needed
I need one developer who will be able work with me. The candidate must have experience on below modules.
1. APEX
2. Visualforce
3. HTML,CSS,Javascript
4. Salesforce Admin
Note:Price should be very low.
Thanks,
Ramesh
- Ramesh Kalloori
- June 20, 2015
- Like
- 0
- Continue reading or reply
How to prevent recursive triggering in this example?
First Trigger updates Invoice a dollar value equal to the sum of the dollar value from Permits which have a matching Invoice number. As below:
trigger InvoiceAmountUpdate on Permit__c (after update) {
for(Permit__c obj : trigger.new)
{
List<Permit__c> permit = [select Total1__c from Permit__c p where p.Invoice_Num__c = :obj.Invoice_Num__c];
decimal sum = 0;
for (Permit__c p : permit) {sum = sum + p.Total1__c;}
List<bb_Invoice__c> invoice = [select Invoice_Amount__c from bb_Invoice__c i where i.id = :obj.Invoice_Num__c];
for (bb_Invoice__c i : invoice) {
i.Invoice_Amount__c = sum;
update i;
}
}
}
Second Trigger updates payment amount on Permits when the full invoice value is paid. However, with each update on Permit, the first trigger is called ending in a recursive pattern
trigger PaymentStatusUpdate on bb_Invoice__c (before update) {
for(bb_Invoice__c obj : trigger.new)
{
if (obj.Paid_Amount__c>=obj.Invoice_Amount__c) {
obj.Payment_Status__c = 'Paid';
List<Permit__c> permit = [select Total1__c,Paid__c from Permit__c p where p.Invoice_Num__c = :obj.id];
for (Permit__c p : permit) {
p.Paid__c = p.Total1__c;
update p;
}
}
else if (obj.Paid_Amount__c>0) {
if (obj.Paid_Amount__c<obj.Invoice_Amount__c) {
obj.Payment_Status__c = 'Partially Paid';
}
}
}
}
- Billbay
- May 27, 2015
- Like
- 0
- Continue reading or reply
System.NullPointerException: Attempt to de-reference a null object
Hi,
I'm adding a field from a parent object on one of our apex classes and one the corresponding visualforce page. When I am navigating to the visualforce page I checked the error message "System.NullPointerException: Attempt to de-reference a null object".
The error seems to be coming from line 620 on the apex class -
offerSiteObj.Offer__r.End_Date__c = offerSiteList[0].Offer__r.End_Date__c;
But I can't see whats wrong with this - this is to allow the user to enter a value and then when they save it will save the value on the field on the parent object.
The field is then referenced on the vf page as:
<apex:inputField value="{!offerSiteList[0].Offer__r.End_Date__c}"/>
Does anyone know what is wrong here? Am I unable to reference a field from a parent object here?
Any help is much appreciated.
- RadDude89
- March 30, 2015
- Like
- 0
- Continue reading or reply
same method, different output
Ordered Items: 10
Cancelled Items: 3
Reviewed Items: 2
VF Page and apex code below:
Ordered Items: <apex:commandButton value="{!Count}"/> Cancelled Items: <apex:commandButton value="{!Count}" /> Reviewed Items: <apex:commandButton value="{!Count}"/> Public Integer Count(){ List<Items__c> items = [SELECT Count(ID) FROM Items__c WHERE Status == 'Ordered' OR Status == 'Cancelled' OR Status == 'Reviewed']; return items.size(); }
With the above code ofcourse, I get the following output
Ordered Items: 15
Cancelled Items: 15
Reviewed Items: 15
Im calling the same method here, but I want to return differently based on the Status. I tried to use apex:param for the commandButton, but doesn't work.
Any ideas how to implement. [I want to use only 1 SOQL, with different SOQL and different methods, I can get what I want]
- sfdcFanBoy
- March 30, 2015
- Like
- 0
- Continue reading or reply
How to Calculate Age in Day?
There is a date field, for inserting date of birth.
There is another button to calculate age (in days) which will be displayed below.
How to do that?
- Dutta Sourav
- March 10, 2015
- Like
- 0
- Continue reading or reply
need help to write a trigger for opoortunity
i am new to Apex triggers. I need to write a trigger for Opportunity object. The logic is when any update is made on opportuntiy object. means if a user make change to an opportuntiy object certain fields should be get update based on the value of other object Credit App.
Opportunity Fields to be updated:
1. Broker_Firm__c
2. Broker_Firm_Office__c
3. Primary_Contact_Role__c
I am trying to it thru this Apex trigger please let me know if i am doing soemthing because it is no compiling
trigger UpdateOpportunity on Opportunity (After update)
//Map broker related opportunity fields to keep credit App up to date.
{
Opportunity Opp = [Select broker_firm__c, broker_firm_office__c, primary_contact_role__c from Opportunity WHERE ID In:Trigger.newMap.keySet()];
Underwriting__c U=[Select Opportunity__c from Underwriting__c where Opportunity_Id__c =:Opp.Id];
For (Opportunity O:Trigger.new){
U.broker_firm__c = o.broker_firm__c;
U.broker_firm_office__c = o.broker_firm_office__c;
U.broker_name__c = o.primary_contact_role__c;
}
}
- Bayarea 101
- March 09, 2015
- Like
- 0
- Continue reading or reply
How to prevent Trigger to be fired after workflow field update? Any suggestions on this?
- Rabbani sayyed 8
- March 09, 2015
- Like
- 0
- Continue reading or reply
Using maps for validation
Below is my code. Hope there is some mistakes while getting the errors string from the map for corresponding records.
Map<String, List<Account>> errorRecords = new Map<String, List<Account>>(); List<Account> accError = new List<Account>(); if((record.Discount_Type__c == 'Date Specified' || record.Discount_Type__c == 'Life Time') && opps.Coupon_Codes__c == null) { accError.add(record); errorRecords.put(' Please provide coupon code for the discount type specified!', accError); } else if(record.Discount_Type__c == 'Date Specified' && String.valueOf(record.Discount_End_Date__c) == null) { accError.add(record); errorRecords.put(' Please choose the discount end date in account before clone the new opportunity', accError); } Here I am adding the error messages to record for(String str : errorRecords.keySet()) { for(Account o : errorRecords.get(str)) { Account oAccErrors = accountNewMap.get(o.Id); oAccErrors.addError(str); } }Error records is seperated perfectly but the error message is displaying as same. Thanks in advance
- Vetriselvan Manoharan
- March 05, 2015
- Like
- 0
- Continue reading or reply
How to hide standard user type picklist value
Hi guys I need to remove customer portal user from standard user look field and only show User and Partner user.Can you please suggest some solution to achieve it.
- Amit Trivedi
- March 05, 2015
- Like
- 1
- Continue reading or reply
Mass Emailing trigger sending email out 5 times - Please help - Urgent
I have a trigger which I have wrriten to send emails to all the contacts that are the children of an account which a custom object record (service__c) is also the child of. The code is designed to trigger upon Last_emails_Sent (picklist) change. The picklist is changed from a time based work flow rule with rule criteria of '(Service: Service NameEQUALSIntensive Property Coaching) AND (Service: Start of ServiceNOT EQUAL TOnull)'. It updates the picklist at (40 days before end of service support, 1 hour before end of service support, 120 days after sstart of service and 240 days after start of service). For some reason, upon reviewing my mass email, 5 accounts came to expiry today and at 11pm last night, 5 emaiils were sent out to each associated contact.
I am not sure what has caused this problem, any help would be very much appreciated. Particular to do with whether this is due to the time based workflow or the trigger. Thank you in advance for any hel that you may give me. Below is my code:
rigger SendEmailtocontact on Service__c (after Update) { List<String> lcontactEmails = new List<String>(); Set<Id> sIds = new Set<Id>(); //Added Set<ID> accIds = new Set<ID>(); for(Service__c qItr : Trigger.new) { if(Trigger.isUpdate) { if(Trigger.oldmap.get(qItr.id).Last_Email_Sent__c!= qItr.Last_Email_Sent__c ) { sIds.add(qItr.id); //Added accIds.add(qItr.Account__c); } } //Will Never Execute as trigger will fire only if a record is updated else if(Trigger.isInsert) { sIds.add(qItr.id); } } // Modified //for(Account accItr : [SELECT id,(SELECT id FROM Contacts) FROM Account WHERE id IN (SELECT Account__c FROM Service__c WHERE Id IN: sIds)]) for(Account accItr : [SELECT id,(SELECT id FROM Contacts) FROM Account WHERE id IN : accIds]) { for(Contact con : accItr.contacts) { if(!String.isBlank(con.id)) { lcontactEmails.add(con.id); } } // No need to put this condition here. /*if(!lcontactEmails.isEmpty()) { EmailHandler.sendEmail(lcontactEmails); }*/ } //Put this here if(!lcontactEmails.isEmpty()) { for(Service__c serv : Trigger.new) { if(Serv.Accept_Mass_Emails__c == True){ //Email handler Updated if(Serv.Last_Email_Sent__c == 'IPC Support Expiry') { EmailHandler.sendSupportExpiryIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '120 days after IPC Support Start') { EmailHandler.send120AfterStartIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '240 days after IPC Support Start') { EmailHandler.send240AfterStartIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '40 days before IPC Support Expiry') { EmailHandler.send40BeforeExpiryIPCEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == 'Momentum Support Expiry') { EmailHandler.sendSupportExpiryMOMEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '160 days after Momentum Support Start') { EmailHandler.send150AfterStartMOMEmail(lcontactEmails); } //Email handler Updated if(Serv.Last_Email_Sent__c == '320 days after Momentum Support Start') { EmailHandler.send300AfterStartMOMEmail(lcontactEmails); } } } } }
- Developer.mikie.Apex.Student
- March 05, 2015
- Like
- 0
- Continue reading or reply
Trigger to match value against custom object.
Hi, I desperatly need some help creating my first trigger and i'm a bit lost.
I'm trying to create a trigger on a custom object called wp_leads__c which looks up a field called code_entered__c against another custom object called wp_cid__c on a field called coupon__c.
If wp_leads__c. code_entered__c = wp_cid__c.coupon__c I want to update a tickbox field called matched_code__c in the wp_leads__c object with a tick.
Please help!
- HB 1
- March 02, 2015
- Like
- 0
- Continue reading or reply
Trigger on task to change opportunity status
trigger TaskSubject on Task (after update, after insert) {
set<id> accountIdSet = new set<id>();
//capture all the subject names in a set
//set<string> subjectName = new set<string>{'Requalify'};
map<id, list<opportunity>> opptyMap = new map<id, list<opportunity>>();
list<opportunity> updateOppList = new list<opportunity>();
//get those tasks where the tasks are related to account. Capture the account IDs in a set.
for(task t: trigger.new){
string tempId = string.valueOf(t.WhatId);
if(tempId.startsWith('001')){
accountIdSet.add(t.whatId);
}
}
//If we have any account IDs then get the associated opportuity and store the one account to many opportunity in a map<id, list<opportunity>>
if(accountIdSet.size()>0){
for(opportunity opp:[select Name, stageName, accountid from opportunity where accountid IN :accountIdSet]){
if(opptyMap.containsKey(opp.accountId)){
list<opportunity> oppList = opptyMap.get(opp.accountId);
oppList.add(opp);
opptyMap.put(opp.accountId, oppList);
}else{
list<opportunity> newOppList = new list<opportunity>();
newOppList.add(opp);
opptyMap.put(opp.accountId, newOppList);
}
}
}
//If we get the opportunities then change the stage.
if(Trigger.isUpdate && opptyMap.size()>0){
for(task t: trigger.new){
//Check if the subject of the task is one among the set
//and also confirm that the subject has been changed.
if(t.subject != trigger.oldMap.get(t.id).subject && opptyMap.containsKey(t.whatId)){
//iterate thru the list of the opportunity associated with that account
//and check which of the opportunity contains the task subject in the
//opportunity name and update the stage to re-qualify
for(opportunity oppty: opptyMap.get(t.whatId)){
{
oppty.stageName='Re-Qualify';
updateOppList.add(oppty);
}
}
}
}
}
if(Trigger.isInsert && opptyMap.size()>0){
for(task t: trigger.new){
if(opptyMap.containsKey(t.whatId)){
for(opportunity oppty: opptyMap.get(t.whatId)){
if(oppty.name.contains(t.subject)){
oppty.stageName='Re-Qualify';
updateOppList.add(oppty);
}
}
}
}
}
//update the oppties
if(updateOppList.size()>0){
update updateOppList;
}
}
- Lauren Honyotski
- March 02, 2015
- Like
- 0
- Continue reading or reply
Before Delete Trigger on CaseComment showing Null values
I have created the following trigger on caseComment.
if(Trigger.isBefore && Trigger.isDelete)
{
cls_Case_Comment.CheckAssignedPermissionSet(trigger.old);
}
}
Below is the Helper Class:
Public with sharing class cls_Case_Comment {
Public Static Void CheckAssignedPermissionSet(List<CaseComment>newList)
{
/* This Method is used as Helper Method for trigger trg_Case_Comment
Set<String>str_set= new Set<String>();
String profile_Name =[SELECT Name from Profile where Id=:UserInfo.getProfileId()].Name;
List<PermissionSet>lst_PermissionSet = [SELECT Id, Name from PermissionSet where ID in ( SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId =:Userinfo.getUserId())];
for(PermissionSet ps:lst_PermissionSet){
str_set.add(ps.Name);
}
for(CaseComment cs:newList)
{
if(profile_Name!='System Administrator'){
if(!str_set.contains('Delete_cases'))
{
cs.addError(system.label.trg_cls_Case_Comment);
}
}
}
}
}
Everything is Working Correctly except on Deleting the CaseComment, I am getting a null value.
Error message is displaying correctly
- Appy123
- February 19, 2015
- Like
- 0
- Continue reading or reply
Mismatch in Number of lines in Class
We are seeing a difference in the number of lines of code shown in the developer console after running the test. The code has only 488 lines but the right hand panel shows that it has 675 lines and only 435 are covered. I have compiled the code and have waited for a couple of days to check if it is a temporary issue and nothing seems to change. This is in production.
- Santhosh Parakunnath
- February 19, 2015
- Like
- 0
- Continue reading or reply