-
ChatterFeed
-
0Best Answers
-
3Likes Received
-
0Likes Given
-
21Questions
-
20Replies
why i am seeing two validation rule errors messages on owner field
I have created two validation rules on Custom object,
One on Status field, and another on Owner field,
When i try to change the validation rule is firing but, it is showing two validation rule error messages on it, how to I handle it ?
One on Status field, and another on Owner field,
When i try to change the validation rule is firing but, it is showing two validation rule error messages on it, how to I handle it ?
- nagendra kumar 21
- March 25, 2022
- Like
- 0
- Continue reading or reply
MIXED_DML_OPERATION, DML operation Invalid Data. System.DmlException
hello All,
I have created a custom user history object to store the old and new value for the updates or changes made in the user object.
my code is working for first and last name fields but not for all other fields and getting this error "
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UserTrigger caused an unexpected exception, contact your administrator: UserTrigger: execution of AfterUpdate caused by: System.DmlException: In
sert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User_History__c, original object: User: []: Class.UserTriggerHandler.CreateUserHistoryRecords: line 31, column 1
can anyone please check and let me know where to change
I have created a custom user history object to store the old and new value for the updates or changes made in the user object.
my code is working for first and last name fields but not for all other fields and getting this error "
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UserTrigger caused an unexpected exception, contact your administrator: UserTrigger: execution of AfterUpdate caused by: System.DmlException: In
apex code - public class UserTriggerHandler { public static void onAfterUpdate (List<User> userList, Map<Id, User> oldUserMap){ CreateUserHistoryRecords(userList,oldUserMap); } public static void CreateUserHistoryRecords(List<User> userList, Map<Id, User> oldUserMap){ List<string> fieldList = new List<String> (); List<Schema.FieldSetMember> fieldSetMemberList = readFieldSet('User_History_Fields','User'); for(Schema.FieldSetMember fieldSetMemberObj : fieldSetMemberList) { fieldList.add(fieldSetMemberObj.getFieldPath()); } List<User_History__c> userHistoryRecords = new List<User_History__c>(); for(User newrec : userList){ User oldrec = oldUserMap.get(newrec.Id); for(String FieldName : fieldList){ if(oldrec.get(FieldName)!=newrec.get(FieldName)){ User_History__c uhrec = new User_History__c(); uhrec.Field__c = FieldName; uhrec.NewValue__c =(String)newrec.get(FieldName); uhrec.OldValue__c = (String)oldrec.get(FieldName); uhrec.User_ID__c = newrec.Id; userHistoryRecords.add(uhrec); } } } if(!userHistoryRecords.isEmpty()) { insert userHistoryRecords; } } public static List<Schema.FieldSetMember> readFieldSet(String fieldSetName, String ObjectName) { System.debug(fieldSetName); System.debug(ObjectName); Map<String, Schema.SObjectType> GlobalDescribeMap = Schema.getGlobalDescribe(); Schema.SObjectType SObjectTypeObj = GlobalDescribeMap.get(ObjectName); Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe(); system.debug('====>' + DescribeSObjectResultObj.FieldSets.getMap()); Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(fieldSetName); //List<Schema.FieldSetMember> fieldSetMemberList = fieldSetObj.getFields(); //system.debug('fieldSetMemberList ====>' + fieldSetMemberList); if(fieldSetObj!=null){ return fieldSetObj.getFields(); } else{ return null; } } } Trigger - 1 2 3 4 5 6 7 8 9 trigger UserTrigger on User (after update) { if ( trigger.isAfter ) { if ( trigger.isUpdate ) { UserTriggerHandler.onAfterUpdate(trigger.new, trigger.oldMap); } } }
sert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User_History__c, original object: User: []: Class.UserTriggerHandler.CreateUserHistoryRecords: line 31, column 1
can anyone please check and let me know where to change
- nagendra kumar 21
- October 13, 2020
- Like
- 0
- Continue reading or reply
How to show specific picklist values based on record type on custom lightning Component page.
Hello every one,
I have this code for the component page and for sub-stage and stage I'm getting all the picklist values that are on that field,
But I want them to show only those values that are assigned to a particular record type
what change should i do ? can anyone please let me her here
Component ...
<aura:component controller="OPPInlineEditCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <!--Init handler which is call initRecords js function on component Load--> <aura:handler name="init" value="{!this}" action="{!c.initRecords}"/> <aura:attribute name="recordId" type="Id" default="" /> <!-- NAME STAGE SUB-STAGE CLOSE DATE TARGET GMR --> <!--declare aura attributes--> <aura:attribute name="OpportunityList" type="Opportunity[]" description="store Opportunity records list"/> <aura:attribute name="StagePicklist" type="List" description=""/> <aura:attribute name="SubStagePicklistMap" type="Map" /> <aura:attribute name="SubStagePicklist" type="List" description=""/> <aura:attribute name="TotalOpportunity" type="Integer" default="0" description=""/> <aura:attribute name="showSaveCancelBtn" type="boolean" default="false" description="flag for rendered save and cancel buttons in aura:if "/> <aura:html tag="style"> .slds-modal__container { min-width: 98vw; min-hieght: 90vh; padding:1vw; } </aura:html> <!-- use aura:if for show/hide buttons --> <lightning:card title="{! 'Opportunity ('+v.TotalOpportunity+')'}"> <aura:set attribute="actions"> <lightning:button onclick="{!c.onclickNew}" label="New"/> </aura:set> <!--Data Table--> <table class="slds-table slds-table_bordered slds-table_cell-buffer "> <thead> <tr class="slds-text-title--caps"> <th scope="col" style="width:15%"><div class="slds-truncate" title="NAME">NAME</div></th> <th scope="col" style="width:15%"><div class="slds-truncate" title="STAGE">STAGE</div></th> <th scope="col" style="width:20%"><div class="slds-truncate" title="SUB-STAGE">SUB-STAGE</div></th> <th scope="col" style="width:20%"><div class="slds-truncate" title="CLOSE DATE">CLOSE DATE</div></th> <th scope="col" style="width:10%"><div class="slds-truncate" title="CURRENT STATE">CURRENT STATE</div></th> <th scope="col" style="width:10%"><div class="slds-truncate" title="NEXT STEP">NEXT STEPS</div></th> <th scope="col" style="width:10%"><div class="slds-truncate" title="TARGET GMR">Expected GMR</div></th> </tr> </thead> <tbody> <!--### display all records of OpportunityList attribute one by one by aura:iteration ###--> <aura:iteration items="{!v.OpportunityList}" var="acc" indexVar="sNo"> <!-- Child Lightning Component --> <c:OppInlineEditRow SubStagePicklistMap = "{!v.SubStagePicklistMap}" StagePicklist = "{!v.StagePicklist}" SubStagePicklist = "{!v.SubStagePicklist}" singleRec="{!acc}" showSaveCancelBtn="{!v.showSaveCancelBtn}" sNo="{!sNo + 1}" /> </aura:iteration> </tbody> </table> <aura:if isTrue="{!v.showSaveCancelBtn}"> <center> <!--button for save and cancel Record after Inline Edit--> <lightning:buttonGroup class="slds-m-around_medium"> <lightning:button label="Refresh" onclick="{!c.cancel}"/> <lightning:button label="Save" onclick="{!c.Save}" variant="brand"/> </lightning:buttonGroup> </center> </aura:if> </lightning:card> </aura:component>
- nagendra kumar 21
- October 01, 2020
- Like
- 0
- Continue reading or reply
how to reduce the batch job running process.
hi everyone, how to reduce the batch run time ?? when I ran the batch it took 2 days to complete it which is a lot time for business to check the changes, is there any way we can reduce it ??
- nagendra kumar 21
- June 08, 2020
- Like
- 0
- Continue reading or reply
How do i write a batch class and trigger on account status to change based on a formula field update happened
Hi Everyone,
Can anyone please help me on how to write a batch class and/or trigger on account status update for below requirement.
I'm pretty new to coding so not sure where to start it from.
Usecase--
Create a batch job that will run hourly with the following functionality:
For any Strategic Supplier Accounts...
1. If the Account.of_Awarded_Divisions_c > 0 and Account.Status != Awarded, Do Not Contact, or Ineligible, then update the Account.Status_c to Awarded
2. If the Account.of_Awarded_Divisions_c = Account.of_Divisions_ever_having_APc, then update the Account.Status_reason_c to Full Award
Can anyone please help me on how to write a batch class and/or trigger on account status update for below requirement.
I'm pretty new to coding so not sure where to start it from.
Usecase--
Create a batch job that will run hourly with the following functionality:
For any Strategic Supplier Accounts...
1. If the Account.of_Awarded_Divisions_c > 0 and Account.Status != Awarded, Do Not Contact, or Ineligible, then update the Account.Status_c to Awarded
2. If the Account.of_Awarded_Divisions_c = Account.of_Divisions_ever_having_APc, then update the Account.Status_reason_c to Full Award
- nagendra kumar 21
- February 04, 2020
- Like
- 0
- Continue reading or reply
System.DmlException: Update failed. First exception on row 0 with id 0011200001DyK2BAAV; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records
Hi Everyone,
I have trigger and class for a custom object, and in prod when data updated or loaded to the custom object I'm getting this error. can anyone please give a solution for this, I'm new to coding.
Error --
External E-Mail – Verify Email Address, Links, and Attachments
Apex script unhandled trigger exception by user/organization: 005A0000004JEGW/00DA0000000C46b
DivisionTrigger: execution of AfterUpdate
caused by: System.DmlException: Update failed. First exception on row 0 with id 0011200001DyK2BAAV; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records: 0011200001DyK2BAAV,0011200001DyKFAAA3,0011200001DyLr8AAF,0011200001DyNIQAA3,0011200001DyNJHAA3,0011200001DyNdZAAV,0011200001DyNycAAF,0011200001DyPHUAA3,0011200001DyQeIAAV,0011200001DyS64AAF, ... (190 more): []
Class.DivisionTriggerHandler.calculateCount: line 124, column 1
Trigger.DivisionTrigger: line 8, column 1
Trigger -
trigger DivisionTrigger on Division__c (after insert,after update,after delete) {
//if( Division__c.Account__c != Null || Division__c.Account__c == Null){
if ( trigger.isAfter ) {
if ( trigger.isInsert ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isUpdate ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isDelete ) {
DivisionTriggerHandler.calculateCount(trigger.old);
}
}
//}
}
Class -
public without sharing class DivisionTriggerHandler {
public static void calculateCount(List<Division__c> divisionList) {
System.debug(divisionList);
Set<Id> accIds = new Set<Id>();
for(Division__c dv: divisionList)
{
accIds.add(dv.Account__c);
}
System.debug(accIds);
if(accIds.size()>0)
{
Map<Id,Account> accMap = new Map<id, Account>([Select id, of_DIvisions__c ,of_Divisions_ever_having_AP__c ,of_Participated_Divisions__c ,of_Blacklisted_Divisions__c ,of_Awarded_Divisions__c from Account where Id in :accIds]);
List<Division__c> divList = [Select id,Account__c, RecordType.Name,First_Awarded_Date__c,Status__c,
First_Invoice_Load_Date__c,First_Participation_Date__c from Division__c where RecordType.Name in ('C2FO Division','International Division') and Account__r.RecordType.Name ='Strategic Supplier' and Account__c in: accIds];
Map<Id,List<Division__c>> AccDivMap = new Map<Id, List<Division__c>>();
for(Division__c dv: divList)
{
if(AccDivMap.containsKey(dv.Account__c))
{
List<Division__c> tempList = AccDivMap.get(dv.Account__c);
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
else{
List<Division__c> tempList = new List<Division__c>();
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
}
for(Id accId : accMap.keySet())
{
Account acc2 = accMap.get(accId);
System.debug(acc2);
acc2.of_Awarded_Divisions__c=0;
acc2.of_Blacklisted_Divisions__c=0;
acc2.of_DIvisions__c=0;
acc2.of_Divisions_ever_having_AP__c=0;
acc2.of_Participated_Divisions__c =0;
accMap.put(accId,acc2);
List<Division__c> tempDivisionlist = AccDivMap.get(accId);
System.debug(tempDivisionlist);
if(tempDivisionlist!=null)
{
for(Division__c div : tempDivisionlist)
{
System.debug(div.Status__c);
if(div.First_Awarded_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Awarded_Divisions__c != null)
{
acc.of_Awarded_Divisions__c = acc.of_Awarded_Divisions__c + 1;
}
else
{
acc.of_Awarded_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.Status__c=='Blacklisted')
{
System.debug('Hello I am here');
Account acc = accMap.get(div.Account__c);
if(acc.of_Blacklisted_Divisions__c != null)
{
acc.of_Blacklisted_Divisions__c = acc.of_Blacklisted_Divisions__c + 1;
}
else
{
acc.of_Blacklisted_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Awarded_Date__c ==null&&div.First_Participation_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Participated_Divisions__c != null)
{
acc.of_Participated_Divisions__c = acc.of_Participated_Divisions__c + 1;
}
else
{
acc.of_Participated_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Invoice_Load_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Divisions_ever_having_AP__c != null)
{
acc.of_Divisions_ever_having_AP__c = acc.of_Divisions_ever_having_AP__c + 1;
}
else
{
acc.of_Divisions_ever_having_AP__c = 1;
}
accMap.put(acc.Id,acc);
}
Account acc = accMap.get(div.Account__c);
if(acc.of_DIvisions__c != null)
{
acc.of_DIvisions__c = acc.of_DIvisions__c + 1;
}
else
{
acc.of_DIvisions__c = 1;
}
accMap.put(acc.Id,acc);
}
}
}
update accMap.values();
}
}
}
I have trigger and class for a custom object, and in prod when data updated or loaded to the custom object I'm getting this error. can anyone please give a solution for this, I'm new to coding.
Error --
External E-Mail – Verify Email Address, Links, and Attachments
Apex script unhandled trigger exception by user/organization: 005A0000004JEGW/00DA0000000C46b
DivisionTrigger: execution of AfterUpdate
caused by: System.DmlException: Update failed. First exception on row 0 with id 0011200001DyK2BAAV; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records: 0011200001DyK2BAAV,0011200001DyKFAAA3,0011200001DyLr8AAF,0011200001DyNIQAA3,0011200001DyNJHAA3,0011200001DyNdZAAV,0011200001DyNycAAF,0011200001DyPHUAA3,0011200001DyQeIAAV,0011200001DyS64AAF, ... (190 more): []
Class.DivisionTriggerHandler.calculateCount: line 124, column 1
Trigger.DivisionTrigger: line 8, column 1
Trigger -
trigger DivisionTrigger on Division__c (after insert,after update,after delete) {
//if( Division__c.Account__c != Null || Division__c.Account__c == Null){
if ( trigger.isAfter ) {
if ( trigger.isInsert ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isUpdate ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isDelete ) {
DivisionTriggerHandler.calculateCount(trigger.old);
}
}
//}
}
Class -
public without sharing class DivisionTriggerHandler {
public static void calculateCount(List<Division__c> divisionList) {
System.debug(divisionList);
Set<Id> accIds = new Set<Id>();
for(Division__c dv: divisionList)
{
accIds.add(dv.Account__c);
}
System.debug(accIds);
if(accIds.size()>0)
{
Map<Id,Account> accMap = new Map<id, Account>([Select id, of_DIvisions__c ,of_Divisions_ever_having_AP__c ,of_Participated_Divisions__c ,of_Blacklisted_Divisions__c ,of_Awarded_Divisions__c from Account where Id in :accIds]);
List<Division__c> divList = [Select id,Account__c, RecordType.Name,First_Awarded_Date__c,Status__c,
First_Invoice_Load_Date__c,First_Participation_Date__c from Division__c where RecordType.Name in ('C2FO Division','International Division') and Account__r.RecordType.Name ='Strategic Supplier' and Account__c in: accIds];
Map<Id,List<Division__c>> AccDivMap = new Map<Id, List<Division__c>>();
for(Division__c dv: divList)
{
if(AccDivMap.containsKey(dv.Account__c))
{
List<Division__c> tempList = AccDivMap.get(dv.Account__c);
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
else{
List<Division__c> tempList = new List<Division__c>();
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
}
for(Id accId : accMap.keySet())
{
Account acc2 = accMap.get(accId);
System.debug(acc2);
acc2.of_Awarded_Divisions__c=0;
acc2.of_Blacklisted_Divisions__c=0;
acc2.of_DIvisions__c=0;
acc2.of_Divisions_ever_having_AP__c=0;
acc2.of_Participated_Divisions__c =0;
accMap.put(accId,acc2);
List<Division__c> tempDivisionlist = AccDivMap.get(accId);
System.debug(tempDivisionlist);
if(tempDivisionlist!=null)
{
for(Division__c div : tempDivisionlist)
{
System.debug(div.Status__c);
if(div.First_Awarded_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Awarded_Divisions__c != null)
{
acc.of_Awarded_Divisions__c = acc.of_Awarded_Divisions__c + 1;
}
else
{
acc.of_Awarded_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.Status__c=='Blacklisted')
{
System.debug('Hello I am here');
Account acc = accMap.get(div.Account__c);
if(acc.of_Blacklisted_Divisions__c != null)
{
acc.of_Blacklisted_Divisions__c = acc.of_Blacklisted_Divisions__c + 1;
}
else
{
acc.of_Blacklisted_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Awarded_Date__c ==null&&div.First_Participation_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Participated_Divisions__c != null)
{
acc.of_Participated_Divisions__c = acc.of_Participated_Divisions__c + 1;
}
else
{
acc.of_Participated_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Invoice_Load_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Divisions_ever_having_AP__c != null)
{
acc.of_Divisions_ever_having_AP__c = acc.of_Divisions_ever_having_AP__c + 1;
}
else
{
acc.of_Divisions_ever_having_AP__c = 1;
}
accMap.put(acc.Id,acc);
}
Account acc = accMap.get(div.Account__c);
if(acc.of_DIvisions__c != null)
{
acc.of_DIvisions__c = acc.of_DIvisions__c + 1;
}
else
{
acc.of_DIvisions__c = 1;
}
accMap.put(acc.Id,acc);
}
}
}
update accMap.values();
}
}
}
- nagendra kumar 21
- January 29, 2020
- Like
- 0
- Continue reading or reply
I need to unchecked the checkbox if second checkbox is clicked and vice-versa i need to change this on exiting lightning controller
Hi Everyone,
I have a Lightning component and contoller which have 2 group check boxes.
but now user able to select both checkboxes but we need it to change when a user select one the other one should get unchecked.
below are the Lightning controler for that. please let me know where to change and should i change anything anything on component also ?
******************
({
doInit : function (component,event,helper) {
var action = component.get("c.initApp");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set('v.pllist4',response.getReturnValue());
component.set("v.sobjDetail.Technology__c",true);
}
else if (state === "INCOMPLETE") {
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
},
****************************
- nagendra kumar 21
- August 13, 2019
- Like
- 0
- Continue reading or reply
Did any one ever worked on any project related to HR Management?? p
Hello Salesforce Geeks,
Did anyone ever worked on any project related to HR Management??
I need to submit some HR management related project as POC to my client, need some help and POC if anyone had please let me know.
Thanks
Nagendra
Did anyone ever worked on any project related to HR Management??
I need to submit some HR management related project as POC to my client, need some help and POC if anyone had please let me know.
Thanks
Nagendra
- nagendra kumar 21
- May 09, 2019
- Like
- 0
- Continue reading or reply
How can i change my code to pull the previous months currency data
Hi Everyone,
I have this Apex code which takes the current date currency value when i ran batch, but now my client want to see when ever i ran btach it should take previous month currency value
So how where and how shouuld i change the code to accomplish below req and code. please someone help me modify my code.
Every single day, financial exchange rates change according to the markets. So what we do, is instead of trying to grab the latest exchange rate every day, we wait until the previous month ends. Then we grab the average exchange rate for that previous month and inputted it into sfdc.
So in this example: We wait until February 2019 is done. Then come march 1st, 2019 we will be able to take the average exchange rate for the entire month of February 2019 and input it into sfdc.
This means that currently, for USD opportunities that close in February 2019, the exchnage rate for the month of January 2019 is used to do the conversion until we are able to go back and update our systems to include the month of february 2019 exchange rate.
This is my code :-
public class ForexCurrencyHandler {
public void processData () {
ExchangeRate exchangeRate = (ExchangeRate) JSON.deserialize(callPublicExchangeRateApi(), ExchangeRate.class);
// Need to populate date manually because we cannot use the "date" name as a variable since it's a reserved keyword
exchangeRate.currencyDate = Date.today();
String jsonDatedConversionRate = createDatedConversionRateJSON(exchangeRate);
insertDatedConversionRate(jsonDatedConversionRate);
}
public String callPublicExchangeRateApi(){
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.exchangeratesapi.io/latest?base=CAD&symbols=USD');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('callout 1 '+res.getStatuscode());
return res.getBody();
}
public String createDatedConversionRateJSON (ExchangeRate exchangeRate) {
DatedConversionRate conversionRate = new DatedConversionRate();
conversionRate.ConversionRate = exchangeRate.rates.get('USD');
conversionRate.IsoCode = 'USD';
conversionRate.StartDate = Date.today();
system.debug(conversionRate);
return JSON.serializePretty(conversionRate);
}
public void insertDatedConversionRate (String jsonDatedConversionRate) {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v44.0/sobjects/DatedConversionRate/');
String body = jsonDatedConversionRate;
req.setBody(body);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json');
req.setMethod('POST');
HttpResponse res = h.send(req);
System.debug('callout 2 '+res.getBody());
System.debug('callout 2 '+res.getStatuscode());
}
public class ExchangeRate
{
public map<String,Decimal> rates;
public String base;
public Date currencyDate;
}
}
I have this Apex code which takes the current date currency value when i ran batch, but now my client want to see when ever i ran btach it should take previous month currency value
So how where and how shouuld i change the code to accomplish below req and code. please someone help me modify my code.
Every single day, financial exchange rates change according to the markets. So what we do, is instead of trying to grab the latest exchange rate every day, we wait until the previous month ends. Then we grab the average exchange rate for that previous month and inputted it into sfdc.
So in this example: We wait until February 2019 is done. Then come march 1st, 2019 we will be able to take the average exchange rate for the entire month of February 2019 and input it into sfdc.
This means that currently, for USD opportunities that close in February 2019, the exchnage rate for the month of January 2019 is used to do the conversion until we are able to go back and update our systems to include the month of february 2019 exchange rate.
This is my code :-
public class ForexCurrencyHandler {
public void processData () {
ExchangeRate exchangeRate = (ExchangeRate) JSON.deserialize(callPublicExchangeRateApi(), ExchangeRate.class);
// Need to populate date manually because we cannot use the "date" name as a variable since it's a reserved keyword
exchangeRate.currencyDate = Date.today();
String jsonDatedConversionRate = createDatedConversionRateJSON(exchangeRate);
insertDatedConversionRate(jsonDatedConversionRate);
}
public String callPublicExchangeRateApi(){
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.exchangeratesapi.io/latest?base=CAD&symbols=USD');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('callout 1 '+res.getStatuscode());
return res.getBody();
}
public String createDatedConversionRateJSON (ExchangeRate exchangeRate) {
DatedConversionRate conversionRate = new DatedConversionRate();
conversionRate.ConversionRate = exchangeRate.rates.get('USD');
conversionRate.IsoCode = 'USD';
conversionRate.StartDate = Date.today();
system.debug(conversionRate);
return JSON.serializePretty(conversionRate);
}
public void insertDatedConversionRate (String jsonDatedConversionRate) {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v44.0/sobjects/DatedConversionRate/');
String body = jsonDatedConversionRate;
req.setBody(body);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json');
req.setMethod('POST');
HttpResponse res = h.send(req);
System.debug('callout 2 '+res.getBody());
System.debug('callout 2 '+res.getStatuscode());
}
public class ExchangeRate
{
public map<String,Decimal> rates;
public String base;
public Date currencyDate;
}
}
- nagendra kumar 21
- February 07, 2019
- Like
- 0
- Continue reading or reply
How to Write a scheduled class to update the Data Conversion Rate at the start of every month.
Hi All,
please help me developing code or share code who to write apex class for this scenario and how to schedule it.
req -
thanks
nagendra
please help me developing code or share code who to write apex class for this scenario and how to schedule it.
req -
1) Fetch the exchange rate (CAN/USD) from some publicly available api using apex
2) Given this exchange rate create a Currency Conversion Record with the correct start date, end date and exchange rate.
3) Run a scheduled job to run (1) and (2) once per month.
2) Given this exchange rate create a Currency Conversion Record with the correct start date, end date and exchange rate.
3) Run a scheduled job to run (1) and (2) once per month.
thanks
nagendra
- nagendra kumar 21
- January 09, 2019
- Like
- 0
- Continue reading or reply
I need to Query a list of Account which have 1 or more records under a child record under the account using workbench
I need to see the the account which have 1 or more records for X child object.
Parent - Account
Child - Account team.
using work bench i need to see the which account have 1 or more records in Account team.
Please help me with query to see the list.
Thanks,
Parent - Account
Child - Account team.
using work bench i need to see the which account have 1 or more records in Account team.
Please help me with query to see the list.
Thanks,
- nagendra kumar 21
- November 30, 2018
- Like
- 0
- Continue reading or reply
Field Service Lightning
Hi Everyone,
Does anyone know/working on Field service lightning?
I have to create a real-time POC for my client which I’m working now.
Could anyone please help if you know about it
Does anyone know/working on Field service lightning?
I have to create a real-time POC for my client which I’m working now.
Could anyone please help if you know about it
- nagendra kumar 21
- October 18, 2016
- Like
- 1
- Continue reading or reply
System.ListException: Duplicate id in list: 00vj000000R4iTTAAZ line 198, column 1
Hi Everyone,
I'm bad in coding and new to salesforce, in my team tester got this error while testing some scenario i would like to share here and hoping someone can fix this error for me,
Below is the error message that he got.
Apex script unhandled exception by user/organization: 0057A0000016sh1/00D7A0000000Q5l Source organization: 00Dj0000001scFo (null) Visualforce Page: /apex/LogAnInteraction
caused by: System.ListException: Duplicate id in list: 00vj000000R4iTTAAZ
Class.LogAnInteractionExtension.save: line 198, column 1
************
I'm bad in coding and new to salesforce, in my team tester got this error while testing some scenario i would like to share here and hoping someone can fix this error for me,
Below is the error message that he got.
Apex script unhandled exception by user/organization: 0057A0000016sh1/00D7A0000000Q5l Source organization: 00Dj0000001scFo (null) Visualforce Page: /apex/LogAnInteraction
caused by: System.ListException: Duplicate id in list: 00vj000000R4iTTAAZ
Class.LogAnInteractionExtension.save: line 198, column 1
************
public with sharing class LogAnInteractionExtension { public Task task; public string taskId; public Set<Id> accContactIds = new Set<Id>(); public Set<Id> cmpgnContactIds = new Set<Id>(); public List<Campaign> relatedCampaigns {get;set;} public Account thisAccount {get;set;} public String AccName {get;set;} public list<CampaignWrapper> CampaignWrapperList {get;set;} private Task currentTaskRecord; public Account currentAccountRecord; public Contact currentContactRecord; public string LeadId; public ID accId; public Account acc {get;set;} Set<Id> selectedIdCamp = new Set<Id>(); public List<CampaignMember> campMem= new List<CampaignMember>(); public List<CampaignMember> updateConMem= new List<CampaignMember>(); public static final String DECLINED_CM_STATUS = 'Declined'; public static final String FULFILLED_CM_STATUS = 'Fulfilled'; private final string Campaign_Activity_RecType = Label.RT_CampaignActivity; public boolean isWater{get;set;} @testVisible private boolean testRun{get;set;} ApexPages.Standardcontroller controller; String CAMPAIGN_ACTIVITY_RECTYPEID = Schema.SObjectType.Task.getRecordTypeInfosByName().get(Campaign_Activity_RecType).getRecordTypeId(); //Controller public LogAnInteractionExtension(ApexPages.StandardController controller) { //check to see if profile is water isWater = false; testRun = false; String profileName=[Select Id,Name from Profile where Id=:userinfo.getProfileId()].Name; for(WaterProfiles__c setting : WaterProfiles__c.getAll().values()){ if (setting.Profile_Name__c == profileName) { isWater=true; } } this.task = (Task)controller.getRecord(); this.task.Status = 'Completed'; this.task.ActivityDate = system.today(); this.task.Interaction_Origin__c = ''; this.task.RecordTypeId = ApexPages.currentPage().getParameters().get('RecordType'); //System.debug('@@Record Type' + this.task.RecordTypeId); this.task.Date_of_Activity__c = date.today(); this.task.order__c = ApexPages.currentPage().getParameters().get('orderId'); User u = [Select Id From User Where id = :UserInfo.getUserId()]; task.OwnerId = u.Id; this.controller = controller; if(isWater || testRun){ LeadId = ApexPages.currentPage().getParameters().get('who_id'); if(!String.isBlank(ApexPages.currentPage().getParameters().get('what_id'))){ System.debug('ACC' + ApexPages.currentPage().getParameters().get('what_id')); this.currentAccountRecord = [Select Id From Account Where Id = :ApexPages.currentPage().getParameters().get('what_id')]; accId = currentAccountRecord.Id; } else if(!String.isBlank(ApexPages.currentPage().getParameters().get('who_id'))) { task.whoId = LeadId; } else{ this.currentContactRecord = [SELECT Id, AccountID from Contact WHERE ID =:ApexPages.currentPage().getParameters().get('who_id')]; accId = currentContactRecord.AccountID; } } else{ //fetch all the contacts present on the Account if(!String.isBlank(ApexPages.currentPage().getParameters().get('what_id'))){ this.currentAccountRecord = [Select Id From Account Where Id = :ApexPages.currentPage().getParameters().get('what_id')]; accId = currentAccountRecord.Id; } else if(!String.isBlank(ApexPages.currentPage().getParameters().get('who_id'))){ this.currentContactRecord = [SELECT Id, AccountID from Contact WHERE ID =:ApexPages.currentPage().getParameters().get('who_id')]; accId = currentContactRecord.AccountID; task.whoId = ApexPages.currentPage().getParameters().get('who_id'); } } if(accId != null){ task.WhatId = accId; } thisAccount = new Account(); for(Account acc : [select id,Name,Top_200_Ranking__c,(select Id,Name from Contacts ) From Account where id = :accId ]) { thisAccount = acc; for(Contact cnt: acc.contacts){ accContactIds.add(cnt.Id); } } //fetch all the campaigns related to the Account relatedCampaigns = new List<Campaign>(); getrelatedcampains(); CampaignWrapperList = new List<CampaignWrapper>(); Map<Id, List<SelectOption>> campaignRelatedStatus = new Map<Id, List<SelectOption>>(); for(CampaignMemberStatus cms : [Select Id, CampaignId, Label From CampaignMemberStatus WHERE CampaignId IN :relatedCampaigns ORDER BY CampaignId]){ SelectOption option = new SelectOption(cms.Label, cms.Label); if(!campaignRelatedStatus.containsKey(cms.CampaignId)){ campaignRelatedStatus.put(cms.CampaignId, new List<SelectOption>{option}); } else{ List<SelectOption> existingValues = new List<SelectOption>(); existingValues = campaignRelatedStatus.get(cms.CampaignId); existingValues.add(option); campaignRelatedStatus.put(cms.CampaignId,existingValues); } } for(Campaign cmp : relatedCampaigns) { for(CampaignMember cmpmem : cmp.CampaignMembers) { CampaignWrapperList.add(new CampaignWrapper (cmp, cmpmem.Status, cmpmem.Name, cmpmem, campaignRelatedStatus.get(cmp.Id))); } } } public void getrelatedcampains() { for(Campaign c : [Select Name, status, StartDate, Type, Id, (Select Name, CampaignId, ContactId, Status, HasResponded, Contact.AccountId from CampaignMembers where Contact.AccountId =:accId and status!=: DECLINED_CM_STATUS and status!=: FULFILLED_CM_STATUS ORDER By LastModifiedDate DESC ) from Campaign where isActive = true ]) { relatedCampaigns.add(c); } } public class CampaignWrapper { //Fetch Campaign details public Campaign campgn {get; set;} public String CampStatus {get; set;} public List<SelectOption> statusValues {get;set;} public String campMemName {get; set;} public CampaignMember campgnMember {get; set;} //select checkbox public Boolean selectCheck {get;set;} public CampaignWrapper(Campaign c, String CampStatus, String campMemName, CampaignMember campgnMember, List<SelectOption> statuses) { campgn = c; selectCheck= false; this.CampStatus = CampStatus; this.campMemName = campMemName; this.campgnMember = campgnMember; statusValues = statuses; } } public PageReference save() { String selectedcampId = ''; task.Top_200_Account__c = String.valueOf(thisAccount.Top_200_Ranking__c); List<Task> newtaskList = new List<Task>(); Task tempTask; if(!CampaignWrapperList.isEmpty()) { for(CampaignWrapper cm : CampaignWrapperList){ if(cm.selectCheck == true) { tempTask = new Task(Subject = task.Subject,RecordTypeId = CAMPAIGN_ACTIVITY_RECTYPEID,Status =task.Status, Top_200_Account__c = task.Top_200_Account__c,Interaction_Origin__c = task.Interaction_Origin__c, Activity_Account__c = task.WhatId,Activity_Descriptions__c = task.Activity_Descriptions__c,WhatId = cm.campgn.id, Campaign_Member_Name__c = cm.campMemName , Campaign_Member_Status__c = cm.CampStatus ); newtaskList.add(tempTask); cm.campgnMember.Status = cm.CampStatus; system.debug(cm.campgnmember); updateConMem.add(cm.campgnMember); } if(cm.selectCheck) { selectedIdCamp.add(cm.campgnMember.Id); if(selectedcampId =='') selectedcampId = cm.campgnMember.Id; else { selectedcampId = selectedcampId + ';'+cm.campgnMember.Id; } } } update updateConMem; string selectcmpIds= selectedcampId ; this.task.selectedcampaign__c= selectcmpIds; } try{ if(!newtaskList.isEmpty()){ insert newtaskList; } upsert task; PageReference pr = new PageReference('/'+task.Id); return pr; }catch(DMLException e){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,Label.Log_An_Interaction_Error)); SystemLoggingService.log(e); return null; }catch(Exception e){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()); ApexPages.addmessage(myMsg); return null; } } public PageReference cancel(){ PageReference page; if( ApexPages.currentPage().getParameters().get('what_id') != null && ApexPages.currentPage().getParameters().get('what_id') ==task.WhatId ){ page = new PageReference('/'+task.WhatId ); } else{ page = new PageReference('/'+task.whoId); } page.setRedirect(true); return page; } public PageReference saveNew() { PageReference pr; try{ controller.save(); Schema.DescribeSObjectResult describeResult = controller.getRecord().getSObjectType().getDescribe(); //pr = new PageReference('/' + describeResult.getKeyPrefix() + '/e'); pr = new PageReference('/setup/ui/recordtypeselect.jsp?ent=Task' ); pr.setRedirect(true); return pr; }catch(Exception e) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage())); return null; }//try }//saveNew }
- nagendra kumar 21
- October 03, 2016
- Like
- 0
- Continue reading or reply
How to Update custom setting values, when sandbox get refreshed from prod?
Hi Everyone,
Currently we are manually changing/updating custom field values every time we did refresh from production. But we have different values in Production and sandbox, when we refreshed sandbox values are getting Prod values and we are doing manual changes to them.
To avoid this manual change is there any other way that can be auto update to old values whenever refresh is done??
Note: - we can do I with Apex scheduler "but we don’t want to go with code" other than Apex please suggest any other flow.
any suggestions are appreciated
Currently we are manually changing/updating custom field values every time we did refresh from production. But we have different values in Production and sandbox, when we refreshed sandbox values are getting Prod values and we are doing manual changes to them.
To avoid this manual change is there any other way that can be auto update to old values whenever refresh is done??
Note: - we can do I with Apex scheduler "but we don’t want to go with code" other than Apex please suggest any other flow.
any suggestions are appreciated
- nagendra kumar 21
- September 29, 2016
- Like
- 0
- Continue reading or reply
What is "Aria Workforce management."
Talent tool for data loader
Hello Everyone,
I recently placed in one firm as Salesforce Consultant and I’m new to Salesforce.
in my company they wanted to implement "Workforce Management" WFM and for that they wanted to purchase Salesforce AppExchange named "Aria".
Can anyone please tell me on
1. What is Workforce management?
2. For what they will Use this?
3. How can we work in it?
4. Did anyone ever work on Aria WFM?
Any suggestions are appreciated.
Thanks in Advance,
Thanks,
Nagendra
Hello Everyone,
I recently placed in one firm as Salesforce Consultant and I’m new to Salesforce.
in my company they wanted to implement "Workforce Management" WFM and for that they wanted to purchase Salesforce AppExchange named "Aria".
Can anyone please tell me on
1. What is Workforce management?
2. For what they will Use this?
3. How can we work in it?
4. Did anyone ever work on Aria WFM?
Any suggestions are appreciated.
Thanks in Advance,
Thanks,
Nagendra
- nagendra kumar 21
- September 26, 2016
- Like
- 0
- Continue reading or reply
Getting Error "Error: Duplicate Values" While Adding New Values on Standard field INDUSTRY .
Hi Every One,
I'm trying to add new pick list values on Standard fields "Industry" On Account Object. After adding values and while saving I’m getting "Error: Duplicate Values" but they are new values. can anyone please give let me know how to fix this error?
Thanks in Advance,
Nagendra
I'm trying to add new pick list values on Standard fields "Industry" On Account Object. After adding values and while saving I’m getting "Error: Duplicate Values" but they are new values. can anyone please give let me know how to fix this error?
Thanks in Advance,
Nagendra
- nagendra kumar 21
- August 22, 2016
- Like
- 2
- Continue reading or reply
Code coverage of 79% in sandbox but only 45% in production - won't deploy
Hi Everyone, Here i'm facing an issue while deploying my code to Prodection.
I'm a new Bee to SFDC, and i took forms help and others help i wrote a Test class, When i ran it in Dev Org i'm getting 79% code coverage but when i'm trying to deploy it to production it is showing code coverage was 45% as a Error, I have no clue why it is happening. Below i'm giving you my test code, please can any one check what is going on with my code.
@isTest(SeeAllData = False)
public With Sharing class Test_AccountSalesviewTriggerHandler{
static testMethod void testAccountSalesview_Create(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
tempSV.Price_Group__c = 'DD';
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Update(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
List < Account_Salesview__c > lstsalesviewrecordsupdate = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
Integer i = 0;
for (Account_Salesview__c tempSV : lstsalesviewrecords){
tempSV.Name = 'ABCD';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx1234'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecordsupdate.add(tempSV);
i++;
}
update lstsalesviewrecordsupdate;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Delete(){
Account acc = CreateTestClassData.createCustomerAccount();
//Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
delete lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
}
I'm a new Bee to SFDC, and i took forms help and others help i wrote a Test class, When i ran it in Dev Org i'm getting 79% code coverage but when i'm trying to deploy it to production it is showing code coverage was 45% as a Error, I have no clue why it is happening. Below i'm giving you my test code, please can any one check what is going on with my code.
@isTest(SeeAllData = False)
public With Sharing class Test_AccountSalesviewTriggerHandler{
static testMethod void testAccountSalesview_Create(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
tempSV.Price_Group__c = 'DD';
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Update(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
List < Account_Salesview__c > lstsalesviewrecordsupdate = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
Integer i = 0;
for (Account_Salesview__c tempSV : lstsalesviewrecords){
tempSV.Name = 'ABCD';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx1234'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecordsupdate.add(tempSV);
i++;
}
update lstsalesviewrecordsupdate;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Delete(){
Account acc = CreateTestClassData.createCustomerAccount();
//Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
delete lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
}
- nagendra kumar 21
- July 15, 2016
- Like
- 0
- Continue reading or reply
Update the parent field value based on child field value using workflows/Apex
Hello Everyone,
I would like to know what should i use update a field on Account object based on chiled objects fields on account.
I Have created a Checkbox field on Account, and it needs to be True if
account division field is 'xx' and MFD field (checkbox) is 'False' then the fiel on account which i created should be True(check) and they should no longer show up as a 'abc customer'
, If not false(uncheck)..
Please suggest me how can i do this.. If i need to write a code for this please provide a smaple code for it..
Any suggestions is appriceated.
Thanks,
Nag
I would like to know what should i use update a field on Account object based on chiled objects fields on account.
I Have created a Checkbox field on Account, and it needs to be True if
account division field is 'xx' and MFD field (checkbox) is 'False' then the fiel on account which i created should be True(check) and they should no longer show up as a 'abc customer'
, If not false(uncheck)..
Please suggest me how can i do this.. If i need to write a code for this please provide a smaple code for it..
Any suggestions is appriceated.
Thanks,
Nag
- nagendra kumar 21
- July 10, 2016
- Like
- 0
- Continue reading or reply
"Save" button Not working for Case Comment in SF1
Hi All,
I could see Save and Cancel buttons in my VFP. But Save button is not highlighted and it isn't working. I used the same code as above. Please help.
Belowe code i used for this.
https://gist.github.com/Karanraj/6bd1ffc13252b0a22ae0
I could see Save and Cancel buttons in my VFP. But Save button is not highlighted and it isn't working. I used the same code as above. Please help.
Belowe code i used for this.
https://gist.github.com/Karanraj/6bd1ffc13252b0a22ae0
- nagendra kumar 21
- May 19, 2015
- Like
- 0
- Continue reading or reply
Voicemail to Case CX
Hi Everyone,
I'm Up-To-The-Minute to Saleforce.com, Recently i got placed at a top IT company, They assigend me a project name "Voicemail to Case CX".
Can anyone please Brief Me about What is "Voicemail to Case CX" and is ther any suggestable links,
And i would be appricate if you any could help me in Coding part too.
I'm Up-To-The-Minute to Saleforce.com, Recently i got placed at a top IT company, They assigend me a project name "Voicemail to Case CX".
Can anyone please Brief Me about What is "Voicemail to Case CX" and is ther any suggestable links,
And i would be appricate if you any could help me in Coding part too.
- nagendra kumar 21
- March 25, 2015
- Like
- 0
- Continue reading or reply
Field Service Lightning
Hi Everyone,
Does anyone know/working on Field service lightning?
I have to create a real-time POC for my client which I’m working now.
Could anyone please help if you know about it
Does anyone know/working on Field service lightning?
I have to create a real-time POC for my client which I’m working now.
Could anyone please help if you know about it
- nagendra kumar 21
- October 18, 2016
- Like
- 1
- Continue reading or reply
Getting Error "Error: Duplicate Values" While Adding New Values on Standard field INDUSTRY .
Hi Every One,
I'm trying to add new pick list values on Standard fields "Industry" On Account Object. After adding values and while saving I’m getting "Error: Duplicate Values" but they are new values. can anyone please give let me know how to fix this error?
Thanks in Advance,
Nagendra
I'm trying to add new pick list values on Standard fields "Industry" On Account Object. After adding values and while saving I’m getting "Error: Duplicate Values" but they are new values. can anyone please give let me know how to fix this error?
Thanks in Advance,
Nagendra
- nagendra kumar 21
- August 22, 2016
- Like
- 2
- Continue reading or reply
how to reduce the batch job running process.
hi everyone, how to reduce the batch run time ?? when I ran the batch it took 2 days to complete it which is a lot time for business to check the changes, is there any way we can reduce it ??
- nagendra kumar 21
- June 08, 2020
- Like
- 0
- Continue reading or reply
System.DmlException: Update failed. First exception on row 0 with id 0011200001DyK2BAAV; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records
Hi Everyone,
I have trigger and class for a custom object, and in prod when data updated or loaded to the custom object I'm getting this error. can anyone please give a solution for this, I'm new to coding.
Error --
External E-Mail – Verify Email Address, Links, and Attachments
Apex script unhandled trigger exception by user/organization: 005A0000004JEGW/00DA0000000C46b
DivisionTrigger: execution of AfterUpdate
caused by: System.DmlException: Update failed. First exception on row 0 with id 0011200001DyK2BAAV; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records: 0011200001DyK2BAAV,0011200001DyKFAAA3,0011200001DyLr8AAF,0011200001DyNIQAA3,0011200001DyNJHAA3,0011200001DyNdZAAV,0011200001DyNycAAF,0011200001DyPHUAA3,0011200001DyQeIAAV,0011200001DyS64AAF, ... (190 more): []
Class.DivisionTriggerHandler.calculateCount: line 124, column 1
Trigger.DivisionTrigger: line 8, column 1
Trigger -
trigger DivisionTrigger on Division__c (after insert,after update,after delete) {
//if( Division__c.Account__c != Null || Division__c.Account__c == Null){
if ( trigger.isAfter ) {
if ( trigger.isInsert ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isUpdate ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isDelete ) {
DivisionTriggerHandler.calculateCount(trigger.old);
}
}
//}
}
Class -
public without sharing class DivisionTriggerHandler {
public static void calculateCount(List<Division__c> divisionList) {
System.debug(divisionList);
Set<Id> accIds = new Set<Id>();
for(Division__c dv: divisionList)
{
accIds.add(dv.Account__c);
}
System.debug(accIds);
if(accIds.size()>0)
{
Map<Id,Account> accMap = new Map<id, Account>([Select id, of_DIvisions__c ,of_Divisions_ever_having_AP__c ,of_Participated_Divisions__c ,of_Blacklisted_Divisions__c ,of_Awarded_Divisions__c from Account where Id in :accIds]);
List<Division__c> divList = [Select id,Account__c, RecordType.Name,First_Awarded_Date__c,Status__c,
First_Invoice_Load_Date__c,First_Participation_Date__c from Division__c where RecordType.Name in ('C2FO Division','International Division') and Account__r.RecordType.Name ='Strategic Supplier' and Account__c in: accIds];
Map<Id,List<Division__c>> AccDivMap = new Map<Id, List<Division__c>>();
for(Division__c dv: divList)
{
if(AccDivMap.containsKey(dv.Account__c))
{
List<Division__c> tempList = AccDivMap.get(dv.Account__c);
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
else{
List<Division__c> tempList = new List<Division__c>();
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
}
for(Id accId : accMap.keySet())
{
Account acc2 = accMap.get(accId);
System.debug(acc2);
acc2.of_Awarded_Divisions__c=0;
acc2.of_Blacklisted_Divisions__c=0;
acc2.of_DIvisions__c=0;
acc2.of_Divisions_ever_having_AP__c=0;
acc2.of_Participated_Divisions__c =0;
accMap.put(accId,acc2);
List<Division__c> tempDivisionlist = AccDivMap.get(accId);
System.debug(tempDivisionlist);
if(tempDivisionlist!=null)
{
for(Division__c div : tempDivisionlist)
{
System.debug(div.Status__c);
if(div.First_Awarded_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Awarded_Divisions__c != null)
{
acc.of_Awarded_Divisions__c = acc.of_Awarded_Divisions__c + 1;
}
else
{
acc.of_Awarded_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.Status__c=='Blacklisted')
{
System.debug('Hello I am here');
Account acc = accMap.get(div.Account__c);
if(acc.of_Blacklisted_Divisions__c != null)
{
acc.of_Blacklisted_Divisions__c = acc.of_Blacklisted_Divisions__c + 1;
}
else
{
acc.of_Blacklisted_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Awarded_Date__c ==null&&div.First_Participation_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Participated_Divisions__c != null)
{
acc.of_Participated_Divisions__c = acc.of_Participated_Divisions__c + 1;
}
else
{
acc.of_Participated_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Invoice_Load_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Divisions_ever_having_AP__c != null)
{
acc.of_Divisions_ever_having_AP__c = acc.of_Divisions_ever_having_AP__c + 1;
}
else
{
acc.of_Divisions_ever_having_AP__c = 1;
}
accMap.put(acc.Id,acc);
}
Account acc = accMap.get(div.Account__c);
if(acc.of_DIvisions__c != null)
{
acc.of_DIvisions__c = acc.of_DIvisions__c + 1;
}
else
{
acc.of_DIvisions__c = 1;
}
accMap.put(acc.Id,acc);
}
}
}
update accMap.values();
}
}
}
I have trigger and class for a custom object, and in prod when data updated or loaded to the custom object I'm getting this error. can anyone please give a solution for this, I'm new to coding.
Error --
External E-Mail – Verify Email Address, Links, and Attachments
Apex script unhandled trigger exception by user/organization: 005A0000004JEGW/00DA0000000C46b
DivisionTrigger: execution of AfterUpdate
caused by: System.DmlException: Update failed. First exception on row 0 with id 0011200001DyK2BAAV; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records: 0011200001DyK2BAAV,0011200001DyKFAAA3,0011200001DyLr8AAF,0011200001DyNIQAA3,0011200001DyNJHAA3,0011200001DyNdZAAV,0011200001DyNycAAF,0011200001DyPHUAA3,0011200001DyQeIAAV,0011200001DyS64AAF, ... (190 more): []
Class.DivisionTriggerHandler.calculateCount: line 124, column 1
Trigger.DivisionTrigger: line 8, column 1
Trigger -
trigger DivisionTrigger on Division__c (after insert,after update,after delete) {
//if( Division__c.Account__c != Null || Division__c.Account__c == Null){
if ( trigger.isAfter ) {
if ( trigger.isInsert ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isUpdate ) {
DivisionTriggerHandler.calculateCount(trigger.new);
}
else if ( trigger.isDelete ) {
DivisionTriggerHandler.calculateCount(trigger.old);
}
}
//}
}
Class -
public without sharing class DivisionTriggerHandler {
public static void calculateCount(List<Division__c> divisionList) {
System.debug(divisionList);
Set<Id> accIds = new Set<Id>();
for(Division__c dv: divisionList)
{
accIds.add(dv.Account__c);
}
System.debug(accIds);
if(accIds.size()>0)
{
Map<Id,Account> accMap = new Map<id, Account>([Select id, of_DIvisions__c ,of_Divisions_ever_having_AP__c ,of_Participated_Divisions__c ,of_Blacklisted_Divisions__c ,of_Awarded_Divisions__c from Account where Id in :accIds]);
List<Division__c> divList = [Select id,Account__c, RecordType.Name,First_Awarded_Date__c,Status__c,
First_Invoice_Load_Date__c,First_Participation_Date__c from Division__c where RecordType.Name in ('C2FO Division','International Division') and Account__r.RecordType.Name ='Strategic Supplier' and Account__c in: accIds];
Map<Id,List<Division__c>> AccDivMap = new Map<Id, List<Division__c>>();
for(Division__c dv: divList)
{
if(AccDivMap.containsKey(dv.Account__c))
{
List<Division__c> tempList = AccDivMap.get(dv.Account__c);
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
else{
List<Division__c> tempList = new List<Division__c>();
tempList.add(dv);
AccDivMap.put(dv.Account__c, tempList);
}
}
for(Id accId : accMap.keySet())
{
Account acc2 = accMap.get(accId);
System.debug(acc2);
acc2.of_Awarded_Divisions__c=0;
acc2.of_Blacklisted_Divisions__c=0;
acc2.of_DIvisions__c=0;
acc2.of_Divisions_ever_having_AP__c=0;
acc2.of_Participated_Divisions__c =0;
accMap.put(accId,acc2);
List<Division__c> tempDivisionlist = AccDivMap.get(accId);
System.debug(tempDivisionlist);
if(tempDivisionlist!=null)
{
for(Division__c div : tempDivisionlist)
{
System.debug(div.Status__c);
if(div.First_Awarded_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Awarded_Divisions__c != null)
{
acc.of_Awarded_Divisions__c = acc.of_Awarded_Divisions__c + 1;
}
else
{
acc.of_Awarded_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.Status__c=='Blacklisted')
{
System.debug('Hello I am here');
Account acc = accMap.get(div.Account__c);
if(acc.of_Blacklisted_Divisions__c != null)
{
acc.of_Blacklisted_Divisions__c = acc.of_Blacklisted_Divisions__c + 1;
}
else
{
acc.of_Blacklisted_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Awarded_Date__c ==null&&div.First_Participation_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Participated_Divisions__c != null)
{
acc.of_Participated_Divisions__c = acc.of_Participated_Divisions__c + 1;
}
else
{
acc.of_Participated_Divisions__c = 1;
}
accMap.put(acc.Id,acc);
}
if(div.First_Invoice_Load_Date__c!=null)
{
Account acc = accMap.get(div.Account__c);
if(acc.of_Divisions_ever_having_AP__c != null)
{
acc.of_Divisions_ever_having_AP__c = acc.of_Divisions_ever_having_AP__c + 1;
}
else
{
acc.of_Divisions_ever_having_AP__c = 1;
}
accMap.put(acc.Id,acc);
}
Account acc = accMap.get(div.Account__c);
if(acc.of_DIvisions__c != null)
{
acc.of_DIvisions__c = acc.of_DIvisions__c + 1;
}
else
{
acc.of_DIvisions__c = 1;
}
accMap.put(acc.Id,acc);
}
}
}
update accMap.values();
}
}
}
- nagendra kumar 21
- January 29, 2020
- Like
- 0
- Continue reading or reply
I need to unchecked the checkbox if second checkbox is clicked and vice-versa i need to change this on exiting lightning controller
Hi Everyone,
I have a Lightning component and contoller which have 2 group check boxes.
but now user able to select both checkboxes but we need it to change when a user select one the other one should get unchecked.
below are the Lightning controler for that. please let me know where to change and should i change anything anything on component also ?
******************
({
doInit : function (component,event,helper) {
var action = component.get("c.initApp");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set('v.pllist4',response.getReturnValue());
component.set("v.sobjDetail.Technology__c",true);
}
else if (state === "INCOMPLETE") {
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
},
****************************
- nagendra kumar 21
- August 13, 2019
- Like
- 0
- Continue reading or reply
how to get one component's attribute in another component in lightning component
Hi Friends
I am facing a issue with how can to get one components attribute value to another component
I have Two components 1) FormComponent and 2) PrintComponent
I need FormComponent's OppId attribute in PrintForm's Java script controller.
How can i get the attribute?
Below is the code skeleton
FormComponent.cmp
----------------
<aura:component controller="FormController">
<aura:attribute name="oppId" type="String" default=""/>
<lightning:layout>
<lightning:layoutItem padding="horizontal-small" largeDeviceSize="3" mediumDeviceSize="3" smallDeviceSize="12" size="12">
<lightning:button variant="brand" label="Print Forms" title="Print Loan Agreement" onclick="{!c.printForms}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
FormComponentcontroller.js
------------------------------
({
doInit: function(component, event, helper){
},
printForms : function(component, event, helper){
// need to send oppId to another component PrintForm
}
})
PrintForm.cmp
-------------
<aura:component implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global"
controller="PrintController">
<aura:attribute name="oppId" type="String" default=""/>
<!-- logic to implement the datatable to view the data -->
</aura:component>
PrintFormController.js
-----------------------
{
doInit: function(component, event, helper){
// how can i get the oppId value from Form component
},
I am facing a issue with how can to get one components attribute value to another component
I have Two components 1) FormComponent and 2) PrintComponent
I need FormComponent's OppId attribute in PrintForm's Java script controller.
How can i get the attribute?
Below is the code skeleton
FormComponent.cmp
----------------
<aura:component controller="FormController">
<aura:attribute name="oppId" type="String" default=""/>
<lightning:layout>
<lightning:layoutItem padding="horizontal-small" largeDeviceSize="3" mediumDeviceSize="3" smallDeviceSize="12" size="12">
<lightning:button variant="brand" label="Print Forms" title="Print Loan Agreement" onclick="{!c.printForms}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
FormComponentcontroller.js
------------------------------
({
doInit: function(component, event, helper){
},
printForms : function(component, event, helper){
// need to send oppId to another component PrintForm
}
})
PrintForm.cmp
-------------
<aura:component implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global"
controller="PrintController">
<aura:attribute name="oppId" type="String" default=""/>
<!-- logic to implement the datatable to view the data -->
</aura:component>
PrintFormController.js
-----------------------
{
doInit: function(component, event, helper){
// how can i get the oppId value from Form component
},
- Rakesh Imsani
- August 12, 2019
- Like
- 0
- Continue reading or reply
How to Write a scheduled class to update the Data Conversion Rate at the start of every month.
Hi All,
please help me developing code or share code who to write apex class for this scenario and how to schedule it.
req -
thanks
nagendra
please help me developing code or share code who to write apex class for this scenario and how to schedule it.
req -
1) Fetch the exchange rate (CAN/USD) from some publicly available api using apex
2) Given this exchange rate create a Currency Conversion Record with the correct start date, end date and exchange rate.
3) Run a scheduled job to run (1) and (2) once per month.
2) Given this exchange rate create a Currency Conversion Record with the correct start date, end date and exchange rate.
3) Run a scheduled job to run (1) and (2) once per month.
thanks
nagendra
- nagendra kumar 21
- January 09, 2019
- Like
- 0
- Continue reading or reply
Field Service Lightning
Hi Everyone,
Does anyone know/working on Field service lightning?
I have to create a real-time POC for my client which I’m working now.
Could anyone please help if you know about it
Does anyone know/working on Field service lightning?
I have to create a real-time POC for my client which I’m working now.
Could anyone please help if you know about it
- nagendra kumar 21
- October 18, 2016
- Like
- 1
- Continue reading or reply
System.ListException: Duplicate id in list: 00vj000000R4iTTAAZ line 198, column 1
Hi Everyone,
I'm bad in coding and new to salesforce, in my team tester got this error while testing some scenario i would like to share here and hoping someone can fix this error for me,
Below is the error message that he got.
Apex script unhandled exception by user/organization: 0057A0000016sh1/00D7A0000000Q5l Source organization: 00Dj0000001scFo (null) Visualforce Page: /apex/LogAnInteraction
caused by: System.ListException: Duplicate id in list: 00vj000000R4iTTAAZ
Class.LogAnInteractionExtension.save: line 198, column 1
************
I'm bad in coding and new to salesforce, in my team tester got this error while testing some scenario i would like to share here and hoping someone can fix this error for me,
Below is the error message that he got.
Apex script unhandled exception by user/organization: 0057A0000016sh1/00D7A0000000Q5l Source organization: 00Dj0000001scFo (null) Visualforce Page: /apex/LogAnInteraction
caused by: System.ListException: Duplicate id in list: 00vj000000R4iTTAAZ
Class.LogAnInteractionExtension.save: line 198, column 1
************
public with sharing class LogAnInteractionExtension { public Task task; public string taskId; public Set<Id> accContactIds = new Set<Id>(); public Set<Id> cmpgnContactIds = new Set<Id>(); public List<Campaign> relatedCampaigns {get;set;} public Account thisAccount {get;set;} public String AccName {get;set;} public list<CampaignWrapper> CampaignWrapperList {get;set;} private Task currentTaskRecord; public Account currentAccountRecord; public Contact currentContactRecord; public string LeadId; public ID accId; public Account acc {get;set;} Set<Id> selectedIdCamp = new Set<Id>(); public List<CampaignMember> campMem= new List<CampaignMember>(); public List<CampaignMember> updateConMem= new List<CampaignMember>(); public static final String DECLINED_CM_STATUS = 'Declined'; public static final String FULFILLED_CM_STATUS = 'Fulfilled'; private final string Campaign_Activity_RecType = Label.RT_CampaignActivity; public boolean isWater{get;set;} @testVisible private boolean testRun{get;set;} ApexPages.Standardcontroller controller; String CAMPAIGN_ACTIVITY_RECTYPEID = Schema.SObjectType.Task.getRecordTypeInfosByName().get(Campaign_Activity_RecType).getRecordTypeId(); //Controller public LogAnInteractionExtension(ApexPages.StandardController controller) { //check to see if profile is water isWater = false; testRun = false; String profileName=[Select Id,Name from Profile where Id=:userinfo.getProfileId()].Name; for(WaterProfiles__c setting : WaterProfiles__c.getAll().values()){ if (setting.Profile_Name__c == profileName) { isWater=true; } } this.task = (Task)controller.getRecord(); this.task.Status = 'Completed'; this.task.ActivityDate = system.today(); this.task.Interaction_Origin__c = ''; this.task.RecordTypeId = ApexPages.currentPage().getParameters().get('RecordType'); //System.debug('@@Record Type' + this.task.RecordTypeId); this.task.Date_of_Activity__c = date.today(); this.task.order__c = ApexPages.currentPage().getParameters().get('orderId'); User u = [Select Id From User Where id = :UserInfo.getUserId()]; task.OwnerId = u.Id; this.controller = controller; if(isWater || testRun){ LeadId = ApexPages.currentPage().getParameters().get('who_id'); if(!String.isBlank(ApexPages.currentPage().getParameters().get('what_id'))){ System.debug('ACC' + ApexPages.currentPage().getParameters().get('what_id')); this.currentAccountRecord = [Select Id From Account Where Id = :ApexPages.currentPage().getParameters().get('what_id')]; accId = currentAccountRecord.Id; } else if(!String.isBlank(ApexPages.currentPage().getParameters().get('who_id'))) { task.whoId = LeadId; } else{ this.currentContactRecord = [SELECT Id, AccountID from Contact WHERE ID =:ApexPages.currentPage().getParameters().get('who_id')]; accId = currentContactRecord.AccountID; } } else{ //fetch all the contacts present on the Account if(!String.isBlank(ApexPages.currentPage().getParameters().get('what_id'))){ this.currentAccountRecord = [Select Id From Account Where Id = :ApexPages.currentPage().getParameters().get('what_id')]; accId = currentAccountRecord.Id; } else if(!String.isBlank(ApexPages.currentPage().getParameters().get('who_id'))){ this.currentContactRecord = [SELECT Id, AccountID from Contact WHERE ID =:ApexPages.currentPage().getParameters().get('who_id')]; accId = currentContactRecord.AccountID; task.whoId = ApexPages.currentPage().getParameters().get('who_id'); } } if(accId != null){ task.WhatId = accId; } thisAccount = new Account(); for(Account acc : [select id,Name,Top_200_Ranking__c,(select Id,Name from Contacts ) From Account where id = :accId ]) { thisAccount = acc; for(Contact cnt: acc.contacts){ accContactIds.add(cnt.Id); } } //fetch all the campaigns related to the Account relatedCampaigns = new List<Campaign>(); getrelatedcampains(); CampaignWrapperList = new List<CampaignWrapper>(); Map<Id, List<SelectOption>> campaignRelatedStatus = new Map<Id, List<SelectOption>>(); for(CampaignMemberStatus cms : [Select Id, CampaignId, Label From CampaignMemberStatus WHERE CampaignId IN :relatedCampaigns ORDER BY CampaignId]){ SelectOption option = new SelectOption(cms.Label, cms.Label); if(!campaignRelatedStatus.containsKey(cms.CampaignId)){ campaignRelatedStatus.put(cms.CampaignId, new List<SelectOption>{option}); } else{ List<SelectOption> existingValues = new List<SelectOption>(); existingValues = campaignRelatedStatus.get(cms.CampaignId); existingValues.add(option); campaignRelatedStatus.put(cms.CampaignId,existingValues); } } for(Campaign cmp : relatedCampaigns) { for(CampaignMember cmpmem : cmp.CampaignMembers) { CampaignWrapperList.add(new CampaignWrapper (cmp, cmpmem.Status, cmpmem.Name, cmpmem, campaignRelatedStatus.get(cmp.Id))); } } } public void getrelatedcampains() { for(Campaign c : [Select Name, status, StartDate, Type, Id, (Select Name, CampaignId, ContactId, Status, HasResponded, Contact.AccountId from CampaignMembers where Contact.AccountId =:accId and status!=: DECLINED_CM_STATUS and status!=: FULFILLED_CM_STATUS ORDER By LastModifiedDate DESC ) from Campaign where isActive = true ]) { relatedCampaigns.add(c); } } public class CampaignWrapper { //Fetch Campaign details public Campaign campgn {get; set;} public String CampStatus {get; set;} public List<SelectOption> statusValues {get;set;} public String campMemName {get; set;} public CampaignMember campgnMember {get; set;} //select checkbox public Boolean selectCheck {get;set;} public CampaignWrapper(Campaign c, String CampStatus, String campMemName, CampaignMember campgnMember, List<SelectOption> statuses) { campgn = c; selectCheck= false; this.CampStatus = CampStatus; this.campMemName = campMemName; this.campgnMember = campgnMember; statusValues = statuses; } } public PageReference save() { String selectedcampId = ''; task.Top_200_Account__c = String.valueOf(thisAccount.Top_200_Ranking__c); List<Task> newtaskList = new List<Task>(); Task tempTask; if(!CampaignWrapperList.isEmpty()) { for(CampaignWrapper cm : CampaignWrapperList){ if(cm.selectCheck == true) { tempTask = new Task(Subject = task.Subject,RecordTypeId = CAMPAIGN_ACTIVITY_RECTYPEID,Status =task.Status, Top_200_Account__c = task.Top_200_Account__c,Interaction_Origin__c = task.Interaction_Origin__c, Activity_Account__c = task.WhatId,Activity_Descriptions__c = task.Activity_Descriptions__c,WhatId = cm.campgn.id, Campaign_Member_Name__c = cm.campMemName , Campaign_Member_Status__c = cm.CampStatus ); newtaskList.add(tempTask); cm.campgnMember.Status = cm.CampStatus; system.debug(cm.campgnmember); updateConMem.add(cm.campgnMember); } if(cm.selectCheck) { selectedIdCamp.add(cm.campgnMember.Id); if(selectedcampId =='') selectedcampId = cm.campgnMember.Id; else { selectedcampId = selectedcampId + ';'+cm.campgnMember.Id; } } } update updateConMem; string selectcmpIds= selectedcampId ; this.task.selectedcampaign__c= selectcmpIds; } try{ if(!newtaskList.isEmpty()){ insert newtaskList; } upsert task; PageReference pr = new PageReference('/'+task.Id); return pr; }catch(DMLException e){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,Label.Log_An_Interaction_Error)); SystemLoggingService.log(e); return null; }catch(Exception e){ ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()); ApexPages.addmessage(myMsg); return null; } } public PageReference cancel(){ PageReference page; if( ApexPages.currentPage().getParameters().get('what_id') != null && ApexPages.currentPage().getParameters().get('what_id') ==task.WhatId ){ page = new PageReference('/'+task.WhatId ); } else{ page = new PageReference('/'+task.whoId); } page.setRedirect(true); return page; } public PageReference saveNew() { PageReference pr; try{ controller.save(); Schema.DescribeSObjectResult describeResult = controller.getRecord().getSObjectType().getDescribe(); //pr = new PageReference('/' + describeResult.getKeyPrefix() + '/e'); pr = new PageReference('/setup/ui/recordtypeselect.jsp?ent=Task' ); pr.setRedirect(true); return pr; }catch(Exception e) { ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage())); return null; }//try }//saveNew }
- nagendra kumar 21
- October 03, 2016
- Like
- 0
- Continue reading or reply
Code coverage of 79% in sandbox but only 45% in production - won't deploy
Hi Everyone, Here i'm facing an issue while deploying my code to Prodection.
I'm a new Bee to SFDC, and i took forms help and others help i wrote a Test class, When i ran it in Dev Org i'm getting 79% code coverage but when i'm trying to deploy it to production it is showing code coverage was 45% as a Error, I have no clue why it is happening. Below i'm giving you my test code, please can any one check what is going on with my code.
@isTest(SeeAllData = False)
public With Sharing class Test_AccountSalesviewTriggerHandler{
static testMethod void testAccountSalesview_Create(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
tempSV.Price_Group__c = 'DD';
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Update(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
List < Account_Salesview__c > lstsalesviewrecordsupdate = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
Integer i = 0;
for (Account_Salesview__c tempSV : lstsalesviewrecords){
tempSV.Name = 'ABCD';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx1234'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecordsupdate.add(tempSV);
i++;
}
update lstsalesviewrecordsupdate;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Delete(){
Account acc = CreateTestClassData.createCustomerAccount();
//Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
delete lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
}
I'm a new Bee to SFDC, and i took forms help and others help i wrote a Test class, When i ran it in Dev Org i'm getting 79% code coverage but when i'm trying to deploy it to production it is showing code coverage was 45% as a Error, I have no clue why it is happening. Below i'm giving you my test code, please can any one check what is going on with my code.
@isTest(SeeAllData = False)
public With Sharing class Test_AccountSalesviewTriggerHandler{
static testMethod void testAccountSalesview_Create(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
tempSV.Price_Group__c = 'DD';
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Update(){
Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
List < Account_Salesview__c > lstsalesviewrecordsupdate = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
Integer i = 0;
for (Account_Salesview__c tempSV : lstsalesviewrecords){
tempSV.Name = 'ABCD';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx1234'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecordsupdate.add(tempSV);
i++;
}
update lstsalesviewrecordsupdate;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
static testMethod void testAccountSalesview_Delete(){
Account acc = CreateTestClassData.createCustomerAccount();
//Account acc = CreateTestClassData.createCustomerAccount();
acc.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Water').getRecordTypeId();
update acc;
Salesview__c SV = CreateTestClassData.CreateSalesview();
Test.StartTest();
List < Account_Salesview__c > lstsalesviewrecords = new List < Account_Salesview__c > ();
for(Integer i=1; i<=10;i++){
Account_Salesview__c tempSV = new Account_Salesview__c();
tempSV.Name = 'ABC';
tempSV.SalesOrg_DistChann_Div_Cust__c = 'idexx123'+i ;
tempSV.Account__c = acc.Id;
tempSV.SalesView__c = SV.Id;
lstsalesviewrecords.add(tempSV);
}
insert lstsalesviewrecords;
delete lstsalesviewrecords;
system.assertequals(acc.name,'Customer Testing Account');
Test.StopTest();
}
}
- nagendra kumar 21
- July 15, 2016
- Like
- 0
- Continue reading or reply
Update the parent field value based on child field value using workflows/Apex
Hello Everyone,
I would like to know what should i use update a field on Account object based on chiled objects fields on account.
I Have created a Checkbox field on Account, and it needs to be True if
account division field is 'xx' and MFD field (checkbox) is 'False' then the fiel on account which i created should be True(check) and they should no longer show up as a 'abc customer'
, If not false(uncheck)..
Please suggest me how can i do this.. If i need to write a code for this please provide a smaple code for it..
Any suggestions is appriceated.
Thanks,
Nag
I would like to know what should i use update a field on Account object based on chiled objects fields on account.
I Have created a Checkbox field on Account, and it needs to be True if
account division field is 'xx' and MFD field (checkbox) is 'False' then the fiel on account which i created should be True(check) and they should no longer show up as a 'abc customer'
, If not false(uncheck)..
Please suggest me how can i do this.. If i need to write a code for this please provide a smaple code for it..
Any suggestions is appriceated.
Thanks,
Nag
- nagendra kumar 21
- July 10, 2016
- Like
- 0
- Continue reading or reply
logs in developer console not visible
Hello,
When i access my visualforce page, i get lops is developer console.
since two days i find it difficult to get logs.
I am opening in same session.
Any idea what i can do ?
When i access my visualforce page, i get lops is developer console.
since two days i find it difficult to get logs.
I am opening in same session.
Any idea what i can do ?
- Simrin
- June 02, 2015
- Like
- 0
- Continue reading or reply
"Save" button Not working for Case Comment in SF1
Hi All,
I could see Save and Cancel buttons in my VFP. But Save button is not highlighted and it isn't working. I used the same code as above. Please help.
Belowe code i used for this.
https://gist.github.com/Karanraj/6bd1ffc13252b0a22ae0
I could see Save and Cancel buttons in my VFP. But Save button is not highlighted and it isn't working. I used the same code as above. Please help.
Belowe code i used for this.
https://gist.github.com/Karanraj/6bd1ffc13252b0a22ae0
- nagendra kumar 21
- May 19, 2015
- Like
- 0
- Continue reading or reply
How do i Translate/Edit Standard Label Name "ERROR" on VFP.
Hello Everyone.
Could any one please suggest me how can i translate/Edit "ERROR" word on the page???
In the provided image you can see that ERROR word in Red color i need to change that to Plosih word.
Could any one please suggest me how can i translate/Edit "ERROR" word on the page???
In the provided image you can see that ERROR word in Red color i need to change that to Plosih word.
- nagendra kumar 21
- February 23, 2015
- Like
- 0
- Continue reading or reply
How to update Multi Currency Exchange rates in salesforce automatically
Hi All,
Multi currency has been enabled in our ORG, Now we want to get the Exchange rates updated regularly on daily basis automatically.
I hope we can accomplish this with API.
Can anyone post some code sample to update the Exchange rates automatically.
Thnaks in advance !!!!!!
Uday
Multi currency has been enabled in our ORG, Now we want to get the Exchange rates updated regularly on daily basis automatically.
I hope we can accomplish this with API.
Can anyone post some code sample to update the Exchange rates automatically.
Thnaks in advance !!!!!!
Uday
- Uday K
- April 23, 2014
- Like
- 0
- Continue reading or reply
custom VisualForce page for task
I would like to create a custom visualforce page for creating a new task. Scenario: user clicks a button on the Activities related list on the parent object. That button launches a VF force page with both standard fields and custom fields for the Task. User populates those fields, then clicks Save.
I've tried all sorts of things hobbled together from research online, but so far, no luck.
(I'm a newbie at VF and apex)
Here's my current VF Page code:
<apex:page standardController="Task" extensions="extension_task">
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageblockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageblockButtons>
<apex:pageBlockSection title="Quick Edits" columns="1">
<apex:inputField value="{!Task.Whatid}"/>
<apex:inputField value="{!Task.Subject}"/>
<apex:inputField value="{!Task.Representative__c}"/>
<apex:inputField value="{!Task.Category__c}"/>
<apex:inputField value="{!Task.Comments__c}" style="width:400px; height:200px"/>
<apex:inputField value="{!Task.Perceived_Call_Value__c}"/>
<apex:inputField value="{!Task.Referred_To__c}"/>
<apex:inputField value="{!Task.Interaction__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here's the apex class extension:
public class extension_task{
Task task = new Task();
public extension_task(ApexPages.StandardController controller) {
this.task = (Task)controller.getRecord();
}
}
**************************
I think a problem is that Task cannot be used as a StandardController. I tried setting the StandardController="ACA_Member__c", but that gives me an error (Error: Unknown property 'ACA_Member__cStandardController.Task'). It seems I should be able to use my custom object with standardController based on this page (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std_associate.htm).
Thanks any advance for any help!
I've tried all sorts of things hobbled together from research online, but so far, no luck.
(I'm a newbie at VF and apex)
Here's my current VF Page code:
<apex:page standardController="Task" extensions="extension_task">
<apex:form >
<apex:pageBlock mode="edit">
<apex:pageblockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageblockButtons>
<apex:pageBlockSection title="Quick Edits" columns="1">
<apex:inputField value="{!Task.Whatid}"/>
<apex:inputField value="{!Task.Subject}"/>
<apex:inputField value="{!Task.Representative__c}"/>
<apex:inputField value="{!Task.Category__c}"/>
<apex:inputField value="{!Task.Comments__c}" style="width:400px; height:200px"/>
<apex:inputField value="{!Task.Perceived_Call_Value__c}"/>
<apex:inputField value="{!Task.Referred_To__c}"/>
<apex:inputField value="{!Task.Interaction__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here's the apex class extension:
public class extension_task{
Task task = new Task();
public extension_task(ApexPages.StandardController controller) {
this.task = (Task)controller.getRecord();
}
}
**************************
I think a problem is that Task cannot be used as a StandardController. I tried setting the StandardController="ACA_Member__c", but that gives me an error (Error: Unknown property 'ACA_Member__cStandardController.Task'). It seems I should be able to use my custom object with standardController based on this page (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std_associate.htm).
Thanks any advance for any help!
- megmooPDX
- February 04, 2014
- Like
- 0
- Continue reading or reply