• Beekman
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 5
    Replies
Hello all,

I have created many buttons with javascript alart with yes/no response to continue.  However, I cannot seem to get a radio typ selection to work.  I need to know if anyone got it to work and if so, can you share?  I can utilize a drop down but prefer the radio as they need to select what to do with 3-4 deifferent options.

Thanks all and happy coding.
Hello all,

I need help on a solution and for some reason I can not figure it out.  We have to many Admin (don't know why) here on Salesforce, with that I need to create my SOQL on the fly.  I currently have the module below for a few major sObjects and it works awesome. 
/*****************************************************************************************************
	Class Abreviations: S - Field, q - Built Query, c - Count
	
	Code class calling examples:
	Opportunity o =  Database.query(Utils.getOpportunityFields() +  ' limit 1');
	list<Opportunity> o =  Database.query(Utils.getOpportunityFields() +  ' where Id in: trigger.new');
	*****************************************************************************************************/
	
	public static string getOpportunityFields() 
	{
		List<String> f = new List<String>();
		Map<String, Schema.SobjectField> fields = Opportunity.getSObjectType().getDescribe().fields.getMap();
		string q = 'SELECT ';
		integer c = 1;
		for (String s: fields.keySet()) 
		{
			if (fields.get(s).getDescribe().isAccessible())
			{ 
				if(c == 1)
					q += s;
				else
					q += ', ' + s;
				c ++;
			}
		}

		return q + ' FROM Opportunity ';
	}



However, I would like it to work with all my objects but don't want to repeat the code over and over.  What I would like to be able to do but cannot figure it out (me stupid) is pass the sObject to one single piece of code.  I can not figure out how to send it or recieve the sObject like show below as <so>.

Any suggestions?
 
/*****************************************************************************************************
	Class Abreviations: S - Field, q - Built Query, c - Count
	
	Code class calling examples:
	Opportunity o =  Database.query(Utils.getOpportunityFields() +  ' limit 1');
	list<Opportunity> o =  Database.query(Utils.getOpportunityFields() +  ' where Id in: trigger.new');
	*****************************************************************************************************/
	
	public static string getOpportunityFields(sObject so) 
	{
		List<String> f = new List<String>();
		Map<String, Schema.SobjectField> fields = so.getSObjectType().getDescribe().fields.getMap();
		string q = ''; // required otherwise the first one is null.
		integer c = 1;
		for (String s: fields.keySet()) 
		{
			if (fields.get(s).getDescribe().isAccessible())
			{ 
				if(c == 1)
					q += s;
				else
					q += ', ' + s;
				c ++;
			}
		}

		return q;
	}

 
Hello,

I am trying to locate documentation on how to insert Javascript inside an Apex method.  I need to invoke a button written is JS for a third party interface on a daily schedule so its not forgotten.

All help is appreicated.

Thank you

Hello,

 

I have a Visual Force Page that I need to test the controller.  Both are attached.  I cannot figure out how to create a testmethod to perform test against this page.  The controller code needs to execute so it can pass testing.

 

Any help with code would be appreciated.

 

Thanks

 

Visual Page Code:

<apex:page showheader="false" controller="systemStatusController">
	<style>
		ul li {
			margin: 10px 0;
		}
		ul.supportLevels li {
			margin: 5px 0;
			list-style: none;
			width:375px;
		}
		ul.supportLevels li span {
			float:right;
		}
	</style>
	<p class="systemDetails">
		<ul>
			<li>You have <a href="#">{!envrCount}</a> Locations with Envysion&nbsp;&nbsp;<a href="mailto:sales@envysion.com?subject=Add%20a%20Site%20to%20my%20Envysion%20Service">add new location</a></li>
			<li>You have {!cameraCount} Cameras across your Locations&nbsp;&nbsp;<a href="mailto:sales@envysion.com?subject=New%20Cameras%20for%20a%20Site">add/replace cameras</a></li>
			<li>Your support levels are:
				<ul class="supportLevels">
					<li>{!notifiesCount} Sites with <i>Envysion Notifies</i><span><a href="mailto:sales@envysion.com?subject=Upgrade%20my%20Envysion%20Support">upgrade</a></span></li>
					<li>{!respondsCount} Sites with <i>Envysion Responds</i><span><a href="mailto:sales@envysion.com?subject=Upgrade%20my%20Envysion%20Support">upgrade</a></span></li>
					<li>{!maintainsCount} Sites with <i>Envysion Maintains</i><span><a href="mailto:sales@envysion.com?subject=Upgrade%20my%20Envysion%20Support">upgrade</a></span></li>
				</ul>
			</li>
		</ul>
	</p>
</apex:page>

 

 

Class Controller code:

public with sharing class systemStatusController {
	private User currentUser;
	private Account currentAccount;
	private String defAcct;
	
	public void setDefaultAccount(String acctID) {
		this.defAcct = acctID;
	}
	
	public User getCurrentUser() {
		if(this.currentUser == NULL) {
			this.currentUser = [SELECT Id, FirstName, LastName, Alias, AccountId FROM User WHERE id = :UserInfo.getUserId()];
		}
		return this.currentUser;
	}
	
	public Account getCurrentAccount() {
		if(this.currentAccount == NULL) {
			User curUser = this.getCurrentUser();
			String accID = curUser.AccountId;
			if(accID == NULL || accID == '') {
				accID = this.defAcct;
			}
			this.currentAccount = [SELECT Id, Name FROM Account WHERE Id = :accID];
		}
		return this.currentAccount;
	}
	
	public Integer getEnvrCount() {
		Account curAcct = this.getCurrentAccount();
		Integer envrCount = [SELECT COUNT() FROM Envr__c WHERE Account__c = :curAcct.Id];
		return envrCount;
	}
		
	public Integer getCameraCount() {
		Account curAcct = this.getCurrentAccount();
		Integer camCount = [SELECT COUNT() FROM Camera__c WHERE Account__c = :curAcct.Id];
		return camCount;
	}
			
	public Integer getNotifiesCount() {
		Account curAcct = this.getCurrentAccount();
		Integer siteCount = [SELECT COUNT() FROM EnvySite__c WHERE Account__c = :curAcct.Id AND Support_Level__c = 'Notifies'];
		return siteCount;
	}
				
	public Integer getRespondsCount() {
		Account curAcct = this.getCurrentAccount();
		Integer siteCount = [SELECT COUNT() FROM EnvySite__c WHERE Account__c = :curAcct.Id AND Support_Level__c = 'Responds'];
		return siteCount;
	}
				
	public Integer getMaintainsCount() {
		Account curAcct = this.getCurrentAccount();
		Integer siteCount = [SELECT COUNT() FROM EnvySite__c WHERE Account__c = :curAcct.Id AND Support_Level__c = 'Maintains'];
		return siteCount;
	}
}

 

Hello,

 

No matter how hard I try I cannot get a simple IF to work.  It keeps telling me that it is missing a ";" on line 5.  If I get rid of the IF statement it works fine but I dont want to overwrite the fields if they are already populated.  Cannot use a workflow as it doesn't understand records "--r" to get Lookup fields.

 

Any suggestions?

 

Even a simple IF fails...

 

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}    

