- Suraj Tripathi 47
- ALL STAR
- 8266 Points
- Member since 2020
- Salesforce Application Architect
- Cloud Analogy
-
ChatterFeed
-
253Best Answers
-
0Likes Received
-
9Likes Given
-
0Questions
-
2017Replies
Getting Error in Min Max Age result showing in another page
Vf code page 1
Apex code Page 1
Vf code page 2
Apex code page 2
The above image was getting error in codes
<apex:page controller="age"> <apex:form > <apex:outputLabel >Enter Min Age</apex:outputLabel> <apex:inputText value="{!p}"/> <apex:commandButton value="Click me" action="{!ageBut}"/> </apex:form> </apex:page>
Apex code Page 1
public class age { public PageReference ageBut() { PageReference pr = new PageReference ('https://93com4-dev-ed--c.visualforce.com/apex/Max_Age?abc='+p); return pr; } public String p { get; set; } }
Vf code page 2
<apex:page controller="Max_Age"> <apex:form > {!z.name} {!z.Age__c} </apex:form> </apex:page>
Apex code page 2
public class Max_Age { public Student__c z { set; get; } public Max_Age(){ string k = ApexPages.currentPage().getParameters().get('abc'); z = [SELECT Name, Student_Id__c, Age__c FROM Student__c WHERE Student_Id__c=:k]; } }
The above image was getting error in codes
- Hari nadh babu Eluru
- December 11, 2021
- Like
- 0
- Continue reading or reply
how to write batch class for this
trigger NumberOfChild on Case (After Insert,After Update,After Delete) {
List<Account> accList=new List<Account>();
Set<Id> setAccIds = new Set<Id>();
if(Trigger.isInsert){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
system.debug('setAccIds ==> '+setAccIds);
if(Trigger.isUpdate){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId){
setAccIds.add(con.AccountId);
setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
}
}
}
}
if(Trigger.isDelete){
if(trigger.isAfter){
for(Case con : Trigger.old) {
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
for(Account acc :[Select id,Summary__c ,(Select id,Description from Cases) from Account where Id in : setAccIds]){
String s ='';
for(Case Con :acc.Cases){
s+=Con.Description +',';
}
acc.Summary__c = s.removeEnd(',');
acclist.add(acc);
}
if(acclist.size()>0){
update accList;
}
}
List<Account> accList=new List<Account>();
Set<Id> setAccIds = new Set<Id>();
if(Trigger.isInsert){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
system.debug('setAccIds ==> '+setAccIds);
if(Trigger.isUpdate){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId){
setAccIds.add(con.AccountId);
setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
}
}
}
}
if(Trigger.isDelete){
if(trigger.isAfter){
for(Case con : Trigger.old) {
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
for(Account acc :[Select id,Summary__c ,(Select id,Description from Cases) from Account where Id in : setAccIds]){
String s ='';
for(Case Con :acc.Cases){
s+=Con.Description +',';
}
acc.Summary__c = s.removeEnd(',');
acclist.add(acc);
}
if(acclist.size()>0){
update accList;
}
}
- Vidya H 4
- December 10, 2021
- Like
- 0
- Continue reading or reply
Error by using Who.Name of tasks in datatable
Hello friends, I have a task datatable component and added the Who.Name as a column. the problem is, that now I do get error messages whenever there is a task where Who.Name is empty. Could you give me a solution for it?
My code:
APEX
JS
My code:
APEX
@AuraEnabled public static List<Task> loadTasks3(Id recordId){ string userId = UserInfo.getUserId(); return[SELECT Subject, Who.Name, ActivityDate, Status FROM Task WHERE ActivityDate = TOMORROW AND OwnerId=:userId AND Status !='Completed']; }
JS
component.set('v.mycolumns', [ {label: 'Thema', fieldName: 'SubjectName', type: 'url', typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}}, {label: 'Name', fieldName: 'whoName', type: 'text', typeAttributes: {label: { fieldName: 'Who.Name' }, target: '_blank'}}, ]); var action = component.get("c.loadTasks"); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var records =response.getReturnValue(); records.forEach(function(record){ record.SubjectName = '/'+record.Id; record.whoName = record.Who.Name }); component.set("v.tasks", records); } }); $A.enqueueAction(action);
- Jonathan Wolff 7
- December 09, 2021
- Like
- 0
- Continue reading or reply
public class Accountupdate { public static void Mymethod(List<Account> acc) { //List<Account> addition=new List<Account>(); set<String> Collectstring=new set<String>(); for(Account collectzipcode:acc)
@istest
public class Accountupdatetest {
@testsetup
static void Fieldvalues()
{
Account accountList=new Account(name='bargavi',BillingPostalCode='56789');
insert accountList ;
Address__c adds=new Address__c(zip_code__c='56789',State_City__c='karntaka',Country__c='india',Street__c='dangal');
insert adds;
}
@istest
static void test1()
{
Account acc2=[select name,BillingPostalCode,BillingCity,BillingCountry,BillingStreet from Account ];
// Address__C adds1=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__C];
test.startTest();
acc2.BillingPostalCode='56789';
try{
update acc2;
}
catch(DmlException exp)
{
system.assert(exp.getMessage().contains('no address zipcode matched to the billing postal code'));
}
test.stopTest();
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public class Accountupdate {
public static void Mymethod(List<Account> acc)
{
//List<Account> addition=new List<Account>();
set<String> Collectstring=new set<String>();
for(Account collectzipcode:acc)
{
Collectstring.add(collectzipcode.BillingPostalCode);
system.debug(' collect All the Zip code ids'+Collectstring);
}
List<Address__c> fetch=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__c where Zip_code__c in:Collectstring];
system.debug(+fetch);
Map<String,Address__c> maping=new Map<String,Address__c>();
for(Address__c edit:fetch)
{
maping.put(edit.Zip_code__c,edit);
system.debug('maping'+maping);
}
for(Account acc1:acc)
{
List<Address__c> lstAdd=new List<Address__c>();
Address__c lastoutput=maping.get(acc1.BillingPostalCode);
lstadd.add(lastoutput);
system.debug('lastoutput'+lastoutput);
if(lstadd.size()<>null)
{
acc1.BillingCity=lastoutput.State_City__c;
acc1.BillingCountry=lastoutput.Country__c;
acc1.BillingStreet=lastoutput.Street__c;
}
else
{
acc1.adderror('no address zipcode matched to the billing postal code');
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
error
//////////////////////
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addressontrigger: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.Accountupdate.Mymethod: line 27, column 1
Trigger.addressontrigger: line 3, column 1: []
public class Accountupdatetest {
@testsetup
static void Fieldvalues()
{
Account accountList=new Account(name='bargavi',BillingPostalCode='56789');
insert accountList ;
Address__c adds=new Address__c(zip_code__c='56789',State_City__c='karntaka',Country__c='india',Street__c='dangal');
insert adds;
}
@istest
static void test1()
{
Account acc2=[select name,BillingPostalCode,BillingCity,BillingCountry,BillingStreet from Account ];
// Address__C adds1=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__C];
test.startTest();
acc2.BillingPostalCode='56789';
try{
update acc2;
}
catch(DmlException exp)
{
system.assert(exp.getMessage().contains('no address zipcode matched to the billing postal code'));
}
test.stopTest();
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public class Accountupdate {
public static void Mymethod(List<Account> acc)
{
//List<Account> addition=new List<Account>();
set<String> Collectstring=new set<String>();
for(Account collectzipcode:acc)
{
Collectstring.add(collectzipcode.BillingPostalCode);
system.debug(' collect All the Zip code ids'+Collectstring);
}
List<Address__c> fetch=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__c where Zip_code__c in:Collectstring];
system.debug(+fetch);
Map<String,Address__c> maping=new Map<String,Address__c>();
for(Address__c edit:fetch)
{
maping.put(edit.Zip_code__c,edit);
system.debug('maping'+maping);
}
for(Account acc1:acc)
{
List<Address__c> lstAdd=new List<Address__c>();
Address__c lastoutput=maping.get(acc1.BillingPostalCode);
lstadd.add(lastoutput);
system.debug('lastoutput'+lastoutput);
if(lstadd.size()<>null)
{
acc1.BillingCity=lastoutput.State_City__c;
acc1.BillingCountry=lastoutput.Country__c;
acc1.BillingStreet=lastoutput.Street__c;
}
else
{
acc1.adderror('no address zipcode matched to the billing postal code');
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
error
//////////////////////
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addressontrigger: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.Accountupdate.Mymethod: line 27, column 1
Trigger.addressontrigger: line 3, column 1: []
- golla Anitha
- December 09, 2021
- Like
- 0
- Continue reading or reply
picklist select option
take a picklist which is having options male,female,others. if user select male and click button then show male students only in vf page
<apex:page controller="ChooseGender"> <apex:form > <apex:selectList id="ChooseGender" value="{!CG}" size="1"> <apex:selectOption itemValue="Male" itemLabel="Male"/> <apex:selectOption itemValue="Female" itemLabel="Female"/> <apex:selectOption itemValue="Others" itemLabel="Others"/> </apex:selectList> <apex:commandButton value="Click me" action="{!PSO}"/> </apex:form> </apex:page>
- Hari nadh babu Eluru 7
- December 09, 2021
- Like
- 0
- Continue reading or reply
Visualforce page records modified recently output not getting blank page getting
VF code
fetch and display students whose records modified recently
in visualforce page
<apex:page controller="Created_Recently"> <apex:form > <apex:pageblock title="Recently Modified student"> <apex:pageBlockTable value="{!stu}" var="c"> <apex:column value="{!c.Name}"/> <apex:column value="{!c.LastModifiedDate}"/> <apex:column value="{!c.Student_Id__c}"/> </apex:pageBlockTable> </apex:pageblock> </apex:form> </apex:page>Apex code
public class Created_Recently { public List<Student__c> stu {get;set;} public Created_Recently(){ DateTime dt = System.Now().addHours(-1); stu = [SELECT Student_Id__c,Name, LastModifiedDate FROM Student__c where LastModifiedDate=:dt ORDER BY LastModifiedDate DESC LIMIT 1]; system.debug('stu'+stu); } }
fetch and display students whose records modified recently
in visualforce page
- Hari nadh babu Eluru 7
- December 08, 2021
- Like
- 0
- Continue reading or reply
System.TypeException: Invalid date/time: 2021-12-07T15:32:19.583
String fake = '2021-12-07T15:32:19.583';
DateTime t = DateTime.valueOfGmt(fake);
system.Debug('Line 17:' + t);
DateTime t = DateTime.valueOfGmt(fake);
system.Debug('Line 17:' + t);
- Priavi
- December 08, 2021
- Like
- 0
- Continue reading or reply
starts with s in visual force
In search box if user enter a letter 's' then bring students name starts with s. In visualforce
- Hari nadh babu Eluru 7
- December 08, 2021
- Like
- 0
- Continue reading or reply
visualforce page modified recently
fetch and display students whose records modified recently in visualforce page
- Hari nadh babu Eluru 7
- December 08, 2021
- Like
- 0
- Continue reading or reply
Reschedule Apex Job using Dev Console
All, I had to delete a scheduled apex job, as this was running under my name.
Now I need to reschudule the apex job to run every hour.
Apex Class is below, can I reschedule this in the Dev Console <Open Execute Anomymouse Window"? and how can I do that?
Now I need to reschudule the apex job to run every hour.
Apex Class is below, can I reschedule this in the Dev Console <Open Execute Anomymouse Window"? and how can I do that?
/** * Schedulable class to retrieve external User Stories on a scheduled basis. * * @author Ümit Can Uçkan * @version 1.0 * @since CCM Integrations 1.0 */ global class ScheduleUserStoryFetch implements Schedulable { copado__Project__c cpRecord; public ScheduleUserStoryFetch(Id pId){ cpRecord = [SELECT Id,Name, Copado_Integration_Setting__r.External_System__c, Copado_Integration_Setting__r.Named_Credential__c,JQL_Extended_Filter__c,Enable_Logs__c, Project_External_Id__c, Workspace_Id__c FROM copado__Project__c WHERE Id=:pId]; } global void execute(SchedulableContext sc) { Database.executeBatch(new ExecuteUserStoryUpsert(this.cpRecord),200); } }
- Dave The Rave
- December 06, 2021
- Like
- 0
- Continue reading or reply
"1. The system should identify the duplicate tickets for the same policy and for the same QRC. 2. The system should merge the duplicate tickets and make a Parent - child ticket relation". here ticket is a case object.
I wrote this code but it is not working, help me for this
Thanks in advance
trigger FindDuplicatecases on Case (after insert) {
system.debug('tset');
String policyVariable;
String typevalue;
Datetime createdDateValue;
List<Case> caseList = New List<Case>();
List<Case> cadup = New List<Case>();
Set<Case> caseSet = New Set<Case>();
for(Case c:trigger.new){
if(c.policy__c != null && c.Type == 'QRC'){
policyVariable = c.policy__c;
typevalue = c.Type;
createdDateValue = c.CreatedDate;
}
}
system.debug('policyVariable>>> '+policyVariable);
system.debug('typevalue>>> '+typevalue);
if(policyVariable != null && typevalue == 'QRC'){
system.debug('in>>>> ');
cadup =[select id, policy__c, Type, ParentId from case where policy__c =: policyVariable AND Type = 'QRC' ];
}
system.debug('cadup>>>> '+cadup);
if(cadup.size() > 0){
for(case cs : trigger.new){
for(case cse : cadup){
system.debug('oldcaseid'+cse);
Case ce = New Case();
ce.Id = cs.Id;
ce.ParentId = cse.Id;
caseSet.add(ce);
}
}
}
system.debug('caseSet>>>> '+caseSet);
for(Case csSet : caseSet){
caseList.add(csSet);
}
Update caseList;
}
Thanks in advance
trigger FindDuplicatecases on Case (after insert) {
system.debug('tset');
String policyVariable;
String typevalue;
Datetime createdDateValue;
List<Case> caseList = New List<Case>();
List<Case> cadup = New List<Case>();
Set<Case> caseSet = New Set<Case>();
for(Case c:trigger.new){
if(c.policy__c != null && c.Type == 'QRC'){
policyVariable = c.policy__c;
typevalue = c.Type;
createdDateValue = c.CreatedDate;
}
}
system.debug('policyVariable>>> '+policyVariable);
system.debug('typevalue>>> '+typevalue);
if(policyVariable != null && typevalue == 'QRC'){
system.debug('in>>>> ');
cadup =[select id, policy__c, Type, ParentId from case where policy__c =: policyVariable AND Type = 'QRC' ];
}
system.debug('cadup>>>> '+cadup);
if(cadup.size() > 0){
for(case cs : trigger.new){
for(case cse : cadup){
system.debug('oldcaseid'+cse);
Case ce = New Case();
ce.Id = cs.Id;
ce.ParentId = cse.Id;
caseSet.add(ce);
}
}
}
system.debug('caseSet>>>> '+caseSet);
for(Case csSet : caseSet){
caseList.add(csSet);
}
Update caseList;
}
- mamatha devaraj
- December 06, 2021
- Like
- 0
- Continue reading or reply
Getting Error in the above code
Date myOldDate = Date.newInstance(2021, 1, 1); Date myTodayDate = date.today(); List<Student__c>studentList = new List <Student__c>(); studentList = [SELECT Student_Id__c, Name, Joining_Date__c FROM Student__c WHERE Joining_Date__c >: myOldDate AND Joining_Date__c :<= myTodayDate];In this above code i had getting this below error
The error is appeared at in "studentList =" on here at in equalto symbol. Please resolve my problem. Thank you !
- Hari nadh babu Eluru 7
- December 04, 2021
- Like
- 0
- Continue reading or reply
Help Me create handler Class for this trigger
trigger OpportunityCloneTrigger on Opportunity (After insert,After update)
{
//For List of Clone Opportunity
List<Opportunity> oppsToUpdate = new List<Opportunity>();
//For Mapping IDs from Opportunity to OpportunityLineItem
Map<Id,List<OpportunityLineItem>> oplitemsMap = new Map<Id,List<OpportunityLineItem>>();
//For Fetching Inserted Or Old list To Clone
List<OpportunityLineItem> oppitemlist = new List<OpportunityLineItem>();
//For Fetching Inserted IDs Or Old IDs To Clone Opportunity
Set<Id> SetID = new Set<Id>();
//For Fetching Newly Inserted Ids for OpportunityLineitem
Set<id> oppIds = new set<Id>();
//For Preventing Recursion
if(OpportunityRecursiveTriggerHandler.isFirstTime)
{
//Resursion Handler Class
OpportunityRecursiveTriggerHandler.isFirstTime = false;
//Fetching Insert and Old Opportunit Ids
for(opportunity opp:Trigger.new)
{
SetID.add(opp.id);
}//End oF 'for'
//Checking the ids
List<Opportunity> ListOpp = [Select id, Name, AccountId, Product_Type__c, CloseDate, StageName, Payment_Frequency__c, Most_Recent_Invoice_Date__c, Billing_Start_Date__c, Interval__c, Parent_Opportunity__c, Clone_Opportunity__c from Opportunity where id IN:SetID];
//For Newly Inserted Opportunity
if(Trigger.IsInsert)
{
//Cloning Opportunity
for(Opportunity opp : ListOpp)
{
//If CheckBox Clone_Opportunity__c is checked
if(opp.Clone_Opportunity__c)
{
//IF StageName is Closed Won
if(opp.StageName == 'Closed Won')
{
//If Product Type is Subscription
if(opp.Product_Type__C == 'Subscription')
{
//if Payment Frequency is not Empty
if(opp.Payment_Frequency__c != Null)
{
//If Next Invoice Date is Today
if(opp.Next_Invoice_Date__c == system.today())
{
//If Parent Opportunity is Empty
if(opp.Parent_Opportunity__c == Null)
{
oppIds.add(opp.Id);
Opportunity newopp = new Opportunity();
newopp.Name = opp.Name + ' Clone';
newopp.AccountId = opp.AccountId;
newopp.Product_Type__c = opp.Product_Type__c;
newopp.CloseDate = opp.CloseDate;
newopp.StageName = opp.StageName;
newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
newopp.Most_Recent_Invoice_Date__c = opp.Most_Recent_Invoice_Date__c;
newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
newopp.Interval__c = opp.Interval__c;
newopp.Parent_Opportunity__c = opp.Id;
oppsToUpdate.add(newopp);
}//End of If Parent Opportunity
}//End of if Next Invoice date
}//End of If Payment Frequency
}//End Of If Product Type
}//End of If StageName
}//End of if Checkbox
}//End of for
}//End of if IsInsert
//if old Opportunity is Updated
else if(Trigger.IsUpdate)
{
//for Updated new Opportunity
for(Opportunity opp : ListOpp)
{
//checking Old ids checkbox
if(Trigger.oldMap.get(opp.Id).Clone_Opportunity__c != opp.Clone_Opportunity__c && opp.Clone_Opportunity__c)
{
//IF StageName is Closed Won
if(opp.StageName == 'Closed Won')
{
//If Product Type is Subscription
if(opp.Product_Type__C == 'Subscription')
{
//if Payment Frequency is not Empty
if(opp.Payment_Frequency__c != Null)
{
//If Next Invoice Date is Today
if(opp.Next_Invoice_Date__c == system.today())
{
//If Parent Opportunity is Empty
if(opp.Parent_Opportunity__c == Null)
{
oppIds.add(opp.Id);
Opportunity newopp = new Opportunity();
newopp.Name = opp.Name + ' Clone';
newopp.AccountId = opp.AccountId;
newopp.Product_Type__c = opp.Product_Type__c;
newopp.CloseDate = opp.CloseDate;
newopp.StageName = opp.StageName;
newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
newopp.Most_Recent_Invoice_Date__c = opp.Most_Recent_Invoice_Date__c;
newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
newopp.Interval__c = opp.Interval__c;
newopp.Parent_Opportunity__c = opp.Id;
oppsToUpdate.add(newopp);
}//End of If Parent Opportunity
}//End of if Next Invoice date
}//End of If Payment Frequency
}//End Of If Product Type
}//End of If StageName
}//End of If Checkbox
}//End of for
}//End of If IsUpdate
//Iterating OpportunityLineitems For Opportunity to update related OpportunityLineItem if Present
for(OpportunityLineitem opl : [SELECT Id, Product2Id, Quantity, UnitPrice,pricebookentryid, OpportunityId FROM OpportunityLineItem Where OpportunityId IN : oppIds])
{
//Mapping Inserted or Old opportunityIds to Clone the related OpportunityLineItem
if(!oplitemsMap.containsKey(opl.OpportunityId))
{
oplitemsMap.put(opl.OpportunityId, new List<OpportunityLineitem>{opl});
}//End of IF Old IDs
else
{
oplitemsMap.get(opl.OpportunityId).add(opl);
}//end of else
}//End Of for iteration oppoopportunityLineItem
//If Opportunity is Not Empty
if(!oppsToUpdate.IsEmpty())
{
//Cloning Inserted Or Updated Opportunity
insert oppsToUpdate;
//Iterating Cloned Inserted Or Updated Opportunity for OpportunityLineItem
for(Opportunity op : oppsToUpdate)
{
//system.debug(' Id --> ' + op.Id);
//system.debug(' Parent Id --> ' + op.Parent_Opportunity__c);
//for inserted Or updated Opportunity if Parent_opportunity__c is equals Opportunity
if(oplitemsMap.containsKey(op.Parent_Opportunity__c))
{
//Iterating OpportunityLineitem From Parent Opportunity For Cloning Its OpportunityLineItem
for(OpportunityLineitem ol : oplitemsMap.get(op.Parent_Opportunity__c))
{
OpportunityLineItem oli = new OpportunityLineitem();
oli.OpportunityId = op.Id;
oli.Product2Id = ol.Product2Id;
oli.Quantity = ol.Quantity;
oli.UnitPrice = ol.UnitPrice;
oli.pricebookentryid=ol.pricebookentryid;
oppitemlist.add(oli);
}//End of for
}//End of If
}//End Of For
//Cloning OpportunityLineItem From Parent Opportunity OpportunityLineItem
if(!oppitemlist.isEmpty())
{
insert oppitemlist;
}//End Of if
}//End of If for Cloning
}//End Of Preventing Recursion
}//End Of trigger
{
//For List of Clone Opportunity
List<Opportunity> oppsToUpdate = new List<Opportunity>();
//For Mapping IDs from Opportunity to OpportunityLineItem
Map<Id,List<OpportunityLineItem>> oplitemsMap = new Map<Id,List<OpportunityLineItem>>();
//For Fetching Inserted Or Old list To Clone
List<OpportunityLineItem> oppitemlist = new List<OpportunityLineItem>();
//For Fetching Inserted IDs Or Old IDs To Clone Opportunity
Set<Id> SetID = new Set<Id>();
//For Fetching Newly Inserted Ids for OpportunityLineitem
Set<id> oppIds = new set<Id>();
//For Preventing Recursion
if(OpportunityRecursiveTriggerHandler.isFirstTime)
{
//Resursion Handler Class
OpportunityRecursiveTriggerHandler.isFirstTime = false;
//Fetching Insert and Old Opportunit Ids
for(opportunity opp:Trigger.new)
{
SetID.add(opp.id);
}//End oF 'for'
//Checking the ids
List<Opportunity> ListOpp = [Select id, Name, AccountId, Product_Type__c, CloseDate, StageName, Payment_Frequency__c, Most_Recent_Invoice_Date__c, Billing_Start_Date__c, Interval__c, Parent_Opportunity__c, Clone_Opportunity__c from Opportunity where id IN:SetID];
//For Newly Inserted Opportunity
if(Trigger.IsInsert)
{
//Cloning Opportunity
for(Opportunity opp : ListOpp)
{
//If CheckBox Clone_Opportunity__c is checked
if(opp.Clone_Opportunity__c)
{
//IF StageName is Closed Won
if(opp.StageName == 'Closed Won')
{
//If Product Type is Subscription
if(opp.Product_Type__C == 'Subscription')
{
//if Payment Frequency is not Empty
if(opp.Payment_Frequency__c != Null)
{
//If Next Invoice Date is Today
if(opp.Next_Invoice_Date__c == system.today())
{
//If Parent Opportunity is Empty
if(opp.Parent_Opportunity__c == Null)
{
oppIds.add(opp.Id);
Opportunity newopp = new Opportunity();
newopp.Name = opp.Name + ' Clone';
newopp.AccountId = opp.AccountId;
newopp.Product_Type__c = opp.Product_Type__c;
newopp.CloseDate = opp.CloseDate;
newopp.StageName = opp.StageName;
newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
newopp.Most_Recent_Invoice_Date__c = opp.Most_Recent_Invoice_Date__c;
newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
newopp.Interval__c = opp.Interval__c;
newopp.Parent_Opportunity__c = opp.Id;
oppsToUpdate.add(newopp);
}//End of If Parent Opportunity
}//End of if Next Invoice date
}//End of If Payment Frequency
}//End Of If Product Type
}//End of If StageName
}//End of if Checkbox
}//End of for
}//End of if IsInsert
//if old Opportunity is Updated
else if(Trigger.IsUpdate)
{
//for Updated new Opportunity
for(Opportunity opp : ListOpp)
{
//checking Old ids checkbox
if(Trigger.oldMap.get(opp.Id).Clone_Opportunity__c != opp.Clone_Opportunity__c && opp.Clone_Opportunity__c)
{
//IF StageName is Closed Won
if(opp.StageName == 'Closed Won')
{
//If Product Type is Subscription
if(opp.Product_Type__C == 'Subscription')
{
//if Payment Frequency is not Empty
if(opp.Payment_Frequency__c != Null)
{
//If Next Invoice Date is Today
if(opp.Next_Invoice_Date__c == system.today())
{
//If Parent Opportunity is Empty
if(opp.Parent_Opportunity__c == Null)
{
oppIds.add(opp.Id);
Opportunity newopp = new Opportunity();
newopp.Name = opp.Name + ' Clone';
newopp.AccountId = opp.AccountId;
newopp.Product_Type__c = opp.Product_Type__c;
newopp.CloseDate = opp.CloseDate;
newopp.StageName = opp.StageName;
newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
newopp.Most_Recent_Invoice_Date__c = opp.Most_Recent_Invoice_Date__c;
newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
newopp.Interval__c = opp.Interval__c;
newopp.Parent_Opportunity__c = opp.Id;
oppsToUpdate.add(newopp);
}//End of If Parent Opportunity
}//End of if Next Invoice date
}//End of If Payment Frequency
}//End Of If Product Type
}//End of If StageName
}//End of If Checkbox
}//End of for
}//End of If IsUpdate
//Iterating OpportunityLineitems For Opportunity to update related OpportunityLineItem if Present
for(OpportunityLineitem opl : [SELECT Id, Product2Id, Quantity, UnitPrice,pricebookentryid, OpportunityId FROM OpportunityLineItem Where OpportunityId IN : oppIds])
{
//Mapping Inserted or Old opportunityIds to Clone the related OpportunityLineItem
if(!oplitemsMap.containsKey(opl.OpportunityId))
{
oplitemsMap.put(opl.OpportunityId, new List<OpportunityLineitem>{opl});
}//End of IF Old IDs
else
{
oplitemsMap.get(opl.OpportunityId).add(opl);
}//end of else
}//End Of for iteration oppoopportunityLineItem
//If Opportunity is Not Empty
if(!oppsToUpdate.IsEmpty())
{
//Cloning Inserted Or Updated Opportunity
insert oppsToUpdate;
//Iterating Cloned Inserted Or Updated Opportunity for OpportunityLineItem
for(Opportunity op : oppsToUpdate)
{
//system.debug(' Id --> ' + op.Id);
//system.debug(' Parent Id --> ' + op.Parent_Opportunity__c);
//for inserted Or updated Opportunity if Parent_opportunity__c is equals Opportunity
if(oplitemsMap.containsKey(op.Parent_Opportunity__c))
{
//Iterating OpportunityLineitem From Parent Opportunity For Cloning Its OpportunityLineItem
for(OpportunityLineitem ol : oplitemsMap.get(op.Parent_Opportunity__c))
{
OpportunityLineItem oli = new OpportunityLineitem();
oli.OpportunityId = op.Id;
oli.Product2Id = ol.Product2Id;
oli.Quantity = ol.Quantity;
oli.UnitPrice = ol.UnitPrice;
oli.pricebookentryid=ol.pricebookentryid;
oppitemlist.add(oli);
}//End of for
}//End of If
}//End Of For
//Cloning OpportunityLineItem From Parent Opportunity OpportunityLineItem
if(!oppitemlist.isEmpty())
{
insert oppitemlist;
}//End Of if
}//End of If for Cloning
}//End Of Preventing Recursion
}//End Of trigger
- SFDCIronMan
- December 02, 2021
- Like
- 0
- Continue reading or reply
SOQL Dates between
Write an SOQL Query to fetch students who joined in between january 1st 2021 to till today date. I want only SOQL Query to execute without list or set
- Hari nadh babu Eluru
- December 02, 2021
- Like
- 0
- Continue reading or reply
Error scheduling chron job
Via anonymous apex, I'm trying to schedule a job to run at 11pm on the first of every month using the following:
RenewalBatch job = new RenewalBatch(); // Scheduling string parameters // Seconds Minutes Hours Day_of_month Month Day_of_week optional_year String 1stOfMonthAt11pm = '0 0 23 1 * *'; System.schedule('Renewal Batch Job Monthly at 11pm', 1stOfMonthAt11pm, job);
However, I receive the following error:
Execute Anonymous Error
Line: 5, Column: 8
Unexpected token '1'.
and am unable to resolve this. What could be the issue here?
- DML2020
- December 01, 2021
- Like
- 0
- Continue reading or reply
- Daniel Lafontant
- November 30, 2021
- Like
- 0
- Continue reading or reply
diagonal length of rectangle
write the apex class to define diagonal length of rectangle formula to substitute values formula is
- Hari nadh babu Eluru 7
- November 30, 2021
- Like
- 0
- Continue reading or reply
string must be 6 digits and string must be numeric only
Take a string type of variable
string pincode = '500038';
- Pincode must be exactly 6 digits, if the no of digits not equal to 6 then print "Pincode must be 6 digits"
- Pincode must be numeric only, if user enters alphabets then show error message "Pincode must be numeric only"
- Hari nadh babu Eluru
- November 25, 2021
- Like
- 0
- Continue reading or reply
written test class but not getting code coverage and getting error plz help
writing test class for the below code
Handler class
public class WorkOredrTriggerHelper {
public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrders){
if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
if(mapLine.get(wo.Id) != null) {
boolean flag = false;
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
if(wd.Status__c=='open'){
flag = true;
}
}
if(flag == true) {
System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
}
}
else {
System.debug('No items');
wo.addError('No line items');
}
}
}
}
public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
String closureStatus = '';
Integer countLineItems;
Map<Id,String> closureStatusMap = new Map<Id,String>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrdersNew){
closureStatus = '';
countLineItems = 0;
if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
countLineItems = countLineItems + 1;
SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
newLineItem.Id = wd.Id;
newLineItem.Work_order_status__c = 'Work Order is Closed';
lineItemsToUpdate.add(newLineItem);
closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
}
closureStatusMap.put(wo.Id, closureStatus);
}
}
List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
for(SVMXC__Service_Order__c workOrder : workOrders){
workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
workOrdersToUpdate.add(workOrder);
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update lineItemsToUpdate;
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update workOrdersToUpdate;
}
}
}
Trigger
trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
if(trigger.isBefore && trigger.isupdate){
system.debug('Inside new trigger'+ Trigger.new);
WorkOredrTriggerHelper.helperMethod(trigger.new);
}
if(trigger.isAfter && trigger.isupdate){
system.debug('Inside new trigger after update'+ Trigger.new);
WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
}
}
Getting error like...
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: [] AND
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: []
TEST CLASS
@isTest
public class WorkOredrTriggerHelperTest {
@isTest static void helperMethod(){
SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
serviceOrderObj.closure_status__c= 'test';
serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
insert serviceOrderObj;
SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
lineObj.Status__c = 'open';
lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ;
insert lineObj;
Test.startTest();
update serviceOrderObj;
System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
Test.stopTest();
}
@isTest static void helperMethodSecond(){
SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
serviceOrderObj.closure_status__c= 'test';
serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
insert serviceOrderObj;
SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
lineObj.Status__c = 'open';
lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ;
insert lineObj;
Test.startTest();
serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
update serviceOrderObj;
System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
Test.stopTest();
}
}
Handler class
public class WorkOredrTriggerHelper {
public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrders){
if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
if(mapLine.get(wo.Id) != null) {
boolean flag = false;
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
if(wd.Status__c=='open'){
flag = true;
}
}
if(flag == true) {
System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
}
}
else {
System.debug('No items');
wo.addError('No line items');
}
}
}
}
public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
String closureStatus = '';
Integer countLineItems;
Map<Id,String> closureStatusMap = new Map<Id,String>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrdersNew){
closureStatus = '';
countLineItems = 0;
if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
countLineItems = countLineItems + 1;
SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
newLineItem.Id = wd.Id;
newLineItem.Work_order_status__c = 'Work Order is Closed';
lineItemsToUpdate.add(newLineItem);
closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
}
closureStatusMap.put(wo.Id, closureStatus);
}
}
List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
for(SVMXC__Service_Order__c workOrder : workOrders){
workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
workOrdersToUpdate.add(workOrder);
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update lineItemsToUpdate;
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update workOrdersToUpdate;
}
}
}
Trigger
trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
if(trigger.isBefore && trigger.isupdate){
system.debug('Inside new trigger'+ Trigger.new);
WorkOredrTriggerHelper.helperMethod(trigger.new);
}
if(trigger.isAfter && trigger.isupdate){
system.debug('Inside new trigger after update'+ Trigger.new);
WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
}
}
Getting error like...
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: [] AND
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: []
TEST CLASS
@isTest
public class WorkOredrTriggerHelperTest {
@isTest static void helperMethod(){
SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
serviceOrderObj.closure_status__c= 'test';
serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
insert serviceOrderObj;
SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
lineObj.Status__c = 'open';
lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ;
insert lineObj;
Test.startTest();
update serviceOrderObj;
System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
Test.stopTest();
}
@isTest static void helperMethodSecond(){
SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
serviceOrderObj.closure_status__c= 'test';
serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
insert serviceOrderObj;
SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
lineObj.Status__c = 'open';
lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ;
insert lineObj;
Test.startTest();
serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
update serviceOrderObj;
System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
Test.stopTest();
}
}
- Roopa S 1
- December 11, 2021
- Like
- 0
- Continue reading or reply
Getting Error in Min Max Age result showing in another page
Vf code page 1
Apex code Page 1
Vf code page 2
Apex code page 2
The above image was getting error in codes
<apex:page controller="age"> <apex:form > <apex:outputLabel >Enter Min Age</apex:outputLabel> <apex:inputText value="{!p}"/> <apex:commandButton value="Click me" action="{!ageBut}"/> </apex:form> </apex:page>
Apex code Page 1
public class age { public PageReference ageBut() { PageReference pr = new PageReference ('https://93com4-dev-ed--c.visualforce.com/apex/Max_Age?abc='+p); return pr; } public String p { get; set; } }
Vf code page 2
<apex:page controller="Max_Age"> <apex:form > {!z.name} {!z.Age__c} </apex:form> </apex:page>
Apex code page 2
public class Max_Age { public Student__c z { set; get; } public Max_Age(){ string k = ApexPages.currentPage().getParameters().get('abc'); z = [SELECT Name, Student_Id__c, Age__c FROM Student__c WHERE Student_Id__c=:k]; } }
The above image was getting error in codes
- Hari nadh babu Eluru
- December 11, 2021
- Like
- 0
- Continue reading or reply
How to use string expression in IF condition Apex
Hi there,
I am stuck in my program, Actually I want to use String expression into the IF statement condition.
eg:
Is there any solution for this, Please let me know your thoughts on this.
Thanks,
Rahul
I am stuck in my program, Actually I want to use String expression into the IF statement condition.
eg:
String expression1 = 'Annual_Rev__c != 0 && Status__c == "Closed"'; if(expression1 ){ System.debug('It Worked...!'); }
Is there any solution for this, Please let me know your thoughts on this.
Thanks,
Rahul
- Anime Lover
- December 10, 2021
- Like
- 0
- Continue reading or reply
Min Age and Max Age result can be show in another page
if user enter min age, max age . fetch all the students in btwn that min and max age
in above example try to load students in ascending order based on age
result can be shown in another page when clicked search button- Hari nadh babu Eluru
- December 10, 2021
- Like
- 0
- Continue reading or reply
fetch user details
How to fetch user details with user "(username,email)and opportunity(id,stagename) object fields based on username by using JSON
- nikki gouda
- December 10, 2021
- Like
- 0
- Continue reading or reply
plz help me to write test class for this
trigger deleteUserTrigger1 on Task (before delete) {
Id profileid=Userinfo.getProfileId();
profile profilname=[select Name from Profile where id=:profileid];
for(Task accountDuplicate:Trigger.old){
if(profilname.Name!='System Administrator'){
accountDuplicate.addError('No Access for Deletion');
}
}
}*/
Id profileid=Userinfo.getProfileId();
profile profilname=[select Name from Profile where id=:profileid];
for(Task accountDuplicate:Trigger.old){
if(profilname.Name!='System Administrator'){
accountDuplicate.addError('No Access for Deletion');
}
}
}*/
- Roopa S 1
- December 10, 2021
- Like
- 0
- Continue reading or reply
I am trying to create a trigger on contact to prevent duplicate records based on Contact Email & Contact Phone.
I tried this code but not working. Can any one help me on this?
trigger Contactduplicaterecord on Contact (before insert, before update)
{
set<string> EmaPho=new set<string>();
for(Contact Con:trigger.new)
{
EmaPho.add(Con.Phone);
EmaPho.add(Con.Email);
}
if(EmaPho.size()>0 )
{
List<Contact> lstContact=[Select Phone,Email from Contact where Phone in:EmaPho or Email in:EmaPho];
Map<string, Contact> MapEmaPhowisecontact=new Map<string, Contact>();
for(Contact Con:lstContact)
{
MapEmaPhowisecontact.put(Con.Phone, Con);
MapEmaPhowisecontact.put(Con.Email, Con);
}
for(Contact Con:trigger.new)
{
if(MapEmaPhowisecontact.containsKey(Con.Phone))
{
Con.Phone.addError('Phone Number already Exist');
}
if(MapEmaPhowisecontact.containsKey(Con.Email))
{
Con.Email.addError('Email already Exist');
}
}
}
}
trigger Contactduplicaterecord on Contact (before insert, before update)
{
set<string> EmaPho=new set<string>();
for(Contact Con:trigger.new)
{
EmaPho.add(Con.Phone);
EmaPho.add(Con.Email);
}
if(EmaPho.size()>0 )
{
List<Contact> lstContact=[Select Phone,Email from Contact where Phone in:EmaPho or Email in:EmaPho];
Map<string, Contact> MapEmaPhowisecontact=new Map<string, Contact>();
for(Contact Con:lstContact)
{
MapEmaPhowisecontact.put(Con.Phone, Con);
MapEmaPhowisecontact.put(Con.Email, Con);
}
for(Contact Con:trigger.new)
{
if(MapEmaPhowisecontact.containsKey(Con.Phone))
{
Con.Phone.addError('Phone Number already Exist');
}
if(MapEmaPhowisecontact.containsKey(Con.Email))
{
Con.Email.addError('Email already Exist');
}
}
}
}
- Salluri Leelavathi
- December 10, 2021
- Like
- 0
- Continue reading or reply
how to write batch class for this
trigger NumberOfChild on Case (After Insert,After Update,After Delete) {
List<Account> accList=new List<Account>();
Set<Id> setAccIds = new Set<Id>();
if(Trigger.isInsert){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
system.debug('setAccIds ==> '+setAccIds);
if(Trigger.isUpdate){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId){
setAccIds.add(con.AccountId);
setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
}
}
}
}
if(Trigger.isDelete){
if(trigger.isAfter){
for(Case con : Trigger.old) {
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
for(Account acc :[Select id,Summary__c ,(Select id,Description from Cases) from Account where Id in : setAccIds]){
String s ='';
for(Case Con :acc.Cases){
s+=Con.Description +',';
}
acc.Summary__c = s.removeEnd(',');
acclist.add(acc);
}
if(acclist.size()>0){
update accList;
}
}
List<Account> accList=new List<Account>();
Set<Id> setAccIds = new Set<Id>();
if(Trigger.isInsert){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
system.debug('setAccIds ==> '+setAccIds);
if(Trigger.isUpdate){
if(trigger.isAfter){
for(Case con : Trigger.new){
if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId){
setAccIds.add(con.AccountId);
setAccIds.add(Trigger.oldMap.get(con.Id).AccountId);
}
}
}
}
if(Trigger.isDelete){
if(trigger.isAfter){
for(Case con : Trigger.old) {
if(con.AccountId != null){
setAccIds.add(con.AccountId);
}
}
}
}
for(Account acc :[Select id,Summary__c ,(Select id,Description from Cases) from Account where Id in : setAccIds]){
String s ='';
for(Case Con :acc.Cases){
s+=Con.Description +',';
}
acc.Summary__c = s.removeEnd(',');
acclist.add(acc);
}
if(acclist.size()>0){
update accList;
}
}
- Vidya H 4
- December 10, 2021
- Like
- 0
- Continue reading or reply
want to create utility class which access the data of Custom object with case and return the fields?
My requirement: write a utility class, class name: XYZ, which fetch the data of ABC__c for case by using caseid, case is lookup with C_ABC__c, return some fields of ABC__c, return the list
program:
public class XYZ{
public static Map<String,Integer> CC(List<case> CaseIDs){
Map<String,Integer> yup = new Map<String,Integer>();
Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);
List<Case> cList = [Select Id (Select ABC__c From C_ABC__r) From Case Where Id IN: caseIds];
for(Case res :cList){
List<ABC__c> list = res.Customer_Vehicle__r; //Child Relationship Name
for(ABC__c a : vehlist){
List<ABC__c> pqr = [SELECT NAME__c,LName__c FIELDS(STANDARD) FROM ABC__c];
}
}
}
}
My questions:
i fetch case id correctly ?, use for loop or not, i want to return fields i do it correctly? please review and help me
program:
public class XYZ{
public static Map<String,Integer> CC(List<case> CaseIDs){
Map<String,Integer> yup = new Map<String,Integer>();
Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);
List<Case> cList = [Select Id (Select ABC__c From C_ABC__r) From Case Where Id IN: caseIds];
for(Case res :cList){
List<ABC__c> list = res.Customer_Vehicle__r; //Child Relationship Name
for(ABC__c a : vehlist){
List<ABC__c> pqr = [SELECT NAME__c,LName__c FIELDS(STANDARD) FROM ABC__c];
}
}
}
}
My questions:
i fetch case id correctly ?, use for loop or not, i want to return fields i do it correctly? please review and help me
- Pravi
- December 10, 2021
- Like
- 0
- Continue reading or reply
Error by using Who.Name of tasks in datatable
Hello friends, I have a task datatable component and added the Who.Name as a column. the problem is, that now I do get error messages whenever there is a task where Who.Name is empty. Could you give me a solution for it?
My code:
APEX
JS
My code:
APEX
@AuraEnabled public static List<Task> loadTasks3(Id recordId){ string userId = UserInfo.getUserId(); return[SELECT Subject, Who.Name, ActivityDate, Status FROM Task WHERE ActivityDate = TOMORROW AND OwnerId=:userId AND Status !='Completed']; }
JS
component.set('v.mycolumns', [ {label: 'Thema', fieldName: 'SubjectName', type: 'url', typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}}, {label: 'Name', fieldName: 'whoName', type: 'text', typeAttributes: {label: { fieldName: 'Who.Name' }, target: '_blank'}}, ]); var action = component.get("c.loadTasks"); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var records =response.getReturnValue(); records.forEach(function(record){ record.SubjectName = '/'+record.Id; record.whoName = record.Who.Name }); component.set("v.tasks", records); } }); $A.enqueueAction(action);
- Jonathan Wolff 7
- December 09, 2021
- Like
- 0
- Continue reading or reply
How to write a trigger on Account , when an account insert , automatically account billing address should populate into the account shipping address.
Hi, can any one help me with trigger on Account , when an account insert , automatically account billing address should populate into the account shipping address.
I wrote this but not working
trigger AddressUpdate on Account (before insert)
{
for(Account Acc:trigger.new)
{
Acc.BillingStreet=Acc.ShippingStreet;
Acc.BillingCity=Acc.ShippingCity;
Acc.BillingCountry=Acc.ShippingCountry;
Acc.BillingState=Acc.ShippingState;
Acc.BillingPostalCode=Acc.ShippingPostalCode;
}
}
I wrote this but not working
trigger AddressUpdate on Account (before insert)
{
for(Account Acc:trigger.new)
{
Acc.BillingStreet=Acc.ShippingStreet;
Acc.BillingCity=Acc.ShippingCity;
Acc.BillingCountry=Acc.ShippingCountry;
Acc.BillingState=Acc.ShippingState;
Acc.BillingPostalCode=Acc.ShippingPostalCode;
}
}
- Salluri Leelavathi
- December 09, 2021
- Like
- 0
- Continue reading or reply
public class Accountupdate { public static void Mymethod(List<Account> acc) { //List<Account> addition=new List<Account>(); set<String> Collectstring=new set<String>(); for(Account collectzipcode:acc)
@istest
public class Accountupdatetest {
@testsetup
static void Fieldvalues()
{
Account accountList=new Account(name='bargavi',BillingPostalCode='56789');
insert accountList ;
Address__c adds=new Address__c(zip_code__c='56789',State_City__c='karntaka',Country__c='india',Street__c='dangal');
insert adds;
}
@istest
static void test1()
{
Account acc2=[select name,BillingPostalCode,BillingCity,BillingCountry,BillingStreet from Account ];
// Address__C adds1=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__C];
test.startTest();
acc2.BillingPostalCode='56789';
try{
update acc2;
}
catch(DmlException exp)
{
system.assert(exp.getMessage().contains('no address zipcode matched to the billing postal code'));
}
test.stopTest();
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public class Accountupdate {
public static void Mymethod(List<Account> acc)
{
//List<Account> addition=new List<Account>();
set<String> Collectstring=new set<String>();
for(Account collectzipcode:acc)
{
Collectstring.add(collectzipcode.BillingPostalCode);
system.debug(' collect All the Zip code ids'+Collectstring);
}
List<Address__c> fetch=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__c where Zip_code__c in:Collectstring];
system.debug(+fetch);
Map<String,Address__c> maping=new Map<String,Address__c>();
for(Address__c edit:fetch)
{
maping.put(edit.Zip_code__c,edit);
system.debug('maping'+maping);
}
for(Account acc1:acc)
{
List<Address__c> lstAdd=new List<Address__c>();
Address__c lastoutput=maping.get(acc1.BillingPostalCode);
lstadd.add(lastoutput);
system.debug('lastoutput'+lastoutput);
if(lstadd.size()<>null)
{
acc1.BillingCity=lastoutput.State_City__c;
acc1.BillingCountry=lastoutput.Country__c;
acc1.BillingStreet=lastoutput.Street__c;
}
else
{
acc1.adderror('no address zipcode matched to the billing postal code');
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
error
//////////////////////
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addressontrigger: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.Accountupdate.Mymethod: line 27, column 1
Trigger.addressontrigger: line 3, column 1: []
public class Accountupdatetest {
@testsetup
static void Fieldvalues()
{
Account accountList=new Account(name='bargavi',BillingPostalCode='56789');
insert accountList ;
Address__c adds=new Address__c(zip_code__c='56789',State_City__c='karntaka',Country__c='india',Street__c='dangal');
insert adds;
}
@istest
static void test1()
{
Account acc2=[select name,BillingPostalCode,BillingCity,BillingCountry,BillingStreet from Account ];
// Address__C adds1=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__C];
test.startTest();
acc2.BillingPostalCode='56789';
try{
update acc2;
}
catch(DmlException exp)
{
system.assert(exp.getMessage().contains('no address zipcode matched to the billing postal code'));
}
test.stopTest();
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public class Accountupdate {
public static void Mymethod(List<Account> acc)
{
//List<Account> addition=new List<Account>();
set<String> Collectstring=new set<String>();
for(Account collectzipcode:acc)
{
Collectstring.add(collectzipcode.BillingPostalCode);
system.debug(' collect All the Zip code ids'+Collectstring);
}
List<Address__c> fetch=[select Street__c,Zip_code__c,State_City__c,Country__c from Address__c where Zip_code__c in:Collectstring];
system.debug(+fetch);
Map<String,Address__c> maping=new Map<String,Address__c>();
for(Address__c edit:fetch)
{
maping.put(edit.Zip_code__c,edit);
system.debug('maping'+maping);
}
for(Account acc1:acc)
{
List<Address__c> lstAdd=new List<Address__c>();
Address__c lastoutput=maping.get(acc1.BillingPostalCode);
lstadd.add(lastoutput);
system.debug('lastoutput'+lastoutput);
if(lstadd.size()<>null)
{
acc1.BillingCity=lastoutput.State_City__c;
acc1.BillingCountry=lastoutput.Country__c;
acc1.BillingStreet=lastoutput.Street__c;
}
else
{
acc1.adderror('no address zipcode matched to the billing postal code');
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
error
//////////////////////
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addressontrigger: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.Accountupdate.Mymethod: line 27, column 1
Trigger.addressontrigger: line 3, column 1: []
- golla Anitha
- December 09, 2021
- Like
- 0
- Continue reading or reply
how to write test class for this codee
public class WorkOredrTriggerHelper {
public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrders){
if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
if(mapLine.get(wo.Id) != null) {
boolean flag = false;
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
if(wd.Status__c=='open'){
flag = true;
}
}
if(flag == true) {
System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
}
}
else {
System.debug('No items');
wo.addError('No line items');
}
}
}
}
public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
String closureStatus = '';
Integer countLineItems;
Map<Id,String> closureStatusMap = new Map<Id,String>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrdersNew){
closureStatus = '';
countLineItems = 0;
if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
countLineItems = countLineItems + 1;
SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
newLineItem.Id = wd.Id;
newLineItem.Work_order_status__c = 'Work Order is Closed';
lineItemsToUpdate.add(newLineItem);
closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
}
closureStatusMap.put(wo.Id, closureStatus);
}
}
List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
for(SVMXC__Service_Order__c workOrder : workOrders){
workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
workOrdersToUpdate.add(workOrder);
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update lineItemsToUpdate;
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update workOrdersToUpdate;
}
}
}
trigger
trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
if(trigger.isBefore && trigger.isupdate){
system.debug('Inside new trigger'+ Trigger.new);
WorkOredrTriggerHelper.helperMethod(trigger.new);
}
if(trigger.isAfter && trigger.isupdate){
system.debug('Inside new trigger after update'+ Trigger.new);
WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
}
}
public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrders){
if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
if(mapLine.get(wo.Id) != null) {
boolean flag = false;
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
if(wd.Status__c=='open'){
flag = true;
}
}
if(flag == true) {
System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
}
}
else {
System.debug('No items');
wo.addError('No line items');
}
}
}
}
public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
String closureStatus = '';
Integer countLineItems;
Map<Id,String> closureStatusMap = new Map<Id,String>();
lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c from SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
for(SVMXC__Service_Order_Line__c asd : lineItems) {
if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
continue;
}
mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
}
for(SVMXC__Service_Order__c wo : WorkOrdersNew){
closureStatus = '';
countLineItems = 0;
if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
countLineItems = countLineItems + 1;
SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
newLineItem.Id = wd.Id;
newLineItem.Work_order_status__c = 'Work Order is Closed';
lineItemsToUpdate.add(newLineItem);
closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
}
closureStatusMap.put(wo.Id, closureStatus);
}
}
List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
for(SVMXC__Service_Order__c workOrder : workOrders){
workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
workOrdersToUpdate.add(workOrder);
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update lineItemsToUpdate;
}
if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
update workOrdersToUpdate;
}
}
}
trigger
trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
if(trigger.isBefore && trigger.isupdate){
system.debug('Inside new trigger'+ Trigger.new);
WorkOredrTriggerHelper.helperMethod(trigger.new);
}
if(trigger.isAfter && trigger.isupdate){
system.debug('Inside new trigger after update'+ Trigger.new);
WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
}
}
- Roopa S 1
- December 09, 2021
- Like
- 0
- Continue reading or reply
I need test class for it someone please help me out..
*Controller Class
public class ConOpptyRelatedToAccount
{
public ConOpptyRelatedToAccount(ApexPages.StandardController controller)
{
}
public List<Contact> getContacts()
{
List<Contact> con = [SELECT Id, FirstName, LastName, Title, Email FROM Contact WHERE AccountId=:apexpages.currentpage().getparameters().get('id')];
return con;
}
public List<Opportunity> getOpportunities()
{
List<Opportunity> Oppty = [SELECT Id, CloseDate, Amount, StageName, Name FROM Opportunity WHERE AccountId=:apexpages.currentpage().getparameters().get('id')];
return Oppty;
}
public pagereference downLoad(){
pagereference p = new pagereference('/apex/PDFofRelatedList');
return p;
}
}
******************************************************************************
*Vf page
<apex:page standardController="Account" extensions="ConOpptyRelatedToAccount" >
<apex:form >
<apex:pageBlock title="Contacts List" >
<apex:pageBlockTable value="{!contacts }" var="Con">
<apex:column value="{!Con.FirstName }"/>
<apex:column value="{!Con.LastName }"/>
<apex:column value="{!Con.Title }"/>
<apex:column value="{!Con.Email }"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Opportunity List" >
<apex:pageBlockTable value="{!opportunities }" var="op">
<apex:column value="{!op.Name }"/>
<apex:column value="{!op.CloseDate }"/>
<apex:column value="{!op.StageName }"/>
<apex:column value="{!op.Amount }"/>
</apex:pageBlockTable>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Download Pdf" action="{!downLoad}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
public class ConOpptyRelatedToAccount
{
public ConOpptyRelatedToAccount(ApexPages.StandardController controller)
{
}
public List<Contact> getContacts()
{
List<Contact> con = [SELECT Id, FirstName, LastName, Title, Email FROM Contact WHERE AccountId=:apexpages.currentpage().getparameters().get('id')];
return con;
}
public List<Opportunity> getOpportunities()
{
List<Opportunity> Oppty = [SELECT Id, CloseDate, Amount, StageName, Name FROM Opportunity WHERE AccountId=:apexpages.currentpage().getparameters().get('id')];
return Oppty;
}
public pagereference downLoad(){
pagereference p = new pagereference('/apex/PDFofRelatedList');
return p;
}
}
******************************************************************************
*Vf page
<apex:page standardController="Account" extensions="ConOpptyRelatedToAccount" >
<apex:form >
<apex:pageBlock title="Contacts List" >
<apex:pageBlockTable value="{!contacts }" var="Con">
<apex:column value="{!Con.FirstName }"/>
<apex:column value="{!Con.LastName }"/>
<apex:column value="{!Con.Title }"/>
<apex:column value="{!Con.Email }"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Opportunity List" >
<apex:pageBlockTable value="{!opportunities }" var="op">
<apex:column value="{!op.Name }"/>
<apex:column value="{!op.CloseDate }"/>
<apex:column value="{!op.StageName }"/>
<apex:column value="{!op.Amount }"/>
</apex:pageBlockTable>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Download Pdf" action="{!downLoad}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
- Surya Killedar
- December 02, 2021
- Like
- 0
- Continue reading or reply
Error when saving lightning-datatable edit on Time field
I'm creating a custom lightning-datatable component. As part of it I can edit a field of type "Time". When I do though and click save, I get the following error: "alue for field 'Start_Time__c' is not in ISO 8601 format, Value: 1970-01-01T15:00:00.000Z, Runtime class: java.lang.String"
My save handler looks like this:
const fields = {}; fields[ID_FIELD.fieldApiName] = event.detail.draftValues[0].Id; fields[START_TIME.fieldApiName] = event.detail.draftValues[0].Start_Time__c; const recordInput = {fields}; updateRecord(recordInput).then(() => { this.dispatchEvent( new ShowToastEvent({ title: 'Success', message: 'Contact updated', variant: 'success' }) ); // Display fresh data in the datatable return refreshApex(this.agendaItems).then(() => { // Clear all draft values in the datatable this.draftValues = []; }); }).catch(error => { this.dispatchEvent( new ShowToastEvent({ title: 'Error updating or reloading record', message: error.body.message, variant: 'error' }) ); });This seems like it should be so simple, but I can't get it to work.
What should I be doing to the value I get from event.detail.draftValues[0].<Time field that was updated> when adding it to the list of fields to update?
- Jeremy Thomas 15
- December 01, 2021
- Like
- 0
- Continue reading or reply
How to put text over the image in visualforce (contentType="application/msword")
How to put text over image in visualforce (contentType = "application) I'm with a vfp and generating it as .doc, but I'm not getting the image to be under a table, as if it were the table's background, whoever can give me any suggestions thanks, this was my last try
<style type="text/css" > @page Section1 { size:8.3in 11.7in; mso-title-page:yes; mso-footer:f1; mso-header:h1; mso-first-header: fh1; mso-first-footer: ff1; margin:0.0in 0.6in 0.0in 0.6in; mso-header-margin:0.3in; mso-footer-margin:0.3in; } div.Section1{ page:Section1; } .capa{ z-index: 0; background-image: } .textcapa{ z-index: 1; float: right; } </style> <apex:form > <body> <div class="section1" > <br/><br/> <div> <apex:image url="{!DocumentCapa}" width="650" height="550" styleClass="capa"/> </div> </div> <table cellspacing="0" cellpadding="0" align="left" width="100%" border="0" class="textcapa"> <tr><td>Caxias do Sul, <apex:outputText value="{0, date, d-MM-yyyy}"> <apex:param value="{!quoteObj.CreatedDate}"/> </apex:outputText> </td></tr> </table>
the result I want looks like this:
- Thais Carolyne Souza
- November 24, 2021
- Like
- 0
- Continue reading or reply
Push notifications on created cases
I cannot get push notifications to fire in the console when a new Case is created. It works for updated cases and create on other objects.
- Jeremy Sparrell
- May 30, 2014
- Like
- 0
- Continue reading or reply
can I insert a template into an exsiting email converstation in salesforce
Hi,
I would like to embed a template into an exsisting email converation. Is this possible and if so how? Currently when I use templates they are creating a new email and I am loosing the conversation with my clients.
I would like to embed a template into an exsisting email converation. Is this possible and if so how? Currently when I use templates they are creating a new email and I am loosing the conversation with my clients.
- Hannah Lake
- November 24, 2021
- Like
- 1
- Continue reading or reply
Create 2 custom fields on account : 1. Contact Last updated ( date time ) 2. Contact Updating count ( number ) When ever a child contact record is updated, update the date/time field “Contact Last updated” field on parent account, also increment the cou
Create two custom fields on account :
1. Contact Last updated ( date time )
2. Contact Updating count ( number )
When ever a child contact record is updated, update the date/time field “Contact Last updated” field on parent account, also increment the counter field “Updating count” with plus one. So that if the child contact record is updated 3 times the counter field “Updating count” will have the value 3, and the “Contact Last updated” will have the value of the date/time it was last updated.
1. Contact Last updated ( date time )
2. Contact Updating count ( number )
When ever a child contact record is updated, update the date/time field “Contact Last updated” field on parent account, also increment the counter field “Updating count” with plus one. So that if the child contact record is updated 3 times the counter field “Updating count” will have the value 3, and the “Contact Last updated” will have the value of the date/time it was last updated.
- Prashant Gulve
- October 09, 2021
- Like
- 2
- Continue reading or reply
- ram t 22
- October 07, 2021
- Like
- 1
- Continue reading or reply
Guest user not able to access document records through SOQL
We have a public site and we want to get the site logo from the document. The associated Document record is not returned on querying by a guest user with user license "Guest User". But it returns a row if internal SF user queries for the same. Can you please suggest a solution for the same?
- Shyam Vaishnav
- July 21, 2021
- Like
- 1
- Continue reading or reply
How to calculate number of hours entered by a user in a single day
Hi Team,
I have an object called Leave Tracker, where users enter the leave date, reason, and number of hours, user can create more than one record in a day with different hours, ex: 1 entry with 2 hours and another entry with 4 hours. but my request is that we should not allow a user to create/update a leave tracker record if the leave hours are more than 8 in a single day per user?
any help is appreciated.
Thanks,
Madhu
I have an object called Leave Tracker, where users enter the leave date, reason, and number of hours, user can create more than one record in a day with different hours, ex: 1 entry with 2 hours and another entry with 4 hours. but my request is that we should not allow a user to create/update a leave tracker record if the leave hours are more than 8 in a single day per user?
any help is appreciated.
Thanks,
Madhu
- Madhu navuluri 4
- May 22, 2021
- Like
- 1
- Continue reading or reply