Created
January 24, 2017 06:39
-
-
Save swapnilshrikhande/d64203a1d88adc72e7c4a011c0f8ce95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RemoteAction | |
public static map<String,map<String,String>> getValidationRule() { | |
map<String,map<String,String>> mapObjectValidationRule = new map<String,map<String,String>>(); | |
// get list of the validation rules associated with the object | |
String domainUrl = URL.getSalesforceBaseUrl().toExternalForm(); | |
HttpRequest req = new HttpRequest(); | |
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); | |
req.setHeader('Content-Type', 'application/json'); | |
req.setEndpoint(domainUrl+'/services/data/v36.0/tooling/query/?q=Select%20id%2CValidationName%2CActive%2CEntityDefinitionId%20From%20ValidationRule'); | |
req.setMethod('GET'); | |
Http h = new Http(); | |
HttpResponse res = h.send(req); | |
system.debug(res.getBody()); | |
Map<String, Object> mapValidationRuleResult = (Map<String, Object>)JSON.deserializeUntyped(res.getBody()); | |
list<Object> lstobj = (List<Object>)mapValidationRuleResult.get('records'); | |
List<String> lstValidationName = new List<String>(); | |
if ( !lstobj.isEmpty() ) { | |
totalValidationRule = Integer.valueOf( mapValidationRuleResult.get('totalSize') ); | |
} else { | |
totalValidationRule = 0; | |
} | |
map<String,String> mapValidationIdName = new map<String,String>(); | |
for( String strObject : listObject ) { | |
for( Object objtemp : lstobj ) { | |
Map<String, Object> mapValidationRule = ( Map<String, Object> ) objtemp; | |
if( !mapObjectValidationRule.containsKey( strObject ) ) { | |
mapValidationIdName.put( string.valueOf( mapValidationRule.get('Id') ) , string.valueOf( mapValidationRule.get('ValidationName') ) ); | |
mapObjectValidationRule.put( strObject,mapValidationIdName ); | |
} else { | |
if( mapObjectValidationRule.get( strObject ).containsKey( string.valueOf( mapValidationRule.get('Id') ) ) ){ | |
mapObjectValidationRule.get( strObject ).put( string.valueOf( mapValidationRule.get('Id') ) , string.valueOf( mapValidationRule.get('ValidationName') ) ); | |
} else { | |
mapObjectValidationRule.get( strObject ).put( string.valueOf( mapValidationRule.get('Id') ) , string.valueOf( mapValidationRule.get('ValidationName') ) ); | |
} | |
} | |
} | |
} | |
return mapObjectValidationRule; | |
} // end of getValidationRule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment