-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
61Questions
-
19Replies
How to create Email logs into custom Object?
I am having Send Email Button in Case Object. Now whenever Email is being sent, its ToAddress, BCC,CC and TemplateName should be copied into custom Object Email_History__c, having similar fields. How to perform this task? Please sugggest.
- Kunal Purohit 4
- May 30, 2023
- Like
- 0
- Continue reading or reply
How to populate/Inherit field values in child record from Parent record.?
Hi,
I am having one Object named Product_Complaint__c having self lookup relation named Parent_Product_Complaint__c. Now whenever user click on New button in related List, All the field values of parent record must populate in Child Record. (before clikcing on Save button). How to achieve this functionality?
I don't want to create formula fields as fields are already available in child record.
- Kunal Purohit 4
- March 29, 2023
- Like
- 0
- Continue reading or reply
How to write Validation rule for given scenario?
Hello FOlks,
In my org there is one Object named Adverse Event/Product Complaint. It is having self lookup relationship named Parent Adverse Event/Product Complaint.
There are 2 record types. AE and PC,
Requirement is like,
If parent (original) record is AE:
Child (follow-up) record cannot be PC only
Child record can only be AE or AE/PC combo
If parent (original) record is PC:
Child (follow-up) record cannot be AE only
Child record can only be PC or AE/PC combo.
How to write Validation Rule for this?
- Kunal Purohit 4
- March 24, 2023
- Like
- 0
- Continue reading or reply
How to resolve System.NullPointerException: Attempt to de-reference a null object
System.NullPointerException: Attempt to de-reference a null object
Here is my controller and its test class.
public class SendEligibilityFileDetailsToProductCtrl { public SendEligibilityFileDetailsToProductCtrl(ApexPages.StandardController stdController) { } public PageReference SendEligibilityFileDetailsToProduct(){ String eligibilityFileId = ApexPages.currentPage().getParameters().get('id'); String environmentCode = 'bst'; Eligibility_File__c eligibilityFile = [Select Id, Name, Eligibility_File_Name__c, Product_Response__c,ProgramList__c from Eligibility_File__c Where Id = :eligibilityFileId Limit 1]; System.debug('Eligibility-->:' +eligibilityFile); string eligibilityFileAPIDetails = Utility.getServiceURLFromEnvironmentSettings(environmentCode) + 'EligibilityFile'; String tokenHeader = Utility.getTokenFromEnvironmentSettings(environmentCode); EligibilityFileDTO eligibilityFileDTO = new EligibilityFileDTO(); eligibilityFileDTO.FileName = eligibilityFile.Eligibility_File_Name__c; eligibilityFileDTO.Version = eligibilityFile.Name; // Custom Setting EligiblityFileProductDetails__c CustomSetting = EligiblityFileProductDetails__c.getvalues(eligibilityFile.ProgramList__c); System.debug('CustomSetting -->>'+CustomSetting); if(eligibilityFile.ProgramList__c != Null ){ System.debug(eligibilityFile.ProgramList__c); eligibilityFileDTO.ProgramList = CustomSetting.ProgramList__c; System.debug(eligibilityFileDTO.ProgramList); } System.debug('Value of eligibilityFileDTO:'+eligibilityFileDTO) ; System.debug('Endpoint: ' + eligibilityFileAPIDetails); HttpRequest req = new HttpRequest(); req.setHeader('Content-Length', '0'); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', tokenHeader); req.setEndpoint(eligibilityFileAPIDetails); req.setMethod('POST'); String requestBody = JSON.serialize(eligibilityFileDTO).replace('\\','').replace('"[{','[{').replace('}]"','}]'); System.debug('requestBody >>> ' + requestBody); req.setBody(requestBody); Http http = new Http(); req.setTimeout(120000); try{ String jsonstr = ''; HTTPResponse respns = http.send(req); if (respns.getStatusCode() != null && respns.getStatusCode() == 401) { System.debug('Error Occured>>>'); tokenHeader = Utility.getToken(environmentCode); req.setHeader('Authorization', tokenHeader); respns = http.send(req); System.debug('Response >>> '+ respns ); jsonstr = respns.getBody(); Utility.updateTokenForEnvironmentSettings(environmentCode, tokenHeader); }else{ jsonstr= respns.getBody(); } System.debug('Response >>> ' + jsonstr); //hcpDetails = (HCPDetails)JSON.deserialize(jsonstr, HCPDetails.class); //System.debug(hcpDetails); eligibilityFile.Product_Response__c = jsonstr; }catch (System.NullPointerException e){ System.debug('The following exception has occurred: ' + e.getMessage()); //message = 'The following exception has occurred: ' + e.getMessage(); eligibilityFile.Product_Response__c = e.getMessage(); } update eligibilityFile; PageReference pr = new PageReference('/' + eligibilityFileId); pr.setredirect(true); return pr; } public class EligibilityFileDTO{ public String FileName {get;set;} public String Version {get;set;} public String ProgramList {get;set;} } }
Test Class
@isTest private class SendEligibilityFileDetailsTest{ @isTest static void testSendEligibilityFileDetailsToProduct() { // Create test data Eligibility_File__c eligibilityFile = new Eligibility_File__c( Eligibility_File_Name__c = 'Test Eligibility File Name', ProgramList__c = 'Only DeRx' ); insert eligibilityFile; String environmentCode = 'adapt'; String tokenHeader = 'fakeTokenHeader'; String serviceURL = 'https://test.service.com/'; Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); Utility.getEnvironmentCode(environmentCode); Utility.getTokenFromEnvironmentSettings(tokenHeader); Utility.getServiceURLFromEnvironmentSettings(serviceURL); ApexPages.currentPage().getParameters().put('id', eligibilityFile.Id); // Set up mock HTTP response HttpResponse mockResponse = new HttpResponse(); mockResponse.setStatusCode(200); mockResponse.setBody('{}'); // Set up mock HTTP callout // Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator(mockResponse)); // Create controller and call method under test ApexPages.StandardController stdController = new ApexPages.StandardController(eligibilityFile); SendEligibilityFileDetailsToProductCtrl controller = new SendEligibilityFileDetailsToProductCtrl(stdController); controller.SendEligibilityFileDetailsToProduct(); SendEligibilityFileDetailsToProductCtrl.EligibilityFileDTO first = new SendEligibilityFileDetailsToProductCtrl.EligibilityFileDTO(); first.ProgramList='Only DeRx'; EligiblityFileProductDetails__c custsetting = new EligiblityFileProductDetails__c(); custsetting.ProgramList__c = first.ProgramList; // Verify that the eligibility file was updated eligibilityFile = [SELECT Product_Response__c FROM Eligibility_File__c WHERE Id = :eligibilityFile.Id]; System.assertEquals('{}', eligibilityFile.Product_Response__c); } // Mock HttpResponseGenerator class for HTTP callouts private class MockHttpResponseGenerator implements HttpCalloutMock { public HTTPResponse respond(HTTPRequest req) { HTTPResponse res = new HTTPResponse(); res.setStatusCode(200); res.setBody('{"result": "success"}'); return res; } } @isTest static void testMyHttpRequest() { // Set up mock response Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); // Create HttpRequest and set headers HttpRequest req = new HttpRequest(); req.setHeader('Content-Length', '0'); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', 'myToken'); req.setEndpoint('https://myendpoint.com'); req.setMethod('POST'); // Create request body String requestBody = '{"name": "John"}'; req.setBody(requestBody); // Send HTTP request Http http = new Http(); HTTPResponse res = http.send(req); // Verify response System.assertEquals(200, res.getStatusCode()); System.assertEquals('{"result": "success"}', res.getBody()); } }
- Kunal Purohit 4
- March 09, 2023
- Like
- 0
- Continue reading or reply
How to display confirmation message after clicking Send button?
Hello Folks,
I want to display a confirmation message "Message Submitted Successfully", with OK button. I am trying but before sending message, it is generating an alert and after that SMS is being sent. Here is my Visualforce page code. Please suggest.
<apex:page showHeader="false" controller="ProspectUserSMSMessageController"> <script language="JavaScript" type="text/javascript"> function ClosePage(){ window.top.close(); } </script> <apex:outputPanel id="redirectionBlock"> <apex:pageMessages /> <script> var hasMessages = '{!hasError}'; if(hasMessages == 'No') { window.top.close(); } </script> <script> function Show_Alert() { var msg = "Message submitted successfully"; alert(msg); } </script> </apex:outputPanel> <apex:form > <apex:pageBlock title="Send SMS" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!sendSMS}" reRender="redirectionBlock" value="Send SMS" onclick="Show_Alert()"/> <apex:commandButton onclick="javascript:ClosePage()" value="Close"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="1" showHeader="false"> <apex:pageBlockSectionItem labelStyle="text-align:right;"> <apex:outputLabel value="Name : " /> <apex:outputLabel value="{!fullName}" /> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Phone No : " /> <apex:outputLabel value="{!phoneNumber}" /> </apex:pageBlockSectionItem> <apex:actionFunction name="displayTemplate" action="{!showContent}" reRender="smsMessage"/> <apex:pageBlockSectionItem > <apex:outputlabel value="Choose Template : " /> <apex:selectList value="{!selectedItem}" size="1" onchange="displayTemplate();"> <apex:selectOptions value="{!templateList}" /> </apex:selectList> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="Message : " /> <apex:outputPanel id="smsMessage"> <apex:inputTextArea cols="50" rows="5" value="{!smsMessage}"/> </apex:outputPanel> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- Kunal Purohit 4
- February 02, 2023
- Like
- 0
- Continue reading or reply
How to create a Visualforce page with One field?
Hello Folks,
I am learning VisualForce page. I want to create a VF page with one field and this page should make the api call/fetch the data from custom object and show it in that field. I have tried with below code but it is generating an error:
Unknown property 'ZipCodeController.ProspectUser__c'
Here ProspectUser__c is an object name and ZipCode__c is a field name.
VF Page: <apex:page controller ="ZipCodeController" > <apex:form> <apex:inputField value = "{!ProspectUser__c.ZipCode__c}"/> </apex:form> </apex:page> Controller: public with sharing class ZipCodeController { public List<ProspectUser__c> getProspectUser{get;set;} public ZipCodeController() { getProspectUser = [Select ZipCode__c FROM ProspectUser__c LIMIT 1]; } }
Please suggest.
- Kunal Purohit 4
- January 27, 2023
- Like
- 0
- Continue reading or reply
How to write trigger for REST API?
Hello All,
I am having two Fields ZipCode__c and TimeZone__c, Now whenever user enters ZipCode__c, TimeZone__c should be updated accordingly. Here I have to use REST API for ZipCode. I am new to salesforce. Please help to write the trigger for same.
Thanks.
- Kunal Purohit 4
- January 24, 2023
- Like
- 0
- Continue reading or reply
How to update Time Zone based on ZipCode provided by User? What approach should I use?
How to update Time Zone based on ZipCode provided by User? What approach should I use? Trigger or Flow? Should I need REST API for for same? Please suggest.
- Kunal Purohit 4
- January 24, 2023
- Like
- 0
- Continue reading or reply
How to update the field value using configuration?
I am having an Object named ProspectUSer__c. I want to update the timezone__c field based on AreaCode__c, StateCode__c and ZipCOde__c values at time of insert/update. But again the values of these three fields need to be get from custom metadata.? How to perform this fucntionality using configuration. Please suggest.
- Kunal Purohit 4
- January 19, 2023
- Like
- 0
- Continue reading or reply
How to Update the value of Field at time of insert/update operation.?
There is a custom metadata with four fields AreaCode,ZipCode,State and TimeZone. Whenever these field values are inserted/updated, TimeZone value need to be update. How to achieve this fucntionality through configuration or Lightning Flows?
Please suggest.
- Kunal Purohit 4
- January 19, 2023
- Like
- 0
- Continue reading or reply
How to design a custom button.?
Hello Folks,
I want to design a custom button such that when user click on that custom button, a drop down should appear with list of emeil template, followed by editable Email Body and recipient name. Finally, clocking on Send button in dropdown, Email will be sent to recipient. How to perform this tak? Using Trigger or Lightning Flows? Plz Suggest.
- Kunal Purohit 4
- December 23, 2022
- Like
- 0
- Continue reading or reply
How to rewrite below handler?
Hello Folks,
Below Handler works on Round Robin manner in contact Object. Such that, when Contact record is created , it is assigned to another System Admin, based on Round Robin Manner. It is for 2 users only. What changes should I made so that it could work for multiple users. Please Suggest.
public class RoundRobinContactHandler { public static void AssignUser(List<Contact> cn) { integer countContact = 0; String usr; List<Contact> cnList = new List<Contact> (); List<Contact> clist=[Select id, Name, Assigned_To__c from Contact where Assigned_To__r.isActive = TRUE]; countContact=clist.size(); integer RnRUserAssigned = Math.mod(countContact, 2) + 1; integer CSRindex=0; if(RnRUserAssigned==1) { usr=[Select id, name from User where Id = '0052w000002n0Pj' LIMIT 1].id; } else if (RnRUserAssigned==2) { usr=[Select id, name from User where Id = '0052w000009deaY' LIMIT 1].id; } if(cn.size()>0 && (usr!=null && usr!='')) { for(Contact con : cn) { con.Assigned_To__c= usr; } } } }
- Kunal Purohit 4
- December 20, 2022
- Like
- 0
- Continue reading or reply
there are two system Admin in Org. If I am creating two contact record, each contact record should be assigned to each user. Likewise, if there are 3 System Admin, so whenever 3 Contact record is created, it should be assigned to 3 different user.
Hello Follks,
How to write apex trigger for given scenario?
There are two system Admin in Org. If I am creating two contact record, each contact record should be assigned to each user. Likewise, if there are 3 System Admin, so whenever 3 Contact record is created, it should be assigned to 3 different user(Using Round Robin Technique).
- Kunal Purohit 4
- December 19, 2022
- Like
- 0
- Continue reading or reply
How to assign contact record to another system admin upon creation of new record.
Hello Folks,
There are two System Admin in my Dev Org. Whenever, I will create new Contact record, it must be assigned to another System Admin and Whenever Other System Admin will create Contact Record, it should be assigned to me. (Round Robin)
Here AssignedTo__c is a custom field with Lookup Relation data type(User).
Please suggest.
- Kunal Purohit 4
- December 16, 2022
- Like
- 0
- Continue reading or reply
How to write test class for below Handler?
Hello Folks, I am trying to write test class for below code. Its not moving beyond 45%. Can you please help me to achieve the same?
public class SumAmountOppHandler { List<Account> accList=new List<Account>(); Set<Id> setAccIds = new Set<Id>(); public void afterinsert(List<Opportunity> newoppylist){ for(Opportunity con : newoppylist){ if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); updateamount(setAccIds) ; } } } public void afterupdate(List<Opportunity> newoppylist, Map<Id,Opportunity> mapoppy){ for(Opportunity con : newoppylist){ if(con.AccountId!=mapoppy.get(con.Id).AccountId && con.Amount>10000.00){ setAccIds.add(con.AccountId); setAccIds.add(mapoppy.get(con.Id).AccountId); updateamount(setAccIds) ; } } } public void afterdelete(List<Opportunity> oldoppylist){ for(Opportunity con : oldoppylist){ if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); updateamount(setAccIds) ; } } } public void updateamount(set<id> accids){ for(Account acc :[Select id,Total_Opty_Amount__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : accids]){ acc.Total_Opty_Amount__c = acc.Opportunities.size(); acclist.add(acc); } if(acclist.size()>0){ update accList; } } }
- Kunal Purohit 4
- December 12, 2022
- Like
- 0
- Continue reading or reply
How to write handler for given trigger
Hello Folks,
How to write Handler for below trigger.?
trigger SumAmountOpp on Opportunity (After Insert,After Update,After Delete, After Undelete) { List<Account> accList=new List<Account>(); Set<Id> setAccIds = new Set<Id>(); if(Trigger.isInsert){ if(trigger.isAfter){ for(Opportunity con : Trigger.new){ if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); } } } } system.debug('setAccIds ==> '+setAccIds); if(Trigger.isUpdate){ if(trigger.isAfter){ for(Opportunity con : Trigger.new){ if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId && con.Amount>10000.00){ setAccIds.add(con.AccountId); setAccIds.add(Trigger.oldMap.get(con.Id).AccountId); } } } } if(Trigger.isDelete){ if(trigger.isAfter){ for(Opportunity con : Trigger.old) { if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); } } } } if(Trigger.isUndelete){ if(trigger.isAfter){ for(Opportunity con : Trigger.new) { if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); } } } } for(Account acc :[Select id,Total_Opportunity__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : setAccIds]){ acc.Total_Opportunity__c = acc.Opportunities.size(); acclist.add(acc); } if(acclist.size()>0){ update accList; } }
- Kunal Purohit 4
- December 12, 2022
- Like
- 0
- Continue reading or reply
When an account is selected from the lookup then the account type and account billing address should be auto-populated and displayed in the screen as non-editable fields.
- Kunal Purohit 4
- November 29, 2022
- Like
- 0
- Continue reading or reply
How to populate Account Type and Account billing address in Vf page, after selecting AccountName in lookup filter
I am new to visualforce page.
When an account is selected from the lookup then the account type and account billing address should be auto-populated and displayed in the screen as non-editable fields.
Kindly, suugest possible solution for this scenario.
- Kunal Purohit 4
- November 29, 2022
- Like
- 0
- Continue reading or reply
How to implement test class for the given controller
Hello Folks,
I am new to salesforce development. Attempting to write a test class for below code. Please suggest.
public class CountContactHandler { public static void ContactCheckBox(List<Contact> con) { Set<Id> setid = new Set<Id>(); for(Contact c : con) { setid.add(c.AccountId); } List<Account> acc1 = [SELECT Id, Name From Account WHERE Id In :setid]; for(Account a1 : acc1) { } } }
- Kunal Purohit 4
- November 22, 2022
- Like
- 0
- Continue reading or reply
How to Show/Hide Custom Setting Component in VF page.
Hello Community,
In my VF page, I want to show/Hide Custom setting Component based on User Login. Is it possible through Configuration or else It requires codig?
Marked text is a link that derives from custom setting. Please suggest solution.
- Kunal Purohit 4
- May 23, 2022
- Like
- 0
- Continue reading or reply
How to apply validation rule in junction object?
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?
- Kunal Purohit 4
- August 02, 2020
- Like
- 1
- Continue reading or reply
How to Update the value of Field at time of insert/update operation.?
There is a custom metadata with four fields AreaCode,ZipCode,State and TimeZone. Whenever these field values are inserted/updated, TimeZone value need to be update. How to achieve this fucntionality through configuration or Lightning Flows?
Please suggest.
- Kunal Purohit 4
- January 19, 2023
- Like
- 0
- Continue reading or reply
How to assign contact record to another system admin upon creation of new record.
Hello Folks,
There are two System Admin in my Dev Org. Whenever, I will create new Contact record, it must be assigned to another System Admin and Whenever Other System Admin will create Contact Record, it should be assigned to me. (Round Robin)
Here AssignedTo__c is a custom field with Lookup Relation data type(User).
Please suggest.
- Kunal Purohit 4
- December 16, 2022
- Like
- 0
- Continue reading or reply
How to write handler for given trigger
Hello Folks,
How to write Handler for below trigger.?
trigger SumAmountOpp on Opportunity (After Insert,After Update,After Delete, After Undelete) { List<Account> accList=new List<Account>(); Set<Id> setAccIds = new Set<Id>(); if(Trigger.isInsert){ if(trigger.isAfter){ for(Opportunity con : Trigger.new){ if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); } } } } system.debug('setAccIds ==> '+setAccIds); if(Trigger.isUpdate){ if(trigger.isAfter){ for(Opportunity con : Trigger.new){ if(con.AccountId!=Trigger.oldMap.get(con.Id).AccountId && con.Amount>10000.00){ setAccIds.add(con.AccountId); setAccIds.add(Trigger.oldMap.get(con.Id).AccountId); } } } } if(Trigger.isDelete){ if(trigger.isAfter){ for(Opportunity con : Trigger.old) { if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); } } } } if(Trigger.isUndelete){ if(trigger.isAfter){ for(Opportunity con : Trigger.new) { if(con.AccountId != null && con.Amount>10000.00){ setAccIds.add(con.AccountId); } } } } for(Account acc :[Select id,Total_Opportunity__c ,(Select Amount from Opportunities where Amount>10000.00) from Account where Id in : setAccIds]){ acc.Total_Opportunity__c = acc.Opportunities.size(); acclist.add(acc); } if(acclist.size()>0){ update accList; } }
- Kunal Purohit 4
- December 12, 2022
- Like
- 0
- Continue reading or reply
How to implement test class for the given controller
Hello Folks,
I am new to salesforce development. Attempting to write a test class for below code. Please suggest.
public class CountContactHandler { public static void ContactCheckBox(List<Contact> con) { Set<Id> setid = new Set<Id>(); for(Contact c : con) { setid.add(c.AccountId); } List<Account> acc1 = [SELECT Id, Name From Account WHERE Id In :setid]; for(Account a1 : acc1) { } } }
- Kunal Purohit 4
- November 22, 2022
- Like
- 0
- Continue reading or reply
How to Show/Hide Custom Setting Component in VF page.
Hello Community,
In my VF page, I want to show/Hide Custom setting Component based on User Login. Is it possible through Configuration or else It requires codig?
Marked text is a link that derives from custom setting. Please suggest solution.
- Kunal Purohit 4
- May 23, 2022
- Like
- 0
- Continue reading or reply
How to write trigger?
In my org, there are two objects Case and Project. Case object is having lookup relation with Project and Account Object. Now whenever, Case record is cretaed for particular Project, its asscoiated Account should get populated in case record. Plz help to write trigger for same.
- Kunal Purohit 4
- May 20, 2021
- Like
- 0
- Continue reading or reply
I want to schedule my batch apex after 5 minutes. I have tried using cron,but not working... plz help
public class StatusPublished implements database.Batchable<sobject>,Schedulable{ public void execute(Schedulablecontext sc) { string cron='0 2 * * * ?*'; StatusPublished sp =new StatusPublished(); system.schedule('updatepaper', cron, sp); //database.executeBatch(sp); } public database.QueryLocator start(database.BatchableContext bc) { string query='select id,Name,Status__c from Research_Paper__c'; return database.getQueryLocator(query); } public void execute(database.BatchableContext bc,list<Account> acc) { List<Research_Paper__c> rlist=new list<Research_Paper__c>(); for(Research_Paper__c rp: rlist) { if(rp.Status__c=='Paper registration Complete') { rp.Status__c='Published'; rlist.add(rp); } } update rlist; } public void finish(database.BatchableContext bc) { }
- Kunal Purohit 4
- September 05, 2020
- Like
- 0
- Continue reading or reply
Issue in triggers
trigger TriggerOpp on Opportunity (before insert,before update) { set<id> setid=new set<id>(); for(Opportunity opp:trigger.new) { setid.add(opp.AccountId); } Map<id,Account> acmap=new map<id,Account>(); for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid]) { acmap.put(acc.id,acc); } for(Opportunity opp:trigger.new) { if(acmap.containsKey(opp.AccountId) && acmap.get(opp.AccountId).Opportunities!=null) { { if(opp.StageName=='Prospecting') { (opp.AccountId).addError('Duplicate value'); } } } } }
- Kunal Purohit 4
- September 04, 2020
- Like
- 0
- Continue reading or reply
Error "Variable does not exist: StageName"
trigger TriggerOpp on Opportunity (before insert,before update) { set<id> setid=new set<id>(); for(Opportunity opp:trigger.new) { setid.add(opp.AccountId); } Map<id,Account> acmap=new map<id,Account>(); for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid]) { acmap.put(acc.id,acc); } for(Opportunity opp:trigger.new) { if(acmap.containsKey(opp.AccountId)) { if(acmap.get(opp.AccountId).StageName=='Prospecting') { (opp.AccountId).addError('Duplicate value'); } } } }
- Kunal Purohit 4
- September 04, 2020
- Like
- 0
- Continue reading or reply
How to remove prefix 'Mr.' from Account object?
public class BatchApex1 implements database.Batchable<Sobject> {
public database.QueryLocator start(database.BatchableContext Bc)
{
string query='select id,name from Account';
return database.getQueryLocator(query);
}
public void execute(database.BatchableContext Bc, list<Account> alist)
{
for(account a:alist)
{
a.name= a.Name.removeStart('Mr.');
}
update alist;
system.debug(alist);
}
public void finish(database.BatchableContext Bc)
{
}
}
- Kunal Purohit 4
- August 06, 2020
- Like
- 0
- Continue reading or reply
How to apply validation rule in junction object?
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?
- Kunal Purohit 4
- August 02, 2020
- Like
- 1
- Continue reading or reply
- Balaji B 10
- March 13, 2016
- Like
- 0
- Continue reading or reply