IF ( 0 > 1 ) {
    alert('worked');
}

 

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}		

var a = new sforce.SObject("Opportunity");

IF ( "{!Opportunity.Ship2Addr1__c}" == " ") {
	//Getting Id of Current object
	a.Id =  "{!Opportunity.Id}";
	//Updating fields
	try 	{
		var MySiteAddress = sforce.connection.query("Select Id, Name, Site_Street1__c, Site_City__c, Site_State__c, Site_ZIP__c, Site_Country__c, Site_Phone_Number__c from EnvySite__c where Id = '{!Opportunity.EnvySiteId__c}' Limit 1");
		var recs = MySiteAddress.getArray("records");
		if ( recs.length > 0 ) {
			a.Ship2_Attn__c = "Manager";
			a.Ship2CoName__c = recs[0].Name;
			a.Ship2Addr1__c = recs[0].Site_Street1__c;
			a.Ship2City__c = recs[0].Site_City__c;
			a.Ship2St__c = recs[0].Site_State__c;
			a.Ship2Zip__c = recs[0].Site_ZIP__c;
			a.Ship2Country__c = recs[0].Site_Country__c;
			a.Ship2_Phone__c = recs[0].Site_Phone_Number__c;
		} else {
			alert('Cannot find Site attached to Opportunity.');
		} catch (e) {
        	alert('Exception Error in finding Site. Please try again.: ' + e);
		}
}

//Update Records in the array to database
sforce.connection.update([a]);

//Reload page
location.reload(true);

 

Hello, I am new to this but I am trying to create a custom button with javascript that will delete a few fields and copy one into another.

 

I would like to delete fields A, B and C.  Copy D to E. Both on a custom object Machine (Machine__c)

 

Any help would be appreciated.

Hello,

 

Dont understand why I am getting this error on the code below.  Isnt a (-) and a (+) an arithmetic expression LOL

 

any help as I am new to Appex.

 

trigger Peachtree_items_process on Peachtree_items__c (after update, after insert) {
    if (Peachtree_items__c.Stock_Minimum__c != null && Peachtree_items__c.Qty_On_Hand__c != null &&
            Peachtree_items__c.Qty_On_PO__c != null) {
            Peachtree_items__c.Stock_Reorder_Qty__c =
                Peachtree_items__c.Stock_Minimum__c -
                    (Peachtree_items__c.Qty_On_Hand__c + Peachtree_items__c.Qty_On_PO__c);
    }
}

Hello all,

I have created many buttons with javascript alart with yes/no response to continue.  However, I cannot seem to get a radio typ selection to work.  I need to know if anyone got it to work and if so, can you share?  I can utilize a drop down but prefer the radio as they need to select what to do with 3-4 deifferent options.

Thanks all and happy coding.
Hello all,

I need help on a solution and for some reason I can not figure it out.  We have to many Admin (don't know why) here on Salesforce, with that I need to create my SOQL on the fly.  I currently have the module below for a few major sObjects and it works awesome. 
/*****************************************************************************************************
	Class Abreviations: S - Field, q - Built Query, c - Count
	
	Code class calling examples:
	Opportunity o =  Database.query(Utils.getOpportunityFields() +  ' limit 1');
	list<Opportunity> o =  Database.query(Utils.getOpportunityFields() +  ' where Id in: trigger.new');
	*****************************************************************************************************/
	
	public static string getOpportunityFields() 
	{
		List<String> f = new List<String>();
		Map<String, Schema.SobjectField> fields = Opportunity.getSObjectType().getDescribe().fields.getMap();
		string q = 'SELECT ';
		integer c = 1;
		for (String s: fields.keySet()) 
		{
			if (fields.get(s).getDescribe().isAccessible())
			{ 
				if(c == 1)
					q += s;
				else
					q += ', ' + s;
				c ++;
			}
		}

		return q + ' FROM Opportunity ';
	}



However, I would like it to work with all my objects but don't want to repeat the code over and over.  What I would like to be able to do but cannot figure it out (me stupid) is pass the sObject to one single piece of code.  I can not figure out how to send it or recieve the sObject like show below as <so>.

Any suggestions?
 
/*****************************************************************************************************
	Class Abreviations: S - Field, q - Built Query, c - Count
	
	Code class calling examples:
	Opportunity o =  Database.query(Utils.getOpportunityFields() +  ' limit 1');
	list<Opportunity> o =  Database.query(Utils.getOpportunityFields() +  ' where Id in: trigger.new');
	*****************************************************************************************************/
	
	public static string getOpportunityFields(sObject so) 
	{
		List<String> f = new List<String>();
		Map<String, Schema.SobjectField> fields = so.getSObjectType().getDescribe().fields.getMap();
		string q = ''; // required otherwise the first one is null.
		integer c = 1;
		for (String s: fields.keySet()) 
		{
			if (fields.get(s).getDescribe().isAccessible())
			{ 
				if(c == 1)
					q += s;
				else
					q += ', ' + s;
				c ++;
			}
		}

		return q;
	}

 

Hello,

 

Dont understand why I am getting this error on the code below.  Isnt a (-) and a (+) an arithmetic expression LOL

 

any help as I am new to Appex.

 

trigger Peachtree_items_process on Peachtree_items__c (after update, after insert) {
    if (Peachtree_items__c.Stock_Minimum__c != null && Peachtree_items__c.Qty_On_Hand__c != null &&
            Peachtree_items__c.Qty_On_PO__c != null) {
            Peachtree_items__c.Stock_Reorder_Qty__c =
                Peachtree_items__c.Stock_Minimum__c -
                    (Peachtree_items__c.Qty_On_Hand__c + Peachtree_items__c.Qty_On_PO__c);
    }
}