• Jetha
• SMARTIE
• 646 Points
• Member since 2015
• Apttus

• Chatter
Feed
• 22
• 0
• 0
Likes Given
• 1
Questions
• 131
Replies

For an opportunity i want to calculate the weekends. In Sucess Community i saw  a code. But i can't understand what the logic they used.

```CASE(MOD( StartDate__c - DATE(1985,6,24),7),
0 , CASE( MOD( EndDate__c - StartDate__c, 7),1,0,2,0,3,0,4,0,5,1,6,2,0),
1 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,0,3,0,4,0,5,2,2),
2 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,0,3,1,2),
3 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,1,2),
4 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,1,2),
5 , CASE( MOD( EndDate__c - StartDate__c, 7),0,1,2),
6 , CASE( MOD( EndDate__c - StartDate__c, 7),6,2,1),
999)
+
(FLOOR(( EndDate__c - StartDate__c )/7)*2)```

I have need to calculate order age. how can I write a formulate in formula field.
(My order age will start with the order start date. and end on Either current date or order End Date)

Need Help
Abhilash Mishra

trigger signaturestatus on dsfs__DocuSign_Status__c (after insert,after update) {

Case t=new Case();

for(dsfs__DocuSign_Status__c d:Trigger.New){

if(d.Id!=null){

d=[SELECT Id,dsfs__Case__r.Signature_Required__c,dsfs__Case__r.Id,dsfs__Case__r.Status,dsfs__Envelope_Status__c FROM dsfs__DocuSign_Status__c WHERE Id=:Trigger.New];

String e=d.dsfs__Case__r.Id;

t=[SELECT ID,Signature_Required__c,Customer_Signature_Status__c,Status FROM CASE WHERE Id=:e];

if(d.dsfs__Case__r.Signature_Required__c==true && d.dsfs__Envelope_Status__c=='Completed'){

t.status='Closed';

t.Customer_Signature_Status__c=d.dsfs__Envelope_Status__c;

update t;

}

else{

t.status=d.dsfs__Case__r.Status;

update t;

}

}

}

}

}

It's urgent
If statement on custom button syntax

Hi,
I am trying to do some validaton checks on some fields via a custom button and am getting stuck on a number field.  Basically I want to check.....does an opportunity type = Tender, the final price is less than 100,000 and the sharepoing link is blank  Here is the code: -

if({!ISPICKVAL(Opportunity.Opportunity_Type__c, "Tender")} && '{!Opportunity.Final_Price_Number__c}' > "100,000.00" && '{!Opportunity.Final_Pricing_Sharepoint_Link__c}' == "") {
alert('You need to enter the Final Pricing Sharepoint URL for this Tender before submitting for approval');

The final price field is a number field and I think its this thats not working.  I am getting the error message all the time when I only need it when the figure typed in is less than 100,000

Thanks

• April 26, 2016
• Like
• 0

My scenario is to calculate the holidays for an opportunity.  For this i have created an custom field(DateType: Integer) in opportunity called "Holidayslist__c"(This field i want to display no of holidays).

1.If my opportunity is in "Open" , i want to calculate the holidays between the opportunity CreatedDate field to TODAY.

2.If Opportunity is "Closed", i want to calculate the holidays between the CreatedDate field to ClosedDate.

I wrote a trigger but its not working and it will hit the governer limit. Can anyone give me suggestion how to do this.

```trigger testholidays on Opportunity (before insert, before update)
{
List<opportunity> lstOpp = new List<opportunity>();
List<opportunity> lstOppToUpdate = new List<opportunity>();
Map<Date,Integer> mapActivDateToCount = new Map<Date,Integer>();
Set<Date> setDateOppCreated = new Set<Date>();
list<opportunity> opp1 = [select id,Name,CreatedDate,Holidayslist__c
from opportunity
where IsClosed =False];
for(Opportunity objOpp : opp1 )
{

}

for(Holiday objHoilday : [ SELECT Id, ActivityDate
FROM Holiday
WHERE ActivityDate < TODAY
AND ActivityDate >: setDateOppCreated
])
{
Date dt = objHoilday.ActivityDate;
if(mapActivDateToCount.containsKey(dt))
{
mapActivDateToCount.put(dt, mapActivDateToCount.get(dt)+1);
}
else
{
mapActivDateToCount.put(dt, 1);
}
}

// I am not getting any way to avoid for inside for .
for(Opportunity objOpp : lstOpp)
{
opp1[0].Holidayslist__c = 0;

for(Date dtActivity : mapActivDateToCount.keySet())
{
if(dtActivity < objOpp.CreatedDate.date())
{
opp1[0].Holidayslist__c +=  mapActivDateToCount.get(dtActivity);
}
}
}

system.debug('=====lstOppToUpdate===='+lstOppToUpdate);

Database.update(lstOppToUpdate, true);

}```
I am not able to pass the parameter in Apex Controller. Below is the my Code.

public assigntechniciancontroller(ApexPages.StandardController controller) {
accID =  ApexPages.currentPage().getParameters().get('Id');
skill =  ApexPages.currentPage().getParameters().get('Problem__c');
system.debug ('@@@@@@@@@@@' +skill);
}

Problem__c is the picklist field on Standard WorkOrder Object. I am getting the null in Problem__c field. Kindly help me on this.

Hello,

An custom object have a master detail relation ship to cotact object  (contact being master).
I was trying to convert this in to lookup but i dont get that option.
What can be the reason and how can i solve it. thank you
• April 21, 2016
• Like
• 0
I want to show  error and order will not be allowed to be created if there is a hard block on the account object is checked.
no error but hte trigger is not working.
my trigger is:

trigger ValidateOrder on Order (before insert) {

for(Order occ : Trigger.new){
if(occ.id!=null)
{
occ = [Select Accountid from Order where id =: occ.id];
system.debug('***********************'+occ);
Account acc = [Select id,Hard_Block__c from Account where  id=:occ.Accountid];
system.debug('***********************'+acc);
if(acc.Hard_Block__c == True)
occ.addError(' This Order Cannot be created' );
}
}
}
I have a string boolean whose value I am using in Javascript on VF page, How do I get the code coverage of the same in test class

```Public id guestuserid=[select id from user where Name =: 'Guest User' limit 1].id;
public string Usertype {get {
if (UserInfo.getUserId() != guestuserid)
return 'APP USER';
else
return 'GUEST';
}}```
And for the boolean getter, in below code Offset is integer having value zero asssigned.
```public Boolean PreviousNew { get {
if (offset>0) return false; else return true;
}}```

Thanks!
Hi,

I am a newbee to salesforce and I am working on a requirement where I need to display all the records of Contacts and Locations belonging to an Account in a single table format with radio button to choose any 1 record out of Contacts and Locations.

My concern is I have to query separately to get the Contacts and Locations records. So I was thinking if we can merge two lists of separate objects or can we have a map of two different List of objects. Please do reply.
Hi,  I have dowloaded an app from app exchange  - Opportunity Contact Roles Validation,
https://appexchange.salesforce.com/listingDetail?listingId=a0N300000025Vs1EAE
Creates 2 custom fields on Opportunity: Number of Contacts and Primary Contact Assigned.
APEX trigger updates those fields every time before Opportunity is edited.

Create your own validation rules to restrict Sales from moving forward in the Sales Process (Defined Stage) if primary Contact Roles are not set.

The class failed during the testing. line 39. Would you help please?  Thank you.

 112 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 public class test_updatecontactrolecount {  public static testMethod void testcreateopptywithconditionandrole() { //Insert Opportunities  try {     Opportunity Oppty = new Opportunity(Name='Oppty_test1',StageName='Defined', CloseDate=System.Today());     insert Oppty;          // insert contact     Contact[] cont = new Contact[]     {         new Contact(LastName = 'testcontact1'),         new Contact(LastName = 'testcontact2')     };         insert cont;         // insert contact role          OpportunityContactRole [] ocr = new OpportunityContactRole[]     {     new OpportunityContactRole(Role ='Technical Buyer',OpportunityId=Oppty.id ,Contactid = cont[0].id ,Isprimary = True),     new OpportunityContactRole(Role ='Technical Buyer',OpportunityId=Oppty.id ,Contactid = cont[1].id ,Isprimary = False)     };     insert ocr;         Oppty.StageName = 'Defined';         //Update opportunity          Test.StartTest();     update Oppty;     Test.StopTest();          Oppty =[SELECT Number_of_Contacts_Roles_Assigned__c,Primary_Contact_Assigned__c FROM Opportunity WHERE Id = :Oppty.Id];     system.assert (Oppty.Number_of_Contacts_Roles_Assigned__c == 2);     system.assert (Oppty.Primary_Contact_Assigned__c == True); } catch (System.DmlException e) {     System.assert(false); }         }  }

Here is the Trigger:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 11trigger updatecontactrolecount on Opportunity (before insert,before update) { Boolean isPrimary; Integer iCount; Map oppty_con = new Map();//check if the contact role is needed and add it to the oppty_con map for (Integer i = 0; i < Trigger.new.size(); i++)  {         oppty_con.put(Trigger.new[i].id,         Trigger.new[i]);       } isPrimary = False;  for (List oppcntctrle :[select OpportunityId from OpportunityContactRole where (OpportunityContactRole.IsPrimary = True and OpportunityContactRole.OpportunityId in :oppty_con.keySet())]) {  if (oppcntctrle .Size() >0)  {  isPrimary = True;       } } iCount = 0; for (List oppcntctrle2 : [select OpportunityId from OpportunityContactRole where (OpportunityContactRole.OpportunityId in :oppty_con.keySet())])//Query for Contact Roles {      if (oppcntctrle2 .Size()>0)  {  iCount= oppcntctrle2 .Size();       } } for (Opportunity Oppty : system.trigger.new) //Check if  roles exist in the map or contact role isn't required  { Oppty.Number_of_Contacts_Roles_Assigned__c = iCount; Oppty.Primary_Contact_Assigned__c =isPrimary;  }
• April 13, 2016
• Like
• 0
I am going through TRAILHEAD -  Apex Basics & Database Getting Started with Apex module, there i found, the following,

Apex supports the following data types.
• A primitive, such as an Integer, Double, Long, Date, Datetime, String, ID, Boolean, among others.
• An sObject, either as a generic sObject or as a specific sObject, such as an Account, Contact, or MyCustomObject__c (you’ll learn more about sObjects in a later unit.)
• A collection, including:
• A list (or array) of primitives, sObjects, user defined objects, objects created from Apexclasses, or collections
• A set of primitives
• A map from a primitive to a primitive, sObject, or collection
• A typed list of values, also known as an enum
• User-defined Apex classes
• System-supplied Apex classes

Do we get an apex class for each standard object, please tell me.
<apex:page >
<div ng-app="myapp" ng-controller="mycntrl">
<ul>
<li ng-repeat="x in names">
{{ x | myFormat}}
</li>
</ul>
</div>

<script>
var myapp = angular.module('myapp', []);
myapp.filter('myFormat',function(){
return function(x){
var i, c, txt = "";
x=x.split("")
for(i = 0;i <=x.length; i++){
c= x[i];
if(i % 2 == 0){
c= c.toUpperCase();
}
txt += c;
}
return txt;
};
});
myapp.controller('mycntrl', function(\$scope) {
\$scope.names= [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
});
</script>

</apex:page>

Decimal total_amt = 0.0;
Base_live_funded_amount__c  obj1 = Base_live_funded_amount__c.getInstance('Base_Live_Amount_funded_so_far__c');
for (Account obj : [select id,Total_Amount_Funded__c, ( Select Id,name,peer__Amount_Funded__c from peer__Loan_Application__r where  status__c =' Funded' AND  peer__Amount_Funded__c!=NULL) from Account Where Type='Borrower'])
{
for(peer__Loan_Application__c temp : obj.peer__Loan_Application__r)
{

total_amt = total_amt + temp.peer__Amount_Funded__c;

if( total_amt != null &&  total_amt >0)
{
total_amt  +=obj1.Base_Live_Amount_funded_so_far__c+total_amt;
total_amt =  obj1.Base_Live_Amount_funded_so_far__c ;
system.debug('TTTTTTTTTTTTTTTTTTTTTTT -----------:'+total_amt);

}

}

}

Trying to come up with an SOQL query to sum last months sales of specific items.  In short, they need to be in our "Reporting" company vertical, but not include some products.

I'm new to SOQL, but experienced with SQL...which well, is a bit frustrating, because I could do this in my sleep in SQL.

So, I have this query:

SELECT
(SELECT TotalPrice FROM OpportunityLineItems WHERE (not PriceBookEntry.Product2.Name like '%ancillary%') and (not PriceBookEntry.Product2.Name like '%listen%') )
FROM
Opportunity
WHERE
CloseDate = LAST_MONTH AND
RecordType.Name = 'Reporting' AND
StageName = 'Closed Won'  AND
Id NOT IN (SELECT OpportunityId FROM OpportunityLineItem WHERE PriceBookEntry.Product2.Name like '%ancillary%' or PriceBookEntry.Product2.Name like '%listen%' )

But, it's returning a dataset with an array.  I've tried doing a sum around the subquery, and I get an error (MALFORMED_QUERY).

How do I collapse the array to get a sum of the LineItems for those products?

Thanks.

Hi All,

Can anyone help me in trigger. My requirement is below:
Whenever Product gets inserted or updated in salesforce on Product2 object, a new record same as on Product2 will be inserted in a custom object(custom__c). Below is my code but it is giving error.
trigger MHHE_Pricing_Tier_Temp_ProductUpdate on Product2 (after insert,after update) {
List <MHHE_Pricing_Tier_Temp__c> productToInsertUpdate = new List <MHHE_Pricing_Tier_Temp__c>();
if(trigger.isInsert || trigger.isUpdate){
for (Product2 o : Trigger.new) {
MHHE_Pricing_Tier_Temp__c temprec = new MHHE_Pricing_Tier_Temp__c();
temprec.Product_Name__c=o.name;
}
}
try{
insert productToInsertUpdate;
}
catch (system.Dmlexception e) {
system.debug (e);
}

Any help regarding would be much appriciated
• April 08, 2016
• Like
• 0
trigger countingof on lead (after insert,after update,after delete)
{
set<id>  conId = new set<id>();

if(trigger.isafter && trigger.isinsert || trigger.isUpdate )
{
{
if(c.owner_type__c!=null)
{
}
}
}
if(trigger.isafter && trigger.isDelete)
{
{
if(c.owner_type__c!=null)
{
}
}
}

{
}

{
system.debug('@@@a' +a);
if(a.owner_type__c!=null)
{
}
update lst;
}
}

Error:Apex trigger countingof caused an unexpected exception, contact your administrator: countingof: execution of AfterUpdate caused by: System.DmlException: Update failed.
Hello,

I have a a object with autonumber as mandatory one.
I use this object as a lookup in other object.
when the lookup is displayed, it display the autonumber on detail page, but i want it to display other text (Name__c) instead of autonumber.

How can iachieve it ?
• April 06, 2016
• Like
• 0
Hello, looking for a way to change a text input field on a Visualforce page to be displayed as an output field after something is entered in that field and save button is pressed. Or generally a way to make the field read-only once it is not null. Hoping to avoid using a controller. Any help much appreciated.
• April 05, 2016
• Like
• 0
I want to apply some styling to pageBlock title.

If lets say my title is "Data is refreshed as of 4/12/2016", in that case date should be displayed in red colour.

Any help is appreciated :)
• April 12, 2016
• Like
• 0
Hi,

We have few trigger which is working as expected. during mass update it is failing if the batch size is 1 it is working as expected if it is more than 1 it is failing and not working as expected.

Please suggest me how to fix this issue.

Thanks
Sudhir
I need to retrieve the record owners manager name and manager email in merge field in a email template.
How is it possible..
I have the option of creating 2 fields on object and updating using the workflow..But I need to create 2 fields and hide them n page layout .

Simply I need to retrieve and display in a email template using merge field.

Any immediate help appreciated.

For an opportunity i want to calculate the weekends. In Sucess Community i saw  a code. But i can't understand what the logic they used.

```CASE(MOD( StartDate__c - DATE(1985,6,24),7),
0 , CASE( MOD( EndDate__c - StartDate__c, 7),1,0,2,0,3,0,4,0,5,1,6,2,0),
1 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,0,3,0,4,0,5,2,2),
2 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,0,3,1,2),
3 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,0,2,1,2),
4 , CASE( MOD( EndDate__c - StartDate__c, 7),0,0,1,1,2),
5 , CASE( MOD( EndDate__c - StartDate__c, 7),0,1,2),
6 , CASE( MOD( EndDate__c - StartDate__c, 7),6,2,1),
999)
+
(FLOOR(( EndDate__c - StartDate__c )/7)*2)```

I have need to calculate order age. how can I write a formulate in formula field.
(My order age will start with the order start date. and end on Either current date or order End Date)

Need Help
Abhilash Mishra

trigger signaturestatus on dsfs__DocuSign_Status__c (after insert,after update) {

Case t=new Case();

for(dsfs__DocuSign_Status__c d:Trigger.New){

if(d.Id!=null){

d=[SELECT Id,dsfs__Case__r.Signature_Required__c,dsfs__Case__r.Id,dsfs__Case__r.Status,dsfs__Envelope_Status__c FROM dsfs__DocuSign_Status__c WHERE Id=:Trigger.New];

String e=d.dsfs__Case__r.Id;

t=[SELECT ID,Signature_Required__c,Customer_Signature_Status__c,Status FROM CASE WHERE Id=:e];

if(d.dsfs__Case__r.Signature_Required__c==true && d.dsfs__Envelope_Status__c=='Completed'){

t.status='Closed';

t.Customer_Signature_Status__c=d.dsfs__Envelope_Status__c;

update t;

}

else{

t.status=d.dsfs__Case__r.Status;

update t;

}

}

}

}

}

It's urgent
i need hard delete all account records  with out cheaking  recyclebin will select all and delete it
how it wii possoble which method will uses

iam having to master detiled relationship and lookup relation for the objects. i have deleted both records so, the delete rcords go to recycle bin. now my question is i have get back deleted records from recycle bin using undelete so, is possible  to get both m-d-r and lookup object records?
which relation objects we can get pls hlp me?
Controller:-

private ApexPages.StandardController controller;

//constructor
this.controller=controller;

}

system.debug('%%%%%%');
PageReference redirectPage = new PageReference ('/apex/Nomination_msg');
//redirectPage.setRedirect(true);
//redirectPage.getParameters().put('id',controller.getId());

return redirectPage;
}
else{

return null;
}

}

//save method when user clicks on save button on nomination msg page
public pagereference save(){
update l;
try{
system.debug('Entered into the Method');
PageReference redirectPage = new PageReference ('/apex/successful_msg');
return redirectPage;
return null;
}
Catch(Exception dmle){
return null;
}
}

//signup method when the user clicks on signup button on login page
public pagereference signup() {
Pagereference pg=new Pagereference('https://ap2.salesforce.com/066280000027Mwq');
try{
system.debug('@@@###\$\$\$\$%%%%');
PageReference redirectPage = Page.SignupPage;
redirectPage.setRedirect(true);
return redirectPage;
}

Catch(Exception dmle){
}
return null;
}

//submit method when the user clicks on submit button on signup page
public pagereference Submit(){
try{
PageReference redirectPage = new PageReference ('/apex/Nomination_msg_a');
system.debug('Entered into the Method');
Insert lp;
return redirectPage;
}
else {
redirectPage.setRedirect(false);
return null;
}
}
Catch(Exception dmle){
return null;
}
}

//savesignup method when user clicks on save option on Nomination_msg_a page
public pageReference savesignup(){
update log;
system.debug('&&&&&&&'+log);
try{

system.debug('Entered into the Method');

PageReference redirectPage = new PageReference ('/apex/successful_msg');
return redirectPage;
}

Catch(Exception dmle){
return null;
}

}

test class:-

@isTest

public static testMethod void oppExtensionTest(){
Test.startTest();

ApexPages.StandardController controller;
PageReference testPage = mec.save();
PageReference testPage1 = mec.signup();
PageReference testPage2 = mec.submit();
PageReference testPage3 = mec.savesignup();

ApexPages.StandardController controller1;