• Nilesh J
  • NEWBIE
  • 5 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I have a custom buttong designed to execute javascript for sending an email in the background and then refreshing the page.

The problem I am running into is that the button works perfectly for myself and the other administrator, but simply refreshes the page for everyone else who clicks it.

Because of this, my assumption is that there must be a user setting or permission for the profile(s) of those who cannot trigger the button to send the email. I've gone through and turned settings on/off and tried to strip the button code down, but I still can't quite figure out what is causing this issue. My hunch says it's something with the SingleEmailMessage or sendEmail parameters of the code, but the user profile(s) in question have the abiltiy to send email and do just about everything else and they don't run into issues with other javascript codes.

Here is my code:
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} 
if( 
{!Contact.Outside_PartnerId__c = "a1sG0000005AeeS"}) 
{ 
var message = new sforce.SingleEmailMessage(); 
message.replyTo = "{!User.Email}"; 
message.targetObjectId = "{!Contact.Id}"; 
message.templateId = "00XG0000001cZKS"; 
message.saveAsActivity = true; 
var result = sforce.connection.sendEmail([message]); 
} 
else{ 
alert('This button is only available for sending to Company X reps.'); 
} 

//refresh the page 
window.location.reload();

I really appreciate anyone's help or insight into this.
  • February 12, 2016
  • Like
  • 0

The below is the all code. error is going if i remove this code.   please help me to solve this. 
 
if(! allquoteowners.contains(Owner.Name))
            {
             

					  if(opp1.stagename == 'Won - Delivery' && daysbetween >= 2)
						 {
						   opp1.Quote_Created__c=true;
						   toUpdateopplist.add(opp1);
						 }   
         
             }


 
global class EmailNotifcation implements Schedulable
{
global integer daysbetween; 
    global static String scheduleIt() 
    {     
        //To start job nxt minuted itself
        dateTime dt=System.now().addMinutes(1); 
        String Csec,Cmin,Chr,Cday,Cmonth,CYear;
        Csec=String.valueof(dt.second());
        Cmin=String.valueof(dt.minute());
        string SchTimer = Csec+' '+Cmin+' * * * ?' ; 
        
        EmailNotifcation  emNOt = new EmailNotifcation();
        
        //String SchTimer = '0 1 12 * * ?'; 
        //String SchTimer = '0 1 * * * ?';
        //String SchTimer =   '0 0 2/3 * * ?';    
        return System.schedule('Email Notification', SchTimer,emNOt );                  
    }   

    global void execute(SchedulableContext SC)
    { 
        emailNotificationMethod();
        System.debug('----------in execute methid');
    }

    public void emailNotificationMethod()
    {
    
		
		list<opportunity> toUpdateopplist= new list<opportunity>();
        // procedure for getting all user names in slesforce
       Map<string,string> allusernamesmap= new map<string,string>() ;
        
       for(user u1:[select id,name from user] )
       {
       allusernamesmap.put(u1.id,u1.name);
       }
       
           
      // getting all quote owner names. 
           
        set<string> allquoteowners = new set<String>();
        
        for(quote q1:[SELECT CreatedById FROM Quote])
        {
          //   .add(q1.CreatedById);
            string name1=allusernamesmap.get(q1.CreatedById);
            allquoteowners.add(name1);
        }
        
       //  Prodecure for getting all opportunites records who is  not created the quote 
        
        list<opportunity> updateopps =new list<opportunity>();       
        
        for(opportunity opp1:[Select id, Owner.Name, Quote_Created__c, ClosedOwn_Date__c, stagename,closedate from Opportunity])
         { 
          daysbetween=opp1.closedate.daysBetween(date.today()); 
           
		   if(! allquoteowners.contains(Owner.Name))
            {
             

					  if(opp1.stagename == 'Won - Delivery' && daysbetween >= 2)
						 {
						   opp1.Quote_Created__c=true;
						   toUpdateopplist.add(opp1);
						 }   
         
             } 


		}  
                           
     //   update  toUpdateopplist;
    }
}