After the February Revolution of 1917, he became a member of the Baku Council, the Hummet Committee, and the Russian Social Democratic Labour Party (Bolsheviks) Committee. During the Civil War he then took part in the defense of Astrakhan. From 1918 to 1931 Afandiyev was appointed to many roles: Commissar on the Transcaucasian Muslims' affairs of the People's Commissariat of Nationalities of RSFSR, deputy chairman of the Central Bureau of Communist Organization of Orient Peoples of the Central Committee of RKP(b) (Russian Communist Party of Bolsheviks), 1920-1921, member of the Executive Committee of Baku Council, Extraordinary Commissioner of the Central Committee of Azerbaijani KP(b), Commissar of Ganja Province ( he commanded the suppression of anti-Bolshevik rebellion in Ganja), member of the Central Executive Committee, People's Commissar of Lands, People's Commissar of Revolutionary Commissariat of Azerbaijan SSR, member of Central Committee of VKP(b) (All-Union Communist Party of the Bolsheviks ), member of Transcaucasian Regional Committee of VKP(b) (All-Union Communist Party of the Bolsheviks), Bureau of the Central Committee of Azerbaijani KP(b), member of the Central Executive Committee of the USSR, deputy chairman and since 1931 the chairman of the Central Executive Committee of Azerbaijani SSR and one of the chairmen of the Central Executive Committee of the Transcaucasian Soviet Federative Socialist Republic